From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rob Hoes Subject: [PATCH v3-RESEND 12/28] libxl: ocaml: make Val_defbool GC-proof Date: Mon, 21 Oct 2013 14:32:29 +0100 Message-ID: <1382362365-6645-13-git-send-email-rob.hoes@citrix.com> References: <1382362365-6645-1-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1382362365-6645-1-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: ian.jackson@eu.citrix.com, ian.campbell@citrix.com, Rob Hoes List-Id: xen-devel@lists.xenproject.org The Val_* functions potentially allocate new values on the OCaml heap, and may trigger an iteration of the OCaml GC. Therefore, it is important to assign values produced by Val_* immediately to variables declared with CAMLlocal macros, which register the values with the GC. This leads to slightly weird looking C code, but avoids hard to find segfaults. Signed-off-by: Rob Hoes --- tools/ocaml/libs/xl/xenlight_stubs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index a6f6e6f..d15a625 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) -- 1.7.10.4