diff options
| author | 2022-10-09 09:47:22 +0200 | |
|---|---|---|
| committer | 2022-10-09 09:47:56 +0200 | |
| commit | d4ab29a4adf9ee1c9aa0e80539910a16a7c1a762 (patch) | |
| tree | ece1f053b905794c14dc209d220436d3678d0f80 /pez.c | |
| parent | 71fc15b92f6166c1bc5bfc6f83a8654c92545662 (diff) | |
gc bugfix
Diffstat (limited to 'pez.c')
| -rw-r--r-- | pez.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -318,6 +318,9 @@ static bool _vecpush(PezContext *cx, void **at, size_t sz, uint *len, uint *cap, const void *src, size_t n) { + if (cx->gccanrun && (cx->dbg & DBGstressgc)) { + gc(cx); + } if (*len + n - 1 >= *cap) { uint newcap = (*len + n - 1) * 2; uint8_t *new; @@ -726,6 +729,7 @@ markarray(PezContext *cx, Array *arr) static void gcmark(PezContext *cx, Obj *o) { + assert(cx->gccanrun); if (o->gc) { return; } @@ -2240,7 +2244,6 @@ lambdaexpr(Comp *cm, const char *name) memset(&cm->con, 0, sizeof cm->con); cm->proto = proto; cm->fenv = fenv; - ETRY(push(cm->cx, box_obj(proto))); // gc keep if (matchspchr(cm, '[')) { while (!matchspchr(cm, ']')) { @@ -2262,7 +2265,6 @@ lambdaexpr(Comp *cm, const char *name) } } - pop(cm->cx); // proto gc ETRY(block(cm, '}')); ETRY(compop(cm, Oret)); fincompfn(cm); @@ -2276,7 +2278,7 @@ Cleanup: return ret && compclosure(cm, proto); Err: - ret = 1; + ret = 0; goto Cleanup; } @@ -3398,6 +3400,7 @@ pez_eval_cb(PezContext *cx, const char *fname, int (*cb)(void *), void *ud) Proto *pr; Fn *fn; Comp cm; + int gccanrun = cx->gccanrun; cx->gccanrun = 0; if (!(pr = newproto(cx, fname, "<eval>", /* line */ 1))) { return 0; @@ -3415,23 +3418,21 @@ pez_eval_cb(PezContext *cx, const char *fname, int (*cb)(void *), void *ud) if (cx->dbg & DBGbytecode) { inspectproto(pr); } - cx->gccanrun = 1; ETRY(push(cx, box_obj(fn))); // gc keep + cx->gccanrun = 1; ETRY(exefn(cx, fn, 0)); cx->stktop[-2] = cx->stktop[-1]; --cx->stktop; // gc unkeep - if (cx->dbg & DBGstressgc) { - gc(cx); - } - cx->gccanrun = 0; deinitcomp(&cm); + cx->gccanrun = gccanrun; return 1; Err: cx->stktop = stktop; deinitcomp(&cm); delfenv(cx, &cm.fenv); + cx->gccanrun = gccanrun; return 0; } |