You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7572 Reporter: @sliquister Status: acknowledged (set by @xavierleroy on 2017-07-18T20:19:38Z) Resolution: open Priority: normal Severity: minor Version: 4.04.2 Category: runtime system and C interface Monitored by:@gasche@hcarty@dbuenzli
Bug description
When writing ocaml plugins for C programs, you end with
functions that look like this:
The problem is that this function is most likely broken, because if
the caml function raises, the ocaml runtime will either exit or unwind
the stack past the C program.
We have caml_callback_exn to help with this, but it's not enough
because caml_alloc_string can also raise.
There seems to be no way of catching ocaml exceptions from a block of
C code, short of exporting the C code, writing an ocaml function that
calls it, registering the ocaml function and calling it from C, which
is a bit ridiculous.
There's this caml_alloc_shr_no_raise function, which may be usable
for this purpose but it's undocumented, so I am not sure it's meant
to be used from the outside (and it's probably not very nice to
have to duplicate all the allocation functions with a _no_raise
suffix).
So is there a recommended way to not throw ocaml exceptions in C
bindings? If not, can we create one?
The text was updated successfully, but these errors were encountered:
The analysis is correct. For the bytecode system (ocamlrun) it would be relatively easy to catch Caml exceptions from C code. The native-code system is a different story, however.
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.
Original bug ID: 7572
Reporter: @sliquister
Status: acknowledged (set by @xavierleroy on 2017-07-18T20:19:38Z)
Resolution: open
Priority: normal
Severity: minor
Version: 4.04.2
Category: runtime system and C interface
Monitored by: @gasche @hcarty @dbuenzli
Bug description
When writing ocaml plugins for C programs, you end with
functions that look like this:
The problem is that this function is most likely broken, because if
the caml function raises, the ocaml runtime will either exit or unwind
the stack past the C program.
We have caml_callback_exn to help with this, but it's not enough
because caml_alloc_string can also raise.
There seems to be no way of catching ocaml exceptions from a block of
C code, short of exporting the C code, writing an ocaml function that
calls it, registering the ocaml function and calling it from C, which
is a bit ridiculous.
There's this caml_alloc_shr_no_raise function, which may be usable
for this purpose but it's undocumented, so I am not sure it's meant
to be used from the outside (and it's probably not very nice to
have to duplicate all the allocation functions with a _no_raise
suffix).
So is there a recommended way to not throw ocaml exceptions in C
bindings? If not, can we create one?
The text was updated successfully, but these errors were encountered: