wren
wren copied to clipboard
Segmentation fault when trying to create foreign class
Currently, when the bind foreign class callback returns { NULL, NULL }
like the following:
WrenForeignClassMethods APITest_bindForeignClass(
WrenVM* vm, const char* module, const char* className)
{
WrenForeignClassMethods methods = { NULL, NULL };
return methods;
}
Any attempt to create a class in Wren will result in segmentation fault.
In https://wren.io/embedding/storing-c-data.html, the code example given does just that.
I think Wren should throw an error about foreign class not defined when allocateFn
is NULL.
I also suspect that Wren might crash when a foreign class's finalizeFn
is NULL, but I haven't tried that.
To reproduce it, simply replace the above function in test/api/api_tests.c
and run:
> bin/wren_test test/api/foreign_class.wren
fish: Job 1, 'bin/wren_test test/api/foreign_…' terminated by signal SIGSEGV (Address boundary error)
Should trigger an error/assert in debug mode.
Should trigger an error/assert in debug mode.
I simply ran make
to build the static library.
Anyway, I think { NULL, _ }
should mean no foreign class is found. The current behavior is inconsistent with bindForeignMethodFn
, where returning NULL means no method is found and raise an error.
Possible duplicate of #811
Should trigger an error/assert in debug mode.
foreign class A {
construct new() {}
}
var a = A.new()