summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-24 08:01:17 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-24 08:01:17 -0800
commitb03342e9ffc924eede2984349a7a9f3a28206d6c (patch)
tree9af94571d7911c82c17f75109cb0aaba0da3df22
parent70a74fbfd01dc5b236888a1d62d9c7b0dcaabde7 (diff)
downloadtxr-b03342e9ffc924eede2984349a7a9f3a28206d6c.tar.gz
txr-b03342e9ffc924eede2984349a7a9f3a28206d6c.tar.bz2
txr-b03342e9ffc924eede2984349a7a9f3a28206d6c.zip
ffi: gc bug in enum type.
* ffi.c (make_ffi_type_enum): Allocate the sym_num an num_sym hashes before the type object. That ensures they are older, and may be assigned into the object without setcheck. Also, move those assignments earlier, before the loop which populates the hashes.
-rw-r--r--ffi.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ffi.c b/ffi.c
index 0b119486..9643ac87 100644
--- a/ffi.c
+++ b/ffi.c
@@ -3013,14 +3013,14 @@ static val make_ffi_type_enum(val syntax, val enums,
chk_calloc(1, sizeof *tft));
struct txr_ffi_type *btft = ffi_type_struct(base_type);
+ val sym_num = make_hash(nil, nil, t);
+ val num_sym = make_hash(nil, nil, nil);
val obj = cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_enum_ops);
cnum lowest = INT_PTR_MAX;
cnum highest = INT_PTR_MIN - 1;
cnum cur = -1;
ucnum count = 0;
val iter;
- val sym_num = make_hash(nil, nil, t);
- val num_sym = make_hash(nil, nil, nil);
val enum_env = make_env(nil, nil, nil);
val shadow_menv = make_env(nil, nil, nil);
@@ -3041,6 +3041,9 @@ static val make_ffi_type_enum(val syntax, val enums,
tft->free = btft->free;
tft->eltype = base_type;
+ tft->num_sym = num_sym;
+ tft->sym_num = sym_num;
+
for (iter = enums; !endp(iter); iter = cdr(iter), count++) {
val en = car(iter);
val nn;
@@ -3092,9 +3095,6 @@ static val make_ffi_type_enum(val syntax, val enums,
}
}
- tft->num_sym = num_sym;
- tft->sym_num = sym_num;
-
return obj;
}