Commit 2bcc2325 authored by Xavier Thompson's avatar Xavier Thompson

Deallocate cypclass wrapper in cyobject destructor

parent 80fcedd4
...@@ -589,7 +589,6 @@ def generate_cyp_class_attrs_destructor_definition(entry, code): ...@@ -589,7 +589,6 @@ def generate_cyp_class_attrs_destructor_definition(entry, code):
code.putln("Cy_XDECREF(this->%s);" % attr.cname) code.putln("Cy_XDECREF(this->%s);" % attr.cname)
code.putln("}") code.putln("}")
def generate_cyp_class_activate_function(entry, code): def generate_cyp_class_activate_function(entry, code):
""" """
Generate activate function for activable cypclass entries Generate activate function for activable cypclass entries
...@@ -1042,7 +1041,9 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry ...@@ -1042,7 +1041,9 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
objstruct_cname = type.wrapper_type.objstruct_cname objstruct_cname = type.wrapper_type.objstruct_cname
cclass_wrapper_base = type.wrapped_base_type().wrapper_type cclass_wrapper_base = type.wrapped_base_type().wrapper_type
code.putln("if(self) {") code.putln("if(self) {")
code.putln("%s * wrapper = new %s();" % (objstruct_cname, objstruct_cname)) code.putln("printf(\"allocating wrapper for %s cypclass\\n\");" % type.name)
code.putln("%s * wrapper = (%s *) ::operator new(sizeof *wrapper);" % (objstruct_cname, objstruct_cname))
code.putln("printf(\"allocated wrapper object @ %p\\n\\n\", wrapper);")
code.putln("((%s *)wrapper)->%s = self;" % (cclass_wrapper_base.objstruct_cname, Naming.cypclass_attr_cname)) code.putln("((%s *)wrapper)->%s = self;" % (cclass_wrapper_base.objstruct_cname, Naming.cypclass_attr_cname))
code.putln("PyObject * wrapper_as_py = (PyObject *) wrapper;") code.putln("PyObject * wrapper_as_py = (PyObject *) wrapper;")
code.putln("wrapper_as_py->ob_refcnt = 0;") code.putln("wrapper_as_py->ob_refcnt = 0;")
......
...@@ -63,8 +63,8 @@ ...@@ -63,8 +63,8 @@
RecursiveUpgradeableRWLock ob_lock; RecursiveUpgradeableRWLock ob_lock;
public: public:
PyObject * cy_pyobject; PyObject * cy_pyobject;
CyObject(): nogil_ob_refcnt(1) {} CyObject(): nogil_ob_refcnt(1), cy_pyobject(NULL) {}
virtual ~CyObject() {} virtual ~CyObject();
void CyObject_INCREF(); void CyObject_INCREF();
int CyObject_DECREF(); int CyObject_DECREF();
void CyObject_RLOCK(); void CyObject_RLOCK();
...@@ -446,6 +446,14 @@ int RecursiveUpgradeableRWLock::trywlock() { ...@@ -446,6 +446,14 @@ int RecursiveUpgradeableRWLock::trywlock() {
return 0; return 0;
} }
CyObject::~CyObject() {
if (cy_pyobject) {
printf("deleting wrapper object @ %p\n", cy_pyobject);
printf("python refcount: %ld\n", cy_pyobject->ob_refcnt);
::operator delete(cy_pyobject);
printf("wrapper deleted\n\n");
}
}
void CyObject::CyObject_INCREF() void CyObject::CyObject_INCREF()
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment