Make destructors of all generated Py class protected

This is to avoid to create an object on the stack and thus to clutter Python's reference counting mechanism
This commit is contained in:
wmayer
2018-09-19 18:22:22 +02:00
parent 360e581672
commit 5df6090150
2 changed files with 9 additions and 5 deletions

View File

@@ -203,10 +203,12 @@ std::string AreaPy::representation(void) const
PyObject *AreaPy::PyMake(struct _typeobject *, PyObject *args, PyObject *kwd) // Python wrapper
{
std::unique_ptr<AreaPy> ret(new AreaPy(new Area));
if(!ret->setParams(args,kwd))
AreaPy* ret = new AreaPy(new Area);
if(!ret->setParams(args,kwd)) {
Py_DecRef(ret);
return 0;
return ret.release();
}
return ret;
}
// constructor method

View File

@@ -56,6 +56,9 @@ namespace @self.export.Namespace@
*/
class @self.export.Namespace@Export @self.export.Name@ : public @self.export.FatherNamespace@::@self.export.Father@
{
protected:
~@self.export.Name@();
public:
static PyTypeObject Type;
static PyMethodDef Methods[];
@@ -76,8 +79,7 @@ public:
@self.export.Name@(@self.export.TwinPointer@ *pcObject, PyTypeObject *T = &Type);
static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
virtual int PyInit(PyObject* args, PyObject*k);
~@self.export.Name@();
+ if (self.export.Initialization):
int initialization();
int finalization();