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:
parent
b0abbaa74a
commit
087aa6aa31
1 changed files with 8 additions and 6 deletions
|
@ -656,10 +656,12 @@ SCM_DEFINE (scm_make_foreign_function, "make-foreign-function", 3, 0, 0,
|
||||||
one for the return val */
|
one for the return val */
|
||||||
cif_len = (ROUND_UP (cif_len, alignof(ffi_type))
|
cif_len = (ROUND_UP (cif_len, alignof(ffi_type))
|
||||||
+ (nargs + n_struct_elts + 1)*sizeof(ffi_type));
|
+ (nargs + n_struct_elts + 1)*sizeof(ffi_type));
|
||||||
|
|
||||||
mem = scm_malloc (cif_len);
|
mem = scm_gc_malloc_pointerless (cif_len, "foreign");
|
||||||
scm_cif = scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID, mem, cif_len, free);
|
scm_cif = scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID, mem,
|
||||||
cif = (ffi_cif*)mem;
|
cif_len, NULL);
|
||||||
|
cif = (ffi_cif *) mem;
|
||||||
|
|
||||||
/* reuse cif_len to walk through the mem */
|
/* reuse cif_len to walk through the mem */
|
||||||
cif_len = ROUND_UP (sizeof (ffi_cif), alignof(void*));
|
cif_len = ROUND_UP (sizeof (ffi_cif), alignof(void*));
|
||||||
type_ptrs = (ffi_type**)(mem + cif_len);
|
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);
|
return scm_from_int64 (*(scm_t_int64*)loc);
|
||||||
case FFI_TYPE_STRUCT:
|
case FFI_TYPE_STRUCT:
|
||||||
{
|
{
|
||||||
void *mem = scm_malloc (type->size);
|
void *mem = scm_gc_malloc_pointerless (type->size, "foreign");
|
||||||
memcpy (mem, loc, type->size);
|
memcpy (mem, loc, type->size);
|
||||||
return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,
|
return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,
|
||||||
mem, type->size, free);
|
mem, type->size, NULL);
|
||||||
}
|
}
|
||||||
case FFI_TYPE_POINTER:
|
case FFI_TYPE_POINTER:
|
||||||
return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,
|
return scm_take_foreign_pointer (SCM_FOREIGN_TYPE_VOID,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue