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: Re: [Caml-list] create a closure in external C function?

At 06:01 PM 3/6/01 +0100, Xavier Leroy wrote:
>Not directly, at least.  Building closures from C isn't impossible,
>just very delicate and highly processor-dependent (in the case of the
>native-code compiler).
>Right. caml_c_call does part of the job, but is indeed very

It seems like most of the platform specific parts are already there in pieces in the native compiler itself.  I'm not familiar enough with calling conventions on the other platforms, but is it true that one could stitch together a bunch of the asmrun functions to give us a simple c-callable function that can be passed as a closure?  Or, are the caml calling conventions such that you need to do special stuff depending on how many arguments there are?

> As Fabrice noted, the hard part is
>to deal with arbitrary many C function types, determined dynamically.
>There, you'd need some kind of dynamic invocation interface for C
>functions, and I don't know of any C library that provides this in a
>portable or semi-portable fashion.
> ...
At 11:50 AM 3/6/01 +0100, Fabrice Le Fessant wrote:
>My problem is: how to call the function f_v, using the types in
>types_v (either integer, char, string or double) to build the call,
>and using arg1_v (translated using its type) as argument.
>Of course, I can implement this easily on my PC, but I don't know any
>way to implement such a function in an architecture-independant way...

I think I can do this part with the ffcall library.  It has functions for building c-callable functions, both in the stdargs way but with return values as well, and the opposite (where you incrementally tell it what paramters the function takes, and then it gives you back a pointer you can call as a full c function call).  It's highly portable (I think it supports more platforms than ocaml, even, so it's overkill).

I was hoping to avoid the "list of parms" solution and just get both ends hooked up directly, which would be really cool.

>PS: I can give you the code I have already written for building the
>closure, and so on if you are interested... but I'm stuck on this
>function !

Yes, that'd be great.  Please email me the code.


To unsubscribe, mail  Archives: