diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-06-28 06:46:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-06-28 06:46:22 -0700 |
commit | 60708150c2efd57f34962b336d9e63684a00aeca (patch) | |
tree | 3769b7d31ed6557e123c5551c090e2b3347653a4 | |
parent | 010f5afe311b8a4f52597db2085a3aae49213c68 (diff) | |
download | txr-60708150c2efd57f34962b336d9e63684a00aeca.tar.gz txr-60708150c2efd57f34962b336d9e63684a00aeca.tar.bz2 txr-60708150c2efd57f34962b336d9e63684a00aeca.zip |
ssort: gc bug in vector case.
* gc.[ch] (gc_prot_array_alloc): Return the COBJ via
new pointer argument.
* lib.c (ssort_vec): Capture the object from gt_prot_array_alloc
into a local variable, That makes it visible to the garbage
collector, so it won't be prematurely reclaimed. Since we don't
use or return that object, we need to use gc_hint.
-rw-r--r-- | gc.c | 4 | ||||
-rw-r--r-- | gc.h | 2 | ||||
-rw-r--r-- | lib.c | 4 |
3 files changed, 6 insertions, 4 deletions
@@ -1321,13 +1321,13 @@ static struct cobj_ops prot_array_ops = cobj_ops_init(eq, prot_array_mark, cobj_eq_hash_op); -val *gc_prot_array_alloc(cnum size) +val *gc_prot_array_alloc(cnum size, val *obj) { struct prot_array *pa = coerce(struct prot_array *, chk_calloc(offsetof(struct prot_array, arr) + size * sizeof(val), 1)); pa->size = size; - pa->self = cobj(coerce(mem_t *, pa), prot_array_cls, &prot_array_ops); + *obj = pa->self = cobj(coerce(mem_t *, pa), prot_array_cls, &prot_array_ops); return pa->arr; } @@ -88,5 +88,5 @@ INLINE void gc_stack_check(void) gc_stack_overflow(); } -val *gc_prot_array_alloc(cnum size); +val *gc_prot_array_alloc(cnum size, val *obj); void gc_prot_array_free(val *); @@ -11094,9 +11094,11 @@ static void mergesort(val vec, val lessfun, val keyfun, cnum from, cnum to, static void ssort_vec(val vec, val lessfun, val keyfun, val self) { cnum len = c_fixnum(length(vec), self); - val *aux = gc_prot_array_alloc(len); + val auxobj; + val *aux = gc_prot_array_alloc(len, &auxobj); mergesort(vec, lessfun, keyfun, 0, len, aux); gc_prot_array_free(aux); + gc_hint(auxobj); } |