Browse thread
[Caml-list] camlidl and pointer to function
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Dmitry Bely <dbely@m...> |
| Subject: | Re: [Caml-list] camlidl and pointer to function |
"NASSOR Eric" <nassor@crf.canon.fr> writes: > > I have a C library function with interface like following: > > > > typedef [abstract] void* SomeType; > > typedef int (*CallBack)(int); > > void convert( SomeType* in, SomeType* out, CallBack c); > > > > It would be nice to use it in caml the following way: > > > > external convert: someType->someType->(int->int)->unit = "something" > > ... > > convert stIn stOut ((+) 1) > > ... > > > > Unfortinately CamIDL language does not allow the pointer to function as a > > valid type, but maybe there is some common solution/workaround for this > > problem? Or the only way is writing necessary stubs and conversion > > functions by hands? Is is possible at all? > > > > It is possible to call back caml code from a C code which was called from caml, but > you need to write a few lines of code. > here is an example extracted from my application (with a few simplifications). > the resulting caml function iter_tree can be called recursively, it can also raise > exceptions. The problem is that C library is binary-only (Intel image processing library), and CallBack type is exactly typedef int (*CallBack)(int); I cannot add value parameter containing Caml callback here. I can store it in a global C variable, but then the entire application will be not thread-safe. Locking the entire ml2c(); f(); c2ml(); section is also not desirable... Hope to hear from you soon, Dmitry ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr