summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-25 19:06:25 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-25 19:06:25 -0700
commitfd402c48d244f7f823f18588bf67eda085b103e9 (patch)
treeae4b87229be6da86174a5f8ea6264decdad52edb
parent8e65f3539cca89375e73eb6aad9959dbe4485583 (diff)
downloadtxr-fd402c48d244f7f823f18588bf67eda085b103e9.tar.gz
txr-fd402c48d244f7f823f18588bf67eda085b103e9.tar.bz2
txr-fd402c48d244f7f823f18588bf67eda085b103e9.zip
ffi: bugfix: gc-correct handling of memb array.
* ffi.c (make_ffi_type_struct): Use calloc for allocating memb, so all the Lisp objects in it are initially nil. Then install it into the structure upfront. Afterward, as we iterate over the slots and types and install them into the array, we lose references to them. But now since the array is now wired into the FFI struct type structure, these objects are now visible to GC.
-rw-r--r--ffi.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ffi.c b/ffi.c
index 6e71e743..79f71538 100644
--- a/ffi.c
+++ b/ffi.c
@@ -1514,7 +1514,7 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
ffi_type **elements = coerce(ffi_type **,
chk_malloc(sizeof *elements * (nmemb + 1)));
struct smemb *memb = coerce(struct smemb *,
- chk_malloc(sizeof *memb * nmemb));
+ chk_calloc(nmemb, sizeof *memb));
val obj = cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_struct_ops);
ucnum offs = 0;
ucnum most_align = 0;
@@ -1533,6 +1533,7 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
tft->release = ffi_struct_release;
tft->alloc = ffi_fixed_alloc;
tft->free = free;
+ tft->memb = memb;
for (i = 0; i < nmemb; i++) {
val type = pop(&types);
@@ -1567,7 +1568,6 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
tft->size = (offs + most_align - 1) & ~(most_align - 1);
tft->align = most_align;
- tft->memb = memb;
return obj;
}