ocaml-ctypes icon indicating copy to clipboard operation
ocaml-ctypes copied to clipboard

Customizing inverted stubs generation

Open braibant opened this issue 10 years ago • 3 comments

I am looking at the stubs generated using Cstubs_inverted and I am wondering to what extent these stubs are usable when used in the context of a multi-threaded application.

Here is a typical stub generated:

unsigned long C_Initialize(void* x1)
{
   enum { nargs = 1 };
   CAMLparam0();
   CAMLlocalN(locals, nargs);
   locals[0] = CTYPES_FROM_PTR(x1);
   value x2 = functions[fn_C_Initialize];
   value x3 = caml_callbackN(x2, nargs, locals);
   unsigned long x4 = ctypes_ulong_val(x3);
   CAMLreturnT(unsigned long, x4);
}

What could be really nice is to have support in the inverted stub mechanisms to be able to insert arbitrary code at the very beginning of that function, and just before the return. We were able to simulate that behavior by patching memory.h (a dirty hack) but this is in no way satisfying. With these hooks in place, it should be possible to put some sane locking in place. Does it make sense? Is it compatible with the kind of customatization you had in mind for #197?

braibant avatar Jan 29 '15 17:01 braibant

I think it should be possible to support customization of Cstubs_inverted output. We should certainly add this.

yallop avatar Jan 30 '15 10:01 yallop

I am working on it.

braibant avatar Jan 30 '15 10:01 braibant

Maybe we should continue the discussion in the #265 pull request

braibant avatar Jan 30 '15 11:01 braibant