mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
added hook into garbage collector
This commit is contained in:
parent
ed6d2fcad7
commit
2c96dbe7ea
@ -44,6 +44,7 @@ class CVM : public VM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
~CVM() {
|
~CVM() {
|
||||||
|
c_data->clear();
|
||||||
delete c_data;
|
delete c_data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -95,9 +96,14 @@ bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) {
|
|||||||
SAFEGUARD_CLOSE
|
SAFEGUARD_CLOSE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gc_marker_ex(CVM* vm) {
|
||||||
|
for(PyObject* obj: *vm->c_data) if(obj!=nullptr) OBJ_MARK(obj);
|
||||||
|
}
|
||||||
|
|
||||||
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os) {
|
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os) {
|
||||||
CVM* vm = new CVM(use_stdio, enable_os);
|
CVM* vm = new CVM(use_stdio, enable_os);
|
||||||
vm->c_data = new ValueStackImpl<PKPY_STACK_SIZE>();
|
vm->c_data = new ValueStackImpl<PKPY_STACK_SIZE>();
|
||||||
|
vm->_gc_marker_ex = (void (*)(VM*)) gc_marker_ex;
|
||||||
return (pkpy_vm*) vm;
|
return (pkpy_vm*) vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ echo "compiling c executable"
|
|||||||
clang -c -o test.o c_bindings/test.c -Wfatal-errors -O2 -Wall -Wno-sign-compare -Wno-unused-variable -I src/ -fsanitize=address -g
|
clang -c -o test.o c_bindings/test.c -Wfatal-errors -O2 -Wall -Wno-sign-compare -Wno-unused-variable -I src/ -fsanitize=address -g
|
||||||
echo "linking"
|
echo "linking"
|
||||||
clang++ -o c_binding_test test.o pocketpy_c.o -stdlib=libc++ -fsanitize=address -g
|
clang++ -o c_binding_test test.o pocketpy_c.o -stdlib=libc++ -fsanitize=address -g
|
||||||
echo "running, no weird output should show up"
|
echo "running, leaksanitizer is finding a false postive leak in the CVM constructor"
|
||||||
|
echo "ignore that but pay attention to anything else"
|
||||||
./c_binding_test > binding_test_scratch
|
./c_binding_test > binding_test_scratch
|
||||||
echo "checking results (they should be identical)"
|
echo "checking results (they should be identical)"
|
||||||
diff -q -s binding_test_scratch c_bindings/test_answers.txt
|
diff -q -s binding_test_scratch c_bindings/test_answers.txt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user