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: 4812 Reporter: goswin Status: closed (set by @damiendoligez on 2013-08-02T14:21:48Z) Resolution: fixed Priority: high Severity: minor Target version: 4.01.0+dev Fixed in version: 4.01.0+dev Category: ~DO NOT USE (was: OCaml general) Monitored by: tgazagna @ygrek@glondu
Bug description
The unixsupport.h header provides functions to convert unix errno into ocamls Unix.error, which is sufficient for most applications. The attached patch adds a function for the reverse convertion.
Additional information
Rational:
For libfuse bindings I need to convert Unix.error to errno numbers. The C stubs call an ocaml closure and expect usualy a string as return value or an Unix.Unix_error exception in case of an error. The stubs need to catch the exception, convert them back to unix errno numbers and return -err to libfuse. The code looks something like this:
static int readlink_stub(const char *name, char *buf, size_t size) {
int res = 0;
leave_blocking_section();
CAMLparam0();
CAMLlocal3(ml_name, ml_res, ml_exn);
ml_name = caml_copy_string(name);
value ml_res = caml_callback2(readlink_callback, ml_name, Val_int(size));
if (Is_exception_result(ml_res)) {
ml_exn = Extract_exception(ml_res);
res = -code_of_unix_error(Field(ml_exn, 1));
} else {
strncpy(buf, String_val(ml_res), size);
}
enter_blocking_section();
return res;
}
Using the function code_of_unix_error from <caml/unixsupport.h> we can
greatly simplify this function. code_of_unix_error was added in OCaml
4.01 which is ≤ 4.03 that we currently require.
See also: ocaml/ocaml#4812
This does require a small change ot how OCaml plugins are linked -- we
now need to link them with the standard OCaml Unix library (unix.cmxa).
This commit also adds a comprehensive end-to-end test of error codes.
Acked-by: Laszlo Ersek <lersek@redhat.com>
Original bug ID: 4812
Reporter: goswin
Status: closed (set by @damiendoligez on 2013-08-02T14:21:48Z)
Resolution: fixed
Priority: high
Severity: minor
Target version: 4.01.0+dev
Fixed in version: 4.01.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: tgazagna @ygrek @glondu
Bug description
The unixsupport.h header provides functions to convert unix errno into ocamls Unix.error, which is sufficient for most applications. The attached patch adds a function for the reverse convertion.
Additional information
Rational:
For libfuse bindings I need to convert Unix.error to errno numbers. The C stubs call an ocaml closure and expect usualy a string as return value or an Unix.Unix_error exception in case of an error. The stubs need to catch the exception, convert them back to unix errno numbers and return -err to libfuse. The code looks something like this:
static int readlink_stub(const char *name, char *buf, size_t size) {
int res = 0;
leave_blocking_section();
CAMLparam0();
CAMLlocal3(ml_name, ml_res, ml_exn);
ml_name = caml_copy_string(name);
value ml_res = caml_callback2(readlink_callback, ml_name, Val_int(size));
if (Is_exception_result(ml_res)) {
ml_exn = Extract_exception(ml_res);
res = -code_of_unix_error(Field(ml_exn, 1));
} else {
strncpy(buf, String_val(ml_res), size);
}
enter_blocking_section();
return res;
}
File attachments
The text was updated successfully, but these errors were encountered: