Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] create a closure in external C function?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Hecker <checker@d...>
Subject: [Caml-list] create a closure in external C function?

I can't find any docs on this, except for a couple hints that it might be possible...

I want to create a function and return it from an external C function:

type ii = int -> int
val f : int -> ii = "c_function"

where c_function looks something like this:

value c_function( value i )
    return Val_closure(&some_c_int_int_function);

Is this possible?  The Closure_tag is not very well documented, but from tracing through the asm for some callbacks and passing closures to C functions, it appears that the first word is a pointer to the actual generated code for the caml function.  So, if you wanted to make this work you'd have to return a pointer to a caml function that calls _caml_c_call, which isn't really documented either (and looks platform specific, although it seems to just be jumping to the address of the passed C function after setting things up).

Any hope of getting this working?  Is caml_c_call designed to be a C callable function on all platforms (it doesn't look like it, since it takes a parm in registers on x86, which is unusual)?  Is the bytecode sitatution completely different (I assume so)?


To unsubscribe, mail  Archives: