On 01/27/2017 04:11 AM, Richard W.M. Jones wrote:
Actually OCaml is a real compiled language, and the call from C to
OCaml code (via caml_callback_exn) is a short piece of asm which
preserves errno.
Which shows my lack of familiarity with OCaml; but I'm guessing that
also means that OCaml comes with easy ways to directly set errno so that
it will be visible from C.
However you'll need to save errno around caml_enter_blocking_section
since that unblocks and processes signals.
IOW:
static int
pread_wrapper (void *h, void *buf, uint32_t count, uint64_t offset)
{
CAMLparam0 ();
CAMLlocal3 (rv, strv, offsetv);
+ int saved_errno;
...
rv = caml_callback3_exn (pread_fn, *(value *) h, strv, offsetv);
+ saved_errno = errno;
if (Is_exception_result (rv)) {
nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
caml_enter_blocking_section ();
+ errno = saved_errno;
CAMLreturnT (int, -1);
Okay, I'll respin the patch along these lines.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org