Skip to content

Commit f4cbb38

Browse files
committed
Fix GC bugs due to missing STORE_FRAME before allocations
1 parent 1a515a4 commit f4cbb38

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/runtime/vm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,11 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
445445

446446
CASE_OP(OP_BUILD_LIST) {
447447
int count = READ_BYTE();
448+
STORE_FRAME();
448449
ObjList* list = newList();
449450
PUSH(OBJ_VAL(list));
450451
if (count > 0) {
452+
STORE_FRAME();
451453
list->items = ALLOCATE(Value, count);
452454
list->capacity = count;
453455
list->count = count;
@@ -471,6 +473,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
471473

472474
CASE_OP(OP_BUILD_MAP) {
473475
int count = READ_BYTE();
476+
STORE_FRAME();
474477
ObjDictionary* dict = newDictionary();
475478
PUSH(OBJ_VAL(dict));
476479
for (int i = 0; i < count; i++) {
@@ -781,6 +784,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
781784
PUSH(OBJ_VAL(copyString(buffer, (int)strlen(buffer))));
782785
stackTop[-2] = stackTop[-1];
783786
stackTop--;
787+
STORE_FRAME();
784788
concatenate(pvm);
785789
LOAD_FRAME();
786790
} else if (IS_STRING(stackTop[-1]) && IS_NUMBER(stackTop[-2])) {
@@ -792,6 +796,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
792796
PUSH(newA);
793797
stackTop[-3] = stackTop[-1];
794798
stackTop--;
799+
STORE_FRAME();
795800
concatenate(pvm);
796801
LOAD_FRAME();
797802
} else {
@@ -1301,6 +1306,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
13011306

13021307
CASE_OP(OP_LAYER) {
13031308
ObjString* name = READ_STRING();
1309+
STORE_FRAME();
13041310
ObjLayer* layer = newLayer(name);
13051311
PUSH(OBJ_VAL(layer));
13061312
Value contextVal = stackTop[-2];

0 commit comments

Comments
 (0)