diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-06-08 17:17:48 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-06-08 17:17:48 +0200 |
| commit | 1040f7f6ec9cf689d6530827348a63daad52b3ef (patch) | |
| tree | e043184e4e1ee74126059881a03b38a3a845f611 /python | |
| parent | 857774704739c39a68a1e72914a82e001e62ec93 (diff) | |
| download | python-apt-1040f7f6ec9cf689d6530827348a63daad52b3ef.tar.gz | |
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.
Diffstat (limited to 'python')
| -rw-r--r-- | python/configuration.cc | 3 | ||||
| -rw-r--r-- | python/generic.h | 12 | ||||
| -rw-r--r-- | python/tag.cc | 8 |
3 files changed, 12 insertions, 11 deletions
diff --git a/python/configuration.cc b/python/configuration.cc index 81dd78ac..3c6ea88c 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -161,7 +161,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) } // Create a new sub configuration. - SubConfiguration *New = PyObject_NEW(SubConfiguration,&ConfigurationSubType); + SubConfiguration *New = (SubConfiguration*)(&ConfigurationSubType) + ->tp_alloc(&ConfigurationSubType,0); new (&New->Object) Configuration(Itm); New->Owner = Self; Py_INCREF(Self); 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 <class T> inline CppPyObject<T> *CppPyObject_NEW(PyTypeObject *Type) { - CppPyObject<T> *New = PyObject_NEW(CppPyObject<T>,Type); + CppPyObject<T> *New = (CppPyObject<T>*)Type->tp_alloc(Type, 0); new (&New->Object) T; return New; } @@ -107,7 +107,7 @@ inline CppPyObject<T> *CppPyObject_NEW(PyTypeObject *Type) template <class T,class A> inline CppPyObject<T> *CppPyObject_NEW(PyTypeObject *Type,A const &Arg) { - CppPyObject<T> *New = PyObject_NEW(CppPyObject<T>,Type); + CppPyObject<T> *New = (CppPyObject<T>*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); return New; } @@ -116,7 +116,7 @@ template <class T> inline CppOwnedPyObject<T> *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type) { - CppOwnedPyObject<T> *New = PyObject_NEW(CppOwnedPyObject<T>,Type); + CppOwnedPyObject<T> *New = (CppOwnedPyObject<T>*)Type->tp_alloc(Type, 0); new (&New->Object) T; New->Owner = Owner; Py_INCREF(Owner); @@ -127,7 +127,7 @@ template <class T,class A> inline CppOwnedPyObject<T> *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type,A const &Arg) { - CppOwnedPyObject<T> *New = PyObject_NEW(CppOwnedPyObject<T>,Type); + CppOwnedPyObject<T> *New = (CppOwnedPyObject<T>*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); New->Owner = Owner; if (Owner != 0) @@ -140,7 +140,7 @@ template <class T> void CppDealloc(PyObject *Obj) { GetCpp<T>(Obj).~T(); - PyObject_DEL(Obj); + Obj->ob_type->tp_free(Obj); } template <class T> @@ -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) diff --git a/python/tag.cc b/python/tag.cc index 5a31488c..31491c90 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -68,7 +68,7 @@ void TagFileFree(PyObject *Obj) Self->Object.~pkgTagFile(); Self->Fd.~FileFd(); Py_DECREF(Self->File); - PyObject_DEL(Obj); + Obj->ob_type->tp_free(Obj); } /*}}}*/ @@ -246,7 +246,7 @@ static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { return 0; // Create the object.. - TagSecData *New = PyObject_NEW(TagSecData,type); + TagSecData *New = (TagSecData*)type->tp_alloc(type, 0); new (&New->Object) pkgTagSection(); New->Data = new char[strlen(Data)+2]; snprintf(New->Data,strlen(Data)+2,"%s\n",Data); @@ -286,14 +286,14 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) if (fileno == -1) return 0; - TagFileData *New = PyObject_NEW(TagFileData,type); + TagFileData *New = (TagFileData*)type->tp_alloc(type, 0); new (&New->Fd) FileFd(fileno,false); New->File = File; Py_INCREF(New->File); new (&New->Object) pkgTagFile(&New->Fd); // Create the section - New->Section = PyObject_NEW(TagSecData,&TagSecType); + New->Section = (TagSecData*)(&TagSecType)->tp_alloc(&TagSecType, 0); new (&New->Section->Object) pkgTagSection(); New->Section->Data = 0; |
