caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <yallop@gmail.com>
To: David Sheets <sheets@alum.mit.edu>
Cc: "Malcolm Matalka" <mmatalka@gmail.com>,
	"Jeremie Dimino" <jdimino@janestreet.com>,
	"Christoph Höger" <christoph.hoeger@tu-berlin.de>,
	"caml users" <caml-list@inria.fr>
Subject: Re: [Caml-list] Save callbacks from OCaml to C
Date: Wed, 3 Feb 2016 10:02:06 -0800	[thread overview]
Message-ID: <CAAxsn=G4oRTdE_Peh8FWvfjTuSu+9jSw8q-dvZ+QNmGyWpWw4Q@mail.gmail.com> (raw)
In-Reply-To: <CAAWM5Tyn-HjZPWOmUaWmk_w8isetx_x6pmLHUpXugHhjZsKZ5Q@mail.gmail.com>

On 3 February 2016 at 05:44, David Sheets <sheets@alum.mit.edu> wrote:
> On Wed, Feb 3, 2016 at 12:26 PM, Malcolm Matalka <mmatalka@gmail.com> wrote:
>> Jeremie Dimino <jdimino@janestreet.com> writes:
>>> You need to register [ml_t], [ml_x] and [ml_g
>>> ] as GC roots. Otherwise if the GC runs in caml_ba_alloc for instance,
>>> [ml_t] might ends up containing garbage even before reaching
>>> [caml_callback3]. You can use the normal macros for that:
>>>
>> If one is using ctypes, is all of this taken care of?  I have a library
>> that registers a bunch of Ocaml functions in C code, which the C code
>> calls.  I haven't experienced anything bad happening yet, but that
>> doesn't mean much...
>
> If you use ctypes and pass OCaml closures to C, you *must* retain a
> reference to the closure to avoid it being GCed. If you do not, you
> may experience the exception CallToExpiredClosure sporadically.

Besides David's caveat, the answer is yes: ctypes will take care of
registering arguments as GC roots as necessary.

  reply	other threads:[~2016-02-03 18:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 10:54 Christoph Höger
2016-02-03 11:48 ` Jeremie Dimino
2016-02-03 12:26   ` Malcolm Matalka
2016-02-03 13:44     ` David Sheets
2016-02-03 18:02       ` Jeremy Yallop [this message]
2016-02-03 20:15         ` Malcolm Matalka
2016-02-04  0:14           ` Jeremy Yallop
2016-02-04  7:26             ` Malcolm Matalka
2016-02-04 19:29               ` Jeremy Yallop
     [not found]   ` <56B1EC33.2090303@tu-berlin.de>
2016-02-03 13:49     ` Jeremie Dimino
2016-02-03 14:38       ` Christoph Höger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAxsn=G4oRTdE_Peh8FWvfjTuSu+9jSw8q-dvZ+QNmGyWpWw4Q@mail.gmail.com' \
    --to=yallop@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-berlin.de \
    --cc=jdimino@janestreet.com \
    --cc=mmatalka@gmail.com \
    --cc=sheets@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).