diff --git a/c_bindings/pocketpy_c.cpp b/c_bindings/pocketpy_c.cpp index 3126aed3..6abb7ef9 100644 --- a/c_bindings/pocketpy_c.cpp +++ b/c_bindings/pocketpy_c.cpp @@ -125,8 +125,8 @@ bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) { } void gc_marker_ex(CVM* vm) { - for(PyObject* obj: *vm->c_data) if(obj!=nullptr) OBJ_MARK(obj); - if(vm->error != nullptr) OBJ_MARK(vm->error); + for(PyObject* obj: *vm->c_data) if(obj!=nullptr) PK_OBJ_MARK(obj); + if(vm->error != nullptr) PK_OBJ_MARK(vm->error); } static OutputHandler stdout_handler = nullptr; diff --git a/src/codeobject.h b/src/codeobject.h index 406b2d4f..67eaa817 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -161,7 +161,7 @@ struct CodeObject { std::vector func_decls; void _gc_mark() const { - for(PyObject* v : consts) OBJ_MARK(v); + for(PyObject* v : consts) PK_OBJ_MARK(v); for(auto& decl: func_decls) decl->_gc_mark(); } diff --git a/src/dict.h b/src/dict.h index a83fbdf3..8b8ada21 100644 --- a/src/dict.h +++ b/src/dict.h @@ -142,8 +142,8 @@ struct Dict{ void _gc_mark() const{ for(int i=0; i<_capacity; i++){ if(_items[i].first == nullptr) continue; - OBJ_MARK(_items[i].first); - OBJ_MARK(_items[i].second); + PK_OBJ_MARK(_items[i].first); + PK_OBJ_MARK(_items[i].second); } } }; diff --git a/src/frame.h b/src/frame.h index 42cde59c..3266a749 100644 --- a/src/frame.h +++ b/src/frame.h @@ -194,7 +194,7 @@ struct Frame { } void _gc_mark() const { - OBJ_MARK(_module); + PK_OBJ_MARK(_module); co->_gc_mark(); } }; diff --git a/src/gc.h b/src/gc.h index b247b295..38ba286c 100644 --- a/src/gc.h +++ b/src/gc.h @@ -128,7 +128,7 @@ struct ManagedHeap{ inline void FuncDecl::_gc_mark() const{ code->_gc_mark(); - for(int i=0; i_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false; @@ -58,7 +58,7 @@ struct StringIter{ StringIter(PyObject* ref) : ref(ref), str(&PK_OBJ_GET(Str, ref)), index(0) {} - void _gc_mark() const{ OBJ_MARK(ref); } + void _gc_mark() const{ PK_OBJ_MARK(ref); } static void _register(VM* vm, PyObject* mod, PyObject* type){ vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false; @@ -85,7 +85,7 @@ struct Generator{ void _gc_mark() const{ frame._gc_mark(); - for(PyObject* obj: s_backup) OBJ_MARK(obj); + for(PyObject* obj: s_backup) PK_OBJ_MARK(obj); } PyObject* next(VM* vm){ diff --git a/src/memory.h b/src/memory.h index ec2d2893..85d0e357 100644 --- a/src/memory.h +++ b/src/memory.h @@ -168,6 +168,12 @@ struct MemoryPool{ } }; + MemoryPool() = default; + MemoryPool(const MemoryPool&) = delete; + MemoryPool& operator=(const MemoryPool&) = delete; + MemoryPool(MemoryPool&&) = delete; + MemoryPool& operator=(MemoryPool&&) = delete; + DoubleLinkedList _arenas; DoubleLinkedList _empty_arenas; diff --git a/src/obj.h b/src/obj.h index 0fd24697..623c4c94 100644 --- a/src/obj.h +++ b/src/obj.h @@ -201,7 +201,7 @@ struct MappingProxy{ #define PK_OBJ_GET(T, obj) (((Py_*)(obj))->_value) -#define OBJ_MARK(obj) \ +#define PK_OBJ_MARK(obj) \ if(!is_tagged(obj) && !(obj)->gc.marked) { \ (obj)->gc.marked = true; \ (obj)->_obj_gc_mark(); \ @@ -212,7 +212,7 @@ inline void gc_mark_namedict(NameDict& t){ if(t.size() == 0) return; for(uint16_t i=0; i final: PyObject { Py_(Type type, const List& val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - for(PyObject* obj: _value) OBJ_MARK(obj); + for(PyObject* obj: _value) PK_OBJ_MARK(obj); } }; @@ -319,7 +319,7 @@ struct Py_ final: PyObject { Py_(Type type, const Tuple& val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - for(PyObject* obj: _value) OBJ_MARK(obj); + for(PyObject* obj: _value) PK_OBJ_MARK(obj); } }; @@ -328,7 +328,7 @@ struct Py_ final: PyObject { MappingProxy _value; Py_(Type type, MappingProxy val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.obj); + PK_OBJ_MARK(_value.obj); } }; @@ -337,8 +337,8 @@ struct Py_ final: PyObject { BoundMethod _value; Py_(Type type, BoundMethod val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.self); - OBJ_MARK(_value.func); + PK_OBJ_MARK(_value.self); + PK_OBJ_MARK(_value.func); } }; @@ -347,7 +347,7 @@ struct Py_ final: PyObject { StarWrapper _value; Py_(Type type, StarWrapper val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.obj); + PK_OBJ_MARK(_value.obj); } }; @@ -356,8 +356,8 @@ struct Py_ final: PyObject { Property _value; Py_(Type type, Property val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.getter); - OBJ_MARK(_value.setter); + PK_OBJ_MARK(_value.getter); + PK_OBJ_MARK(_value.setter); } }; @@ -366,9 +366,9 @@ struct Py_ final: PyObject { Slice _value; Py_(Type type, Slice val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.start); - OBJ_MARK(_value.stop); - OBJ_MARK(_value.step); + PK_OBJ_MARK(_value.start); + PK_OBJ_MARK(_value.stop); + PK_OBJ_MARK(_value.step); } }; @@ -380,7 +380,7 @@ struct Py_ final: PyObject { } void _obj_gc_mark() override { _value.decl->_gc_mark(); - if(_value._module != nullptr) OBJ_MARK(_value._module); + if(_value._module != nullptr) PK_OBJ_MARK(_value._module); if(_value._closure != nullptr) gc_mark_namedict(*_value._closure); } }; @@ -399,7 +399,7 @@ struct Py_ final: PyObject { Super _value; Py_(Type type, Super val): PyObject(type), _value(val) {} void _obj_gc_mark() override { - OBJ_MARK(_value.first); + PK_OBJ_MARK(_value.first); } }; diff --git a/src/vm.h b/src/vm.h index 3c804f09..8959d9fe 100644 --- a/src/vm.h +++ b/src/vm.h @@ -1529,11 +1529,11 @@ inline void VM::_error(Exception e){ } inline void ManagedHeap::mark() { - for(PyObject* obj: _no_gc) OBJ_MARK(obj); + for(PyObject* obj: _no_gc) PK_OBJ_MARK(obj); for(auto& frame : vm->callstack.data()) frame._gc_mark(); - for(PyObject* obj: vm->s_data) OBJ_MARK(obj); + for(PyObject* obj: vm->s_data) PK_OBJ_MARK(obj); if(_gc_marker_ex) _gc_marker_ex(vm); - if(vm->_last_exception) OBJ_MARK(vm->_last_exception); + if(vm->_last_exception) PK_OBJ_MARK(vm->_last_exception); } inline Str obj_type_name(VM *vm, Type type){