1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-30 06:50:31 +02:00

Use GC-managed pointerless memory in the FFI.

* 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.
This commit is contained in:
Ludovic Courtès 2010-03-16 23:51:21 +01:00
parent b0abbaa74a
commit 087aa6aa31

View file

@ -657,9 +657,11 @@ SCM_DEFINE (scm_make_foreign_function, "make-foreign-function", 3, 0, 0,
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);
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,