refactor: replace finalizer fiber with raw data pointer callback

Remove the dedicated finalizer fiber from WrenVM and change finalizer functions to accept a void* data pointer instead of a full WrenVM reference. This prevents user code from interacting with the VM during garbage collection, simplifying the GC path and eliminating the need for pre-allocated fiber infrastructure. Update the WrenForeignClassMethods struct, all built-in finalizers (file, test), and the binding/calling logic accordingly.
This commit is contained in:
Bob Nystrom
2015-12-28 16:06:29 +00:00
parent 6abebbe906
commit 1797c6c977
7 changed files with 31 additions and 37 deletions
+7 -2
View File
@@ -69,11 +69,16 @@ static void pointToString(WrenVM* vm)
static void resourceAllocate(WrenVM* vm)
{
wrenAllocateForeign(vm, 0);
int* value = (int*)wrenAllocateForeign(vm, sizeof(int));
*value = 123;
}
static void resourceFinalize(WrenVM* vm)
static void resourceFinalize(void* data)
{
// Make sure we get the right data back.
int* value = (int*)data;
if (*value != 123) exit(1);
finalized++;
}
+10
View File
@@ -0,0 +1,10 @@
import "io" for File
// Don't store in a variable.
File.open("test/io/file/finalize.wren")
System.gc()
// We can't really test what the finalizer *does* from Wren, since the object
// is unreachable, but this at least ensures it doesn't crash.
System.print("ok") // expect: ok