Use GC-managed pointerless memory in the FFI.
authorLudovic Courtès <ludo@gnu.org>
Tue, 16 Mar 2010 22:51:21 +0000 (23:51 +0100)
committerLudovic Courtès <ludo@gnu.org>
Tue, 16 Mar 2010 23:54:00 +0000 (00:54 +0100)
* libguile/foreign.c (scm_make_foreign_function): Use
  `scm_gc_malloc_pointerless ()' when allocating memory for CIF.
  (pack): Likewise for the `FFI_TYPE_STRUCT' case.

libguile/foreign.c

index 00de06f..c87c378 100644 (file)
@@ -656,10 +656,12 @@ SCM_DEFINE (scm_make_foreign_function, "make-foreign-function", 3, 0, 0,
      one for the return val */
   cif_len = (ROUND_UP (cif_len, alignof(ffi_type))
              + (nargs + n_struct_elts + 1)*sizeof(ffi_type));
-  
-  mem = scm_malloc (cif_len);
-  scm_cif = scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID, mem, cif_len, free);
-  cif = (ffi_cif*)mem;
+
+  mem = scm_gc_malloc_pointerless (cif_len, "foreign");
+  scm_cif = scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID, mem,
+                                     cif_len, NULL);
+  cif = (ffi_cif *) mem;
+
   /* reuse cif_len to walk through the mem */
   cif_len = ROUND_UP (sizeof (ffi_cif), alignof(void*));
   type_ptrs = (ffi_type**)(mem + cif_len);
@@ -910,10 +912,10 @@ pack (ffi_type *type, void *loc)
       return scm_from_int64 (*(scm_t_int64*)loc);
     case FFI_TYPE_STRUCT:
       {
-        void *mem = scm_malloc (type->size);
+        void *mem = scm_gc_malloc_pointerless (type->size, "foreign");
         memcpy (mem, loc, type->size);
         return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,
-                                         mem, type->size, free);
+                                         mem, type->size, NULL);
       }
     case FFI_TYPE_POINTER:
       return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,