These are considerably more efficient than ordinary global roots, but
with the caveat that the program is not allowed to modify them without
calling a special function. We don't modify them, so this change is
safe.
This requires OCaml >= 3.11, but we have that on RHEL 6
(since we dropped support for RHEL 5).
See also:
http://caml.inria.fr/pub/ml-archives/caml-list/2008/03/c3bf86990088236cee...
---
README | 2 +-
ocaml/guestfs-c.c | 16 +++++-----------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/README b/README
index 8c74901..19a1fb2 100644
--- a/README
+++ b/README
@@ -84,7 +84,7 @@ The full requirements are described below.
+--------------+-------------+---+-----------------------------------------+
| Pod::Simple | | R | Part of Perl core. |
+--------------+-------------+---+-----------------------------------------+
-| OCaml | |R/O| Required if compiling from git. |
+| OCaml | 3.11 |R/O| Required if compiling from git. |
| | | | Optional if compiling from tarball. |
| | | | To build generated files and OCaml bindings.
+--------------+-------------+---+-----------------------------------------+
diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c
index cbff846..1ee5ba7 100644
--- a/ocaml/guestfs-c.c
+++ b/ocaml/guestfs-c.c
@@ -88,12 +88,12 @@ guestfs_finalize (value gv)
/* Now unregister the global roots. */
for (i = 0; i < len; ++i) {
- caml_remove_global_root (roots[i]);
+ caml_remove_generational_global_root (roots[i]);
free (roots[i]);
}
free (roots);
- caml_remove_global_root (v);
+ caml_remove_generational_global_root (v);
free (v);
}
}
@@ -179,10 +179,7 @@ ocaml_guestfs_create (value environmentv, value close_on_exitv, value
unitv)
*/
v = guestfs_int_safe_malloc (g, sizeof *v);
*v = gv;
- /* XXX This global root is generational, but we cannot rely on every
- * user having the OCaml 3.11 version which supports this.
- */
- caml_register_global_root (v);
+ caml_register_generational_global_root (v);
guestfs_set_private (g, "_ocaml_g", v);
CAMLreturn (gv);
@@ -255,10 +252,7 @@ ocaml_guestfs_set_event_callback (value gv, value closure, value
events)
ocaml_guestfs_raise_error (g, "set_event_callback");
}
- /* XXX This global root is generational, but we cannot rely on every
- * user having the OCaml 3.11 version which supports this.
- */
- caml_register_global_root (root);
+ caml_register_generational_global_root (root);
snprintf (key, sizeof key, "_ocaml_event_%d", eh);
guestfs_set_private (g, key, root);
@@ -280,7 +274,7 @@ ocaml_guestfs_delete_event_callback (value gv, value ehv)
value *root = guestfs_get_private (g, key);
if (root) {
- caml_remove_global_root (root);
+ caml_remove_generational_global_root (root);
free (root);
guestfs_set_private (g, key, NULL);
guestfs_delete_event_callback (g, eh);
--
2.5.0