mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
ocaml: Use generational global roots.
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/c3bf86990088236ceeb9a0f0f4c35390.en.html
This commit is contained in:
2
README
2
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.
|
||||
+--------------+-------------+---+-----------------------------------------+
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user