mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-09 21:28:39 +01:00
Fix slot array corrupted by wrenInterpret() (#730)
This commit is contained in:
@ -1446,8 +1446,12 @@ WrenInterpretResult wrenInterpret(WrenVM* vm, const char* module,
|
||||
wrenPushRoot(vm, (Obj*)closure);
|
||||
ObjFiber* fiber = wrenNewFiber(vm, closure);
|
||||
wrenPopRoot(vm); // closure.
|
||||
|
||||
return runInterpreter(vm, fiber);
|
||||
|
||||
WrenInterpretResult result = runInterpreter(vm, fiber);
|
||||
|
||||
vm->fiber = NULL;
|
||||
vm->apiStack = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
ObjClosure* wrenCompileSource(WrenVM* vm, const char* module, const char* source,
|
||||
|
||||
@ -13,9 +13,43 @@ static void nullConfig(WrenVM* vm)
|
||||
wrenFreeVM(otherVM);
|
||||
}
|
||||
|
||||
static void multipleInterpretCalls(WrenVM* vm)
|
||||
{
|
||||
WrenVM* otherVM = wrenNewVM(NULL);
|
||||
WrenInterpretResult result;
|
||||
|
||||
bool correct = true;
|
||||
|
||||
// Handles should be valid across calls into Wren code.
|
||||
WrenHandle* absMethod = wrenMakeCallHandle(otherVM, "abs");
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// Calling `wrenEnsureSlots()` before `wrenInterpret()` should not introduce
|
||||
// problems later.
|
||||
wrenEnsureSlots(otherVM, 2);
|
||||
|
||||
result = wrenInterpret(otherVM, "main", "1 + 2");
|
||||
correct = correct && (result == WREN_RESULT_SUCCESS);
|
||||
|
||||
wrenEnsureSlots(otherVM, 2);
|
||||
wrenSetSlotDouble(otherVM, 0, -i);
|
||||
result = wrenCall(otherVM, absMethod);
|
||||
correct = correct && (result == WREN_RESULT_SUCCESS);
|
||||
|
||||
double absValue = wrenGetSlotDouble(otherVM, 0);
|
||||
correct = correct && (absValue == (double)i);
|
||||
}
|
||||
|
||||
wrenSetSlotBool(vm, 0, correct);
|
||||
|
||||
wrenReleaseHandle(otherVM, absMethod);
|
||||
wrenFreeVM(otherVM);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn newVMBindMethod(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static VM.nullConfig()") == 0) return nullConfig;
|
||||
if (strcmp(signature, "static VM.multipleInterpretCalls()") == 0) return multipleInterpretCalls;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
class VM {
|
||||
foreign static nullConfig()
|
||||
foreign static multipleInterpretCalls()
|
||||
}
|
||||
// TODO: Other configuration settings.
|
||||
|
||||
System.print(VM.nullConfig()) // expect: true
|
||||
System.print(VM.multipleInterpretCalls()) // expect: true
|
||||
|
||||
Reference in New Issue
Block a user