I have the following C++ class :
.H
class ALabSet: public LabSet {
public:
PyObject *m_obj;
ALabSet(PyObject *obj);
virtual ~ALabSet();
PyObject *GetPyObj();
};
.CPP
ALabSet::ALabSet(PyObject *obj): LabSet() {
this->m_obj = obj;
// Provided by "cyelp_api.h"
if (import_cyelp()) {
} else {
Py_XINCREF(this->m_obj);
}
}
ALabSet::~ALabSet() {
Py_XDECREF(this->m_obj);
}
PyObject *ALabSet::GetPyObj() {
return this->m_obj;
}
I exposed it as follows with Cython :
cdef extern from "adapter/ALabSiteSetsManager.h" namespace "elps" :
cdef cppclass ALabSet:
ALabSet(PyObject *)
PyObject *GetPyObj()
cdef class PyLabSet:
cdef ALabSet *thisptr
def __cinit__(self):
self.thisptr = new ALabSet(<PyObject *>self)
def __dealloc__(self):
print "delete from PY !"
if self.thisptr:
del self.thisptr
My problem is that I can't figure out how to get the destructor called from Python. The following does exactly nothing :
a_set = PyLabSet()
del a_set
I can't find similar issues on the web. Does any of you has an idea of is appening to me here ?
I'm I missing something about reference counting management, or ...
Thanks a lot
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…