summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-24 21:28:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-24 21:28:54 -0700
commitd8e999cd3c09924a704d2a3fbe3db5372a5b5f3a (patch)
tree392392cb4162e5eea4c1e8d37747b335b9035976
parent7a6e0e4cc882833578bdfb09fc48ceb7b090f719 (diff)
downloadtxr-d8e999cd3c09924a704d2a3fbe3db5372a5b5f3a.tar.gz
txr-d8e999cd3c09924a704d2a3fbe3db5372a5b5f3a.tar.bz2
txr-d8e999cd3c09924a704d2a3fbe3db5372a5b5f3a.zip
ffi: bugfix: gc issue affecting cptr and carray.
* ffi.c (ffi_type_compile): The problem here is using make_ffi_type_builtin and then installing an eltype. That type has no gc function that will mark tft->eltype, exposing the eltype to premature reclamation. We must change these to use make_ffi_type_pointer. That constructor takes the element type too, so the code gets simplified.
-rw-r--r--ffi.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/ffi.c b/ffi.c
index f5ec4902..35bec226 100644
--- a/ffi.c
+++ b/ffi.c
@@ -1784,22 +1784,14 @@ val ffi_type_compile(val syntax)
return type;
} else if (sym == cptr_s) {
val tag = cadr(syntax);
- val type = make_ffi_type_builtin(syntax, cptr_s, sizeof (mem_t *),
- alignof (mem_t *),
- &ffi_type_pointer,
- ffi_cptr_put, ffi_cptr_get);
- struct txr_ffi_type *tft = ffi_type_struct(type);
- tft->eltype = tag;
- return type;
+ return make_ffi_type_pointer(syntax, cptr_s,
+ ffi_cptr_put, ffi_cptr_get,
+ 0, 0, 0, tag);
} else if (sym == carray_s) {
- val element_type = ffi_type_compile(cadr(syntax));
- val type = make_ffi_type_builtin(syntax, carray_s, sizeof (mem_t *),
- alignof (mem_t *),
- &ffi_type_pointer,
- ffi_carray_put, ffi_carray_get);
- struct txr_ffi_type *tft = ffi_type_struct(type);
- tft->eltype = element_type;
- return type;
+ val eltype = ffi_type_compile(cadr(syntax));
+ return make_ffi_type_pointer(syntax, carray_s,
+ ffi_carray_put, ffi_carray_get,
+ 0, 0, 0, eltype);
}
uw_throwf(error_s, lit("~a: unrecognized type operator: ~s"),
self, sym, nao);