From 1040f7f6ec9cf689d6530827348a63daad52b3ef Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 8 Jun 2009 17:17:48 +0200 Subject: python/generic.h,tag.cc,configuration.cc: Use tp_alloc/tp_free instead of PyObject_NEW/DEL This allows us to finally implement subclassing. Previously deletion of an instance of a subclass caused segmentation faults, this is not the case anymore. --- python/generic.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'python/generic.h') diff --git a/python/generic.h b/python/generic.h index ae2871e3..df4d8755 100644 --- a/python/generic.h +++ b/python/generic.h @@ -99,7 +99,7 @@ inline PyObject *GetOwner(PyObject *Obj) template inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) { - CppPyObject *New = PyObject_NEW(CppPyObject,Type); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; return New; } @@ -107,7 +107,7 @@ inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) template inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type,A const &Arg) { - CppPyObject *New = PyObject_NEW(CppPyObject,Type); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); return New; } @@ -116,7 +116,7 @@ template inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type) { - CppOwnedPyObject *New = PyObject_NEW(CppOwnedPyObject,Type); + CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; New->Owner = Owner; Py_INCREF(Owner); @@ -127,7 +127,7 @@ template inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type,A const &Arg) { - CppOwnedPyObject *New = PyObject_NEW(CppOwnedPyObject,Type); + CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); New->Owner = Owner; if (Owner != 0) @@ -140,7 +140,7 @@ template void CppDealloc(PyObject *Obj) { GetCpp(Obj).~T(); - PyObject_DEL(Obj); + Obj->ob_type->tp_free(Obj); } template @@ -150,7 +150,7 @@ void CppOwnedDealloc(PyObject *iObj) Obj->Object.~T(); if (Obj->Owner != 0) Py_DECREF(Obj->Owner); - PyObject_DEL(Obj); + iObj->ob_type->tp_free(iObj); } inline PyObject *CppPyString(std::string Str) -- cgit v1.2.3