[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: ocaml: make Val_defbool GC-proof
commit fe14c97ae87581269d0391dcc2d0bb94d73c6f6e Author: Rob Hoes <rob.hoes@xxxxxxxxxx> AuthorDate: Wed Nov 6 17:49:50 2013 +0000 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Mon Nov 11 15:39:39 2013 +0000 libxl: ocaml: make Val_defbool GC-proof In order to avoid newly created OCaml values from being GC'ed, they must be registered as roots with the GC, before an iteration of the GC may happen. The Val_* functions potentially allocate new values on the OCaml heap, and may trigger an iteration of the OCaml GC. The way to register a value with the GC is to assign it to a variable declared with a CAMLparam or CAMLlocal macro, which put the value into a struct that can be reached from a GC root. This leads to slightly weird looking C code, but avoids hard to find segfaults. Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx> Acked-by: David Scott <dave.scott@xxxxxxxxxxxxx> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/ocaml/libs/xl/xenlight_stubs.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index 67612f4..94601c4 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -308,15 +308,17 @@ static int Uuid_val(libxl_uuid *c_val, value v) static value Val_defbool(libxl_defbool c_val) { CAMLparam0(); - CAMLlocal1(v); + CAMLlocal2(v1, v2); + bool b; if (libxl_defbool_is_default(c_val)) - v = Val_none; + v2 = Val_none; else { - bool b = libxl_defbool_val(c_val); - v = Val_some(b ? Val_bool(true) : Val_bool(false)); + b = libxl_defbool_val(c_val); + v1 = b ? Val_bool(true) : Val_bool(false); + v2 = Val_some(v1); } - CAMLreturn(v); + CAMLreturn(v2); } static libxl_defbool Defbool_val(value v) -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |