From: Xavier Leroy <xleroy@pauillac.inria.fr>
To: Leszek.Holenderski@gmd.de
Cc: caml-list@pauillac.inria.fr
Subject: Re: Q: How to call a CSL function from C
Date: Fri, 15 Dec 1995 17:33:17 +0100 (MET) [thread overview]
Message-ID: <199512151633.RAA21304@pauillac.inria.fr> (raw)
In-Reply-To: <v01520d0bacf6f9220314@[129.26.12.124]> from "Leszek.Holenderski@gmd.de" at Dec 15, 95 01:40:00 pm
> I need to call some f: 'a -> 'b (in fact, 'a and 'b are some concrete
> types, but it doesn't matter here) from my C code linked with CSL 1.12. In
> my Caml code, I'll have the function
>
> external register_callback: ('a -> 'b) -> unit = "register_callback"
>
> such that 'register_callback f' will store, in my C code, enough
> information to call f later from the C code.
The correct way to do this is as follows (modified from your pseudocode):
static value f_closure = Val_int(0)
value register_callback (f);
value f;
{
register_global_root(&f_closure);
f_closure = f;
return Val_unit;
}
value invoke_f (arg)
value arg;
{
return callback(f_closure, arg);
}
The call to "register_global_root" ensures that the GC will not
deallocate the closure and will update the variable f_closure if the
closure gets moved. (This is documented in the user's manual.)
> The following code, borrowed from CamlTk for CL 0.7 (thus, from Francois
> Rouaix), seems to avoid the problem:
That was a terrible hack to work around the lack of a
"register_global_root" function in Caml Light 0.7. Forget about it.
- Xavier Leroy
prev parent reply other threads:[~1995-12-15 17:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-12-15 12:40 Leszek.Holenderski
1995-12-15 16:33 ` Xavier Leroy [this message]
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=199512151633.RAA21304@pauillac.inria.fr \
--to=xleroy@pauillac.inria.fr \
--cc=Leszek.Holenderski@gmd.de \
--cc=caml-list@pauillac.inria.fr \
/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