Skip to content

Commit 594b030

Browse files
committed
Fix remaining missing STORE_FRAME before table mutations and memory allocations
1 parent f4cbb38 commit 594b030

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/runtime/vm.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
484484
runtimeError(pvm, "Dictionary key must be a string.");
485485
return INTERPRET_RUNTIME_ERROR;
486486
}
487+
STORE_FRAME();
487488
tableSet(&dict->items, AS_STRING(key), val);
488489
Value dictVal = stackTop[-1];
489490
stackTop -= 3;
@@ -557,6 +558,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
557558
return INTERPRET_RUNTIME_ERROR;
558559
}
559560
ObjDictionary* dict = AS_DICTIONARY(targetVal);
561+
STORE_FRAME();
560562
tableSet(&dict->items, AS_STRING(indexVal), value);
561563
stackTop -= 3;
562564
PUSH(value);
@@ -637,6 +639,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
637639

638640
CASE_OP(OP_DEFINE_GLOBAL) {
639641
ObjString* name = READ_STRING();
642+
STORE_FRAME();
640643
tableSet(&pvm->globals, name, stackTop[-1]);
641644
stackTop--;
642645
DISPATCH();
@@ -645,6 +648,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
645648
CASE_OP(OP_SET_GLOBAL) {
646649
ObjString* name = READ_STRING();
647650
/* Optimized set-if-exists check from HEAD */
651+
STORE_FRAME();
648652
if (tableSet(&pvm->globals, name, stackTop[-1])) {
649653
tableDelete(&pvm->globals, name);
650654
STORE_FRAME();
@@ -986,6 +990,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
986990

987991
CASE_OP(OP_CLOSURE) {
988992
ObjFunction* function = AS_FUNCTION(READ_CONSTANT());
993+
STORE_FRAME();
989994
ObjClosure* closure = newClosure(function);
990995
PUSH(OBJ_VAL(closure));
991996
for (int i = 0; i < closure->upvalueCount; i++) {
@@ -1024,7 +1029,9 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
10241029
}
10251030

10261031
CASE_OP(OP_CLASS) {
1027-
PUSH(OBJ_VAL(newClass(READ_STRING())));
1032+
ObjString* name = READ_STRING();
1033+
STORE_FRAME();
1034+
PUSH(OBJ_VAL(newClass(name)));
10281035
DISPATCH();
10291036
}
10301037
CASE_OP(OP_INHERIT) {
@@ -1035,6 +1042,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
10351042
return INTERPRET_RUNTIME_ERROR;
10361043
}
10371044
ObjClass* subclass = AS_CLASS(stackTop[-1]);
1045+
STORE_FRAME();
10381046
tableAddAll(&AS_CLASS(superclass)->methods, &subclass->methods);
10391047
stackTop--; // Pop subclass, keep superclass
10401048
DISPATCH();
@@ -1061,6 +1069,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
10611069

10621070
CASE_OP(OP_INTERFACE) {
10631071
ObjString* name = AS_STRING(READ_CONSTANT());
1072+
STORE_FRAME();
10641073
PUSH(OBJ_VAL(newInterface(name)));
10651074
DISPATCH();
10661075
}
@@ -1095,6 +1104,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
10951104
}
10961105
ObjString* symbol = AS_STRING(*(--stackTop));
10971106
ObjString* libName = AS_STRING(*(--stackTop));
1107+
STORE_FRAME();
10981108
ObjForeign* foreign = loadForeign(libName, symbol);
10991109
if (foreign == NULL) {
11001110
STORE_FRAME();
@@ -1231,6 +1241,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
12311241
return INTERPRET_RUNTIME_ERROR;
12321242
}
12331243
int outDims[] = {a->dims[0], b->dims[1]};
1244+
STORE_FRAME();
12341245
ObjTensor *res = newTensor(2, outDims, NULL);
12351246
PUSH(OBJ_VAL(res));
12361247
for (int i = 0; i < a->dims[0]; i++) {
@@ -1278,6 +1289,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
12781289
}
12791290
totalSize = (int)newSize;
12801291
}
1292+
STORE_FRAME();
12811293
ObjTensor *tensor = newTensor(dimCount, dims, NULL);
12821294
PUSH(OBJ_VAL(tensor));
12831295
if (elementCount == (uint32_t)totalSize) {
@@ -1300,7 +1312,9 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
13001312
}
13011313

13021314
CASE_OP(OP_CONTEXT) {
1303-
PUSH(OBJ_VAL(newContext(READ_STRING())));
1315+
ObjString* name = READ_STRING();
1316+
STORE_FRAME();
1317+
PUSH(OBJ_VAL(newContext(name)));
13041318
DISPATCH();
13051319
}
13061320

@@ -1311,6 +1325,7 @@ static bool resolveContextualMethod(VM* pvm, ObjString* name, Value* result) {
13111325
PUSH(OBJ_VAL(layer));
13121326
Value contextVal = stackTop[-2];
13131327
if (IS_CONTEXT(contextVal)) {
1328+
STORE_FRAME();
13141329
tableSet(&AS_CONTEXT(contextVal)->layers, name, OBJ_VAL(layer));
13151330
}
13161331
DISPATCH();

0 commit comments

Comments
 (0)