diff --git a/src/core/stuff.h b/src/core/stuff.h index 529ab6a4..12e9229e 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -164,7 +164,7 @@ bool isPureFn(B x); // doesn't consume B bqn_merge(B x); // consumes B any_squeeze(B x); // consumes; accepts any array, returns one with the smallest type (doesn't recurse!) -B squeeze_deep(B x); // consumes; accepts any object, returns an object with all parts necessary for equality checking & hashing squeezed +B squeeze_deep(B x); // consumes; accepts any object, returns an object with all parts necessary for equality checking & hashing squeezed; if this function errors due to OOM, the argument won't yet be consumed B num_squeeze(B x); // consumes; see note below B chr_squeeze(B x); // consumes; see note below // Note that num_squeeze & chr_squeeze don't check for fl_squoze, and unconditionally set it. Thus, don't call it on an array if it could be squeezable by the opposite method. diff --git a/src/vm.c b/src/vm.c index cacaadc1..a4b68977 100644 --- a/src/vm.c +++ b/src/vm.c @@ -438,18 +438,21 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to comp->indices = indices; comp->src = src; comp->path = path; - HArr* objArr = comp->objs = cpyHArr(objs); - usz objAm = objArr->ia; - for (usz i = 0; i < objAm; i++) objArr->a[i] = squeeze_deep(objArr->a[i]); - comp->blockAm = 0; B nameList; if (q_N(tokenInfo)) { nameList = bi_emptyHVec; } else { B t = IGetU(tokenInfo,2); - nameList = IGetU(t,0); + nameList = IGet(t,0); } - comp->nameList = inc(nameList); + comp->nameList = nameList; + comp->blockAm = 0; + comp->objs = NULL; + // and now finally it's safe to allocate stuff + HArr* objArr = cpyHArr(objs); + comp->objs = objArr; + usz objAm = objArr->ia; + for (usz i = 0; i < objAm; i++) objArr->a[i] = squeeze_deep(objArr->a[i]); if (!q_N(src) && !q_N(indices)) { if (isAtm(indices) || rnk(indices)!=1 || a(indices)->ia!=2) thrM("VM compiler: Bad indices"); @@ -946,7 +949,7 @@ DEF_FREE(block) { i32 am = c->bodyCount; for (i32 i = 0; i < am; i++) ptr_decR(c->bodies[i]); } -DEF_FREE(comp) { Comp* c = (Comp *)x; ptr_decR(c->objs); decR(c->bc); decR(c->src); decR(c->indices); decR(c->path); decR(c->nameList); } +DEF_FREE(comp) { Comp* c = (Comp *)x; if (c->objs!=NULL) ptr_decR(c->objs); decR(c->bc); decR(c->src); decR(c->indices); decR(c->path); decR(c->nameList); } DEF_FREE(funBl) { FunBlock* c = (FunBlock*)x; ptr_dec(c->sc); ptr_decR(c->bl); } DEF_FREE(md1Bl) { Md1Block* c = (Md1Block*)x; ptr_dec(c->sc); ptr_decR(c->bl); } DEF_FREE(md2Bl) { Md2Block* c = (Md2Block*)x; ptr_dec(c->sc); ptr_decR(c->bl); }