Tweak `netsys_get_custom_ops` for GC safety

Gerd Stolpmann
2019-08-22T10:48:13Z

My understanding is that it is unsafe to have an allocating expression on the right-hand side of an assignment to a Field(...) l-value.

It happens in "netsys_c_mem.c", the following patch fixing the issue:

diff --git a/code/src/netsys/netsys_c_mem.c b/code/src/netsys/netsys_c_mem.c
index 7a55884..86db886 100644
--- a/code/src/netsys/netsys_c_mem.c
+++ b/code/src/netsys/netsys_c_mem.c
@@ -1498,13 +1498,15 @@ value netsys_get_custom_ops (value v)
 {
     struct custom_operations *custom_ops;
     CAMLparam1(v);
-    CAMLlocal1(r);
+    CAMLlocal3(r, s, n);

     if (Is_block(v) && Tag_val(v) == Custom_tag) {
        custom_ops = Custom_ops_val(v);
+       s = caml_copy_string(custom_ops->identifier);
+       n = caml_copy_nativeint((intnat) custom_ops);
        r = alloc_small(2,0);
-       Field(r,0) = caml_copy_string(custom_ops->identifier);
-       Field(r,1) = caml_copy_nativeint((intnat) custom_ops);
+       Field(r,0) = s;
+       Field(r,1) = n;
     }
     else
        invalid_argument("Netsys_mem.get_custom_ops");