libxl: ocaml: make Val_defbool GC-proof
authorRob Hoes <rob.hoes@citrix.com>
Wed, 6 Nov 2013 17:49:50 +0000 (17:49 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 11 Nov 2013 15:39:39 +0000 (15:39 +0000)
commitfe14c97ae87581269d0391dcc2d0bb94d73c6f6e
tree31256fb322ffdcd48d1d7ef87ffa5967f9769a1a
parent38d5aaff4c495eae2d06999a6a18a07eaf719833
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@citrix.com>
Acked-by: David Scott <dave.scott@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/ocaml/libs/xl/xenlight_stubs.c