Skip to content

Commit e94c813

Browse files
authored
Merge pull request wren-lang#698 from matusnovak/fix-foreign-allocate-abort-fiber
Fix wrenAbortFiber does not work inside of foreign class allocator
2 parents 740c365 + f91586a commit e94c813

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/vm/wren_vm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
11981198
CASE_CODE(FOREIGN_CONSTRUCT):
11991199
ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class.");
12001200
createForeign(vm, fiber, stackStart);
1201+
if (wrenHasError(fiber)) RUNTIME_ERROR();
12011202
DISPATCH();
12021203

12031204
CASE_CODE(CLOSURE):

test/api/foreign_class.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ static void resourceFinalize(void* data)
8282
finalized++;
8383
}
8484

85+
static void badClassAllocate(WrenVM* vm)
86+
{
87+
wrenEnsureSlots(vm, 1);
88+
wrenSetSlotString(vm, 0, "Something went wrong");
89+
wrenAbortFiber(vm, 0);
90+
}
91+
8592
WrenForeignMethodFn foreignClassBindMethod(const char* signature)
8693
{
8794
if (strcmp(signature, "static ForeignClass.finalized") == 0) return apiFinalized;
@@ -114,4 +121,10 @@ void foreignClassBindClass(
114121
methods->finalize = resourceFinalize;
115122
return;
116123
}
124+
125+
if (strcmp(className, "BadClass") == 0)
126+
{
127+
methods->allocate = badClassAllocate;
128+
return;
129+
}
117130
}

test/api/foreign_class.wren

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,13 @@ resources.clear()
7575

7676
System.gc()
7777
System.print(ForeignClass.finalized) // expect: 3
78+
79+
// Class that aborts fiber
80+
foreign class BadClass {
81+
construct new() {}
82+
}
83+
84+
error = Fiber.new {
85+
BadClass.new()
86+
}.try()
87+
System.print(error) // expect: Something went wrong

0 commit comments

Comments
 (0)