🐛 delete dlclose in module_test.nas

This commit is contained in:
ValKmjolnir 2023-12-06 21:17:53 +08:00
parent 2a36db1cf5
commit a2c738d4c7
2 changed files with 11 additions and 53 deletions

View File

@ -19,32 +19,26 @@ var _call = dylib.limitcall(1);
var _test_call = dylib.limitcall(2);
var fib = func(x) {
return _call(_fib, x)
}
var qfib = func(x) {
return _call(_qfib, x)
}
var create_ghost = func() {
return _zero_call(_create_ghost)
}
var set_ghost = func(object, x) {
return _test_call(_set_ghost, object, x)
}
var print_ghost = func(object) {
return _call(_print_ghost, object)
}
var test_ghost = func() {
var ghost = create_ghost();
print_ghost(nil); # err

View File

@ -5,47 +5,7 @@ use module.libfib;
println(keys(libfib));
libfib.test_ghost();
var libfib = func() {
var (dd, fib, qfib) = (nil, nil, nil);
var invoke = dylib.limitcall(1);
return {
open: func() {
if (dd==nil) {
dd = dylib.dlopen("libfib."~(os.platform()=="windows"?"dll":"so"));
fib = dd.fib;
qfib = dd.quick_fib;
} else {
println("[info ] already loaded.");
}
},
close: func() {
if (dd==nil) {
println("[error ] already closed.");
return;
}
dylib.dlclose(dd.lib);
(dd, fib, qfib) = (nil, nil, nil);
},
fib: func(x) {
if (fib!=nil) {
return invoke(fib, x);
}
println("[error ] cannot call fib.");
return nil;
},
qfib: func(x) {
if (qfib!=nil) {
return invoke(qfib, x);
}
println("[error ] cannot call qfib.");
return nil;
}
}
}();
println("[keys ] ", keys(libfib));
libfib.open();
libfib.open();
var tm = maketimestamp();
tm.stamp();
println("[result] ", libfib.fib(35));
@ -53,15 +13,19 @@ println("[time ] ", tm.elapsedMSec()," ms");
tm.stamp();
println("[result] ", libfib.qfib(35));
println("[time ] ", tm.elapsedMSec()," ms");
# libfib.close();
println("[result] ", libfib.fib(35));
println("[result] ", libfib.qfib(35));
# libfib.close();
println();
func() {
for(var i = 0; i<256; i += 1) {
var tmp = []; # try trigger gc here to test delete ghost
}
println();
}();
var speed_test = func() {
var d = dylib.dlopen("libfib."~(os.platform()=="windows"? "dll":"so"));
println("[dylib ] ", d);
var fd = d.quick_fib;
var dd = dylib.dlopen("libfib."~(os.platform()=="windows"? "dll":"so"));
println("[dylib ] ", dd);
var fd = dd.quick_fib;
var vec_call = dylib.dlcall;
var invoke = dylib.limitcall(1);
var tm = maketimestamp();