🐛 try fixing segfault in module_test.nas
This commit is contained in:
parent
65dbe51c05
commit
2a36db1cf5
|
@ -47,6 +47,9 @@ struct ghost_obj {
|
||||||
var test_string = nil;
|
var test_string = nil;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if the dynamic library is closed, the pointer of this function will be unsafe
|
||||||
|
// make sure gc deletes the object before closing the dynamic library
|
||||||
|
// or just do not close the dynamic library...
|
||||||
void ghost_for_test_destructor(void* ptr) {
|
void ghost_for_test_destructor(void* ptr) {
|
||||||
std::cout << "ghost_for_test::destructor (0x";
|
std::cout << "ghost_for_test::destructor (0x";
|
||||||
std::cout << std::hex << reinterpret_cast<u64>(ptr) << std::dec << ") {\n";
|
std::cout << std::hex << reinterpret_cast<u64>(ptr) << std::dec << ") {\n";
|
||||||
|
@ -69,7 +72,7 @@ var create_new_ghost(var* args, usize size, gc* ngc) {
|
||||||
var res = ngc->alloc(vm_type::vm_ghost);
|
var res = ngc->alloc(vm_type::vm_ghost);
|
||||||
res.ghost().set(
|
res.ghost().set(
|
||||||
ghost_for_test,
|
ghost_for_test,
|
||||||
nullptr,
|
ghost_for_test_destructor,
|
||||||
ghost_for_test_gc_marker,
|
ghost_for_test_gc_marker,
|
||||||
new ghost_obj
|
new ghost_obj
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,10 +53,10 @@ println("[time ] ", tm.elapsedMSec()," ms");
|
||||||
tm.stamp();
|
tm.stamp();
|
||||||
println("[result] ", libfib.qfib(35));
|
println("[result] ", libfib.qfib(35));
|
||||||
println("[time ] ", tm.elapsedMSec()," ms");
|
println("[time ] ", tm.elapsedMSec()," ms");
|
||||||
libfib.close();
|
# libfib.close();
|
||||||
println("[result] ", libfib.fib(35));
|
println("[result] ", libfib.fib(35));
|
||||||
println("[result] ", libfib.qfib(35));
|
println("[result] ", libfib.qfib(35));
|
||||||
libfib.close();
|
# libfib.close();
|
||||||
|
|
||||||
var speed_test = func() {
|
var speed_test = func() {
|
||||||
var d = dylib.dlopen("libfib."~(os.platform()=="windows"? "dll":"so"));
|
var d = dylib.dlopen("libfib."~(os.platform()=="windows"? "dll":"so"));
|
||||||
|
|
Loading…
Reference in New Issue