From d24964f86e1108f88d55a9580bbd6d2e482562dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 27 Jan 2010 15:11:39 +0100 Subject: Merge the CppOwnedPyObject C++ class into CppPyObject. --- python/acquire-item.cc | 18 ++++---- python/acquire.cc | 24 +++++----- python/apt_instmodule.h | 2 +- python/apt_pkgmodule.cc | 4 +- python/arfile.cc | 32 +++++++------- python/cache.cc | 114 ++++++++++++++++++++++++------------------------ python/cdrom.cc | 2 +- python/configuration.cc | 8 ++-- python/depcache.cc | 42 +++++++++--------- python/generic.h | 93 ++++++++++----------------------------- python/hashes.cc | 2 +- python/hashstring.cc | 2 +- python/indexfile.cc | 8 ++-- python/indexrecords.cc | 2 +- python/metaindex.cc | 8 ++-- python/pkgmanager.cc | 2 +- python/pkgrecords.cc | 10 ++--- python/pkgsrcrecords.cc | 8 ++-- python/policy.cc | 14 +++--- python/python-apt.h | 61 +++++++++++--------------- python/sourcelist.cc | 10 ++--- python/tag.cc | 10 ++--- python/tarfile.cc | 20 ++++----- 23 files changed, 218 insertions(+), 278 deletions(-) (limited to 'python') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 059f1802..d5f9ad10 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -159,13 +159,13 @@ static PyObject *acquireitem_repr(PyObject *Self) static void acquireitem_dealloc(PyObject *self) { - CppOwnedDeallocPtr(self); + CppDeallocPtr(self); } PyTypeObject PyAcquireItem_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItem", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods acquireitem_dealloc, // tp_dealloc @@ -186,8 +186,8 @@ PyTypeObject PyAcquireItem_Type = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "AcquireItem Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -222,7 +222,7 @@ static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * shortDescr, destDir, destFile); // short-desc - CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); + CppPyObject *AcqFileObj = CppPyObject_NEW(pyfetcher, type); AcqFileObj->Object = af; return AcqFileObj; } @@ -237,7 +237,7 @@ static char *acquirefile_doc = PyTypeObject PyAcquireFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireFile", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods acquireitem_dealloc, // tp_dealloc @@ -259,8 +259,8 @@ PyTypeObject PyAcquireFile_Type = { Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, acquirefile_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -309,7 +309,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) shortDescr, destDir, destFile); // short-desc - CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); + CppPyObject *AcqFileObj = CppPyObject_NEW(NULL, &PyAcquireFile_Type); AcqFileObj->Object = af; AcqFileObj->NoDelete = true; diff --git a/python/acquire.cc b/python/acquire.cc index bcb76d67..cd7f7709 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -77,10 +77,10 @@ static PyGetSetDef acquireworker_getset[] = { PyTypeObject PyAcquireWorker_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireWorker", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -98,8 +98,8 @@ PyTypeObject PyAcquireWorker_Type = { Py_TPFLAGS_DEFAULT| // tp_flags Py_TPFLAGS_HAVE_GC, 0, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -132,7 +132,7 @@ static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); return item ? CppPyString(item->ShortDesc) : NULL; } -static PyObject *acquireitemdesc_get_owner(CppOwnedPyObject *self, void *closure) +static PyObject *acquireitemdesc_get_owner(CppPyObject *self, void *closure) { if (self->Owner != NULL) { Py_INCREF(self->Owner); @@ -160,10 +160,10 @@ static char *acquireitemdesc_doc = PyTypeObject PyAcquireItemDesc_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItemDesc", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -181,8 +181,8 @@ PyTypeObject PyAcquireItemDesc_Type = { (Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC), acquireitemdesc_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppTraverse,// tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -255,7 +255,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) { PyObject *List = PyList_New(0); pkgAcquire *Owner = GetCpp(self); - CppOwnedPyObject *PyWorker = NULL; + CppPyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); @@ -313,7 +313,7 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) fetcher = new pkgAcquire(); } - PyObject *FetcherObj = CppPyObject_NEW(type, fetcher); + PyObject *FetcherObj = CppPyObject_NEW(NULL, type, fetcher); if (progress != 0) progress->setPyAcquire(FetcherObj); @@ -325,7 +325,7 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) * Create a new apt_pkg.Acquire Python object from the pkgAcquire object. */ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete) { - CppPyObject *obj = CppPyObject_NEW(&PyAcquire_Type, fetcher); + CppPyObject *obj = CppPyObject_NEW(NULL, &PyAcquire_Type, fetcher); obj->NoDelete = (!Delete); return obj; } diff --git a/python/apt_instmodule.h b/python/apt_instmodule.h index 2b07261b..f6b337f4 100644 --- a/python/apt_instmodule.h +++ b/python/apt_instmodule.h @@ -27,7 +27,7 @@ extern PyTypeObject PyDebFile_Type; extern PyTypeObject PyTarFile_Type; extern PyTypeObject PyTarMember_Type; -struct PyTarFileObject : public CppOwnedPyObject { +struct PyTarFileObject : public CppPyObject { int min; FileFd Fd; }; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 64db74d2..e77fd3ca 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -56,7 +56,7 @@ static PyObject *newConfiguration(PyObject *self,PyObject *args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type, new Configuration()); + return CppPyObject_NEW(NULL, &PyConfiguration_Type, new Configuration()); } #endif /*}}}*/ @@ -599,7 +599,7 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppOwnedPyObject *Config = CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type); + CppPyObject *Config = CppPyObject_NEW(NULL, &PyConfiguration_Type); Config->Object = _config; // Global configuration, should never be deleted. Config->NoDelete = true; diff --git a/python/arfile.cc b/python/arfile.cc index 1abb738f..4f95a791 100644 --- a/python/arfile.cc +++ b/python/arfile.cc @@ -93,10 +93,10 @@ static const char *armember_doc = PyTypeObject PyArMember_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_inst.ArMember", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -114,8 +114,8 @@ PyTypeObject PyArMember_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, armember_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppTraverse,// tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -135,7 +135,7 @@ public: } }; -struct PyArArchiveObject : public CppOwnedPyObject { +struct PyArArchiveObject : public CppPyObject { FileFd Fd; }; @@ -146,7 +146,7 @@ static const char *ararchive_getmember_doc = static PyObject *ararchive_getmember(PyArArchiveObject *self, PyObject *arg) { const char *name; - CppOwnedPyObject *ret; + CppPyObject *ret; if (! (name = PyObject_AsString(arg))) return 0; @@ -157,7 +157,7 @@ static PyObject *ararchive_getmember(PyArArchiveObject *self, PyObject *arg) } // Create our object. - ret = CppOwnedPyObject_NEW(self,&PyArMember_Type); + ret = CppPyObject_NEW(self,&PyArMember_Type); ret->Object = const_cast(member); ret->NoDelete = true; return ret; @@ -302,7 +302,7 @@ static PyObject *ararchive_gettar(PyArArchiveObject *self, PyObject *args) return 0; } - PyTarFileObject *tarfile = (PyTarFileObject*)CppOwnedPyObject_NEW(self,&PyTarFile_Type); + PyTarFileObject *tarfile = (PyTarFileObject*)CppPyObject_NEW(self,&PyTarFile_Type); new (&tarfile->Fd) FileFd(self->Fd); tarfile->min = member->Start; tarfile->Object = new ExtractTar(self->Fd, member->Size, comp); @@ -317,8 +317,8 @@ static PyObject *ararchive_getmembers(PyArArchiveObject *self) PyObject *list = PyList_New(0); ARArchive::Member *member = self->Object->Members(); do { - CppOwnedPyObject *ret; - ret = CppOwnedPyObject_NEW(self,&PyArMember_Type); + CppPyObject *ret; + ret = CppPyObject_NEW(self,&PyArMember_Type); ret->Object = member; ret->NoDelete = true; PyList_Append(list, ret); @@ -380,14 +380,14 @@ static PyObject *ararchive_new(PyTypeObject *type, PyObject *args, // We receive a filename. if ((filename = (char*)PyObject_AsString(file))) { - self = (PyArArchiveObject *)CppOwnedPyObject_NEW(0,type); + self = (PyArArchiveObject *)CppPyObject_NEW(0,type); new (&self->Fd) FileFd(filename,FileFd::ReadOnly); } // We receive a file object. else if ((fileno = PyObject_AsFileDescriptor(file)) != -1) { // Clear the error set by PyObject_AsString(). PyErr_Clear(); - self = (PyArArchiveObject *)CppOwnedPyObject_NEW(file,type); + self = (PyArArchiveObject *)CppPyObject_NEW(file,type); new (&self->Fd) FileFd(fileno,false); } else { @@ -402,7 +402,7 @@ static PyObject *ararchive_new(PyTypeObject *type, PyObject *args, static void ararchive_dealloc(PyObject *self) { ((PyArArchiveObject *)(self))->Fd.~FileFd(); - CppOwnedDeallocPtr(self); + CppDeallocPtr(self); } // Return bool or -1 (exception). @@ -455,8 +455,8 @@ PyTypeObject PyArArchive_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, ararchive_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset (getiterfunc)ararchive_iter, // tp_iter @@ -511,7 +511,7 @@ static PyObject *_gettar(PyDebFileObject *self, const ARArchive::Member *m, { if (!m) return 0; - PyTarFileObject *tarfile = (PyTarFileObject*)CppOwnedPyObject_NEW(self,&PyTarFile_Type); + PyTarFileObject *tarfile = (PyTarFileObject*)CppPyObject_NEW(self,&PyTarFile_Type); new (&tarfile->Fd) FileFd(self->Fd); tarfile->min = m->Start; tarfile->Object = new ExtractTar(self->Fd, m->Size, comp); diff --git a/python/cache.cc b/python/cache.cc index 6bbf0766..fe6e8b68 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -73,7 +73,7 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) { PyObject *Obj; PyObject *Ver; - Ver = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + Ver = CppPyObject_NEW(Owner,&PyVersion_Type, I.OwnerVer()); Obj = Py_BuildValue("ssN",I.ParentPkg().Name(),I.ProvideVersion(), Ver); @@ -162,7 +162,7 @@ static PyMethodDef PkgCacheMethods[] = static PyObject *PkgCacheGetPackages(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); - return CppOwnedPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); + return CppPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); } static PyObject *PkgCacheGetPackageCount(PyObject *Self, void*) { @@ -200,7 +200,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&PyPackageFile_Type,I); + Obj = CppPyObject_NEW(Self,&PyPackageFile_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -250,7 +250,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return 0; } - return CppOwnedPyObject_NEW(Self,&PyPackage_Type,Pkg); + return CppPyObject_NEW(Self,&PyPackage_Type,Pkg); } static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) @@ -292,11 +292,11 @@ static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) return HandleErrors(); } - CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PyCacheFile_Type, Cache); + CppPyObject *CacheFileObj = + CppPyObject_NEW(0,&PyCacheFile_Type, Cache); - CppOwnedPyObject *CacheObj = - CppOwnedPyObject_NEW(CacheFileObj,type, + CppPyObject *CacheObj = + CppPyObject_NEW(CacheFileObj,type, (pkgCache *)(*Cache)); // Do not delete the pointer to the pkgCache, it is managed by pkgCacheFile. @@ -317,10 +317,10 @@ PyTypeObject PyCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cache", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -339,8 +339,8 @@ PyTypeObject PyCache_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgCache, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -364,10 +364,10 @@ PyTypeObject PyCacheFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "pkgCacheFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -418,7 +418,7 @@ static PyObject *PkgListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, + return CppPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, Self.Iter); } @@ -437,10 +437,10 @@ PyTypeObject PyPackageList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageList", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -457,8 +457,8 @@ PyTypeObject PyPackageList_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags 0, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear }; #define Owner (GetOwner(Self)) @@ -470,7 +470,7 @@ PyTypeObject PyPackageList_Type = MkGet(PackageGetName,PyString_FromString(Pkg.Name())) MkGet(PackageGetSection,Safe_FromString(Pkg.Section())) -MkGet(PackageGetRevDependsList,CppOwnedPyObject_NEW(Owner, +MkGet(PackageGetRevDependsList,CppPyObject_NEW(Owner, &PyDependencyList_Type, Pkg.RevDependsList())) MkGet(PackageGetProvidesList,CreateProvides(Owner,Pkg.ProvidesList())) MkGet(PackageGetSelectedState,Py_BuildValue("i",Pkg->SelectedState)) @@ -493,7 +493,7 @@ static PyObject *PackageGetVersionList(PyObject *Self,void*) for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type,I); + Obj = CppPyObject_NEW(Owner,&PyVersion_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -508,7 +508,7 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) Py_INCREF(Py_None); return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + return CppPyObject_NEW(Owner,&PyVersion_Type, Pkg.CurrentVer()); } @@ -558,10 +558,10 @@ PyTypeObject PyPackage_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Package", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -578,8 +578,8 @@ PyTypeObject PyPackage_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Package Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -612,7 +612,7 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) { PyObject *DescFile; PyObject *Obj; - DescFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); + DescFile = CppPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",DescFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -643,10 +643,10 @@ PyTypeObject PyDescription_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Description", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -663,8 +663,8 @@ PyTypeObject PyDescription_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "apt_pkg.Description Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -711,7 +711,7 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, { PyObject *Obj; if (AsObj == true) - Obj = CppOwnedPyObject_NEW(Owner,&PyDependency_Type, + Obj = CppPyObject_NEW(Owner,&PyDependency_Type, Start); else { @@ -763,7 +763,7 @@ static PyObject *VersionGetFileList(PyObject *Self, void*) { { PyObject *PkgFile; PyObject *Obj; - PkgFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); + PkgFile = CppPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",PkgFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -783,7 +783,7 @@ static PyObject *VersionGetDependsList(PyObject *Self, void*) { } static PyObject *VersionGetParentPkg(PyObject *Self, void*) { PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Version_GetVer(Self).ParentPkg()); } static PyObject *VersionGetProvidesList(PyObject *Self, void*) { @@ -814,7 +814,7 @@ static PyObject *VersionGetDownloadable(PyObject *Self, void*) { static PyObject *VersionGetTranslatedDescription(PyObject *Self, void*) { pkgCache::VerIterator &Ver = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner, + return CppPyObject_NEW(Owner, &PyDescription_Type, Ver.TranslatedDescription()); } @@ -894,10 +894,10 @@ PyTypeObject PyVersion_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Version", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -914,8 +914,8 @@ PyTypeObject PyVersion_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Version Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1057,9 +1057,9 @@ static PyGetSetDef PackageFileGetSet[] = { PyTypeObject PyPackageFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1076,8 +1076,8 @@ PyTypeObject PyPackageFile_Type = { 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "apt_pkg.PackageFile Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1113,7 +1113,7 @@ static PyObject *DepSmartTargetPkg(PyObject *Self,PyObject *Args) return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type,P); + return CppPyObject_NEW(Owner,&PyPackage_Type,P); } static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) @@ -1129,7 +1129,7 @@ static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) for (pkgCache::Version **I = Vers; *I != 0; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + Obj = CppPyObject_NEW(Owner,&PyVersion_Type, pkgCache::VerIterator(*Dep.Cache(),*I)); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -1163,7 +1163,7 @@ static PyObject *DependencyGetTargetPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Dep.TargetPkg()); } @@ -1171,7 +1171,7 @@ static PyObject *DependencyGetParentVer(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + return CppPyObject_NEW(Owner,&PyVersion_Type, Dep.ParentVer()); } @@ -1179,7 +1179,7 @@ static PyObject *DependencyGetParentPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Dep.ParentPkg()); } @@ -1240,10 +1240,10 @@ PyTypeObject PyDependency_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Dependency", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1260,8 +1260,8 @@ PyTypeObject PyDependency_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Dependency Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1306,7 +1306,7 @@ static PyObject *RDepListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf), + return CppPyObject_NEW(GetOwner(iSelf), &PyDependency_Type,Self.Iter); } @@ -1325,10 +1325,10 @@ PyTypeObject PyDependencyList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DependencyList", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1345,8 +1345,8 @@ PyTypeObject PyDependencyList_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "DependencyList Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear }; /*}}}*/ diff --git a/python/cdrom.cc b/python/cdrom.cc index 4195c9cb..0b9ae578 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -109,7 +109,7 @@ static PyMethodDef cdrom_methods[] = { static PyObject *cdrom_new(PyTypeObject *type,PyObject *Args,PyObject *kwds) { - return CppPyObject_NEW(type); + return CppPyObject_NEW(NULL, type); } static char *cdrom_doc = diff --git a/python/configuration.cc b/python/configuration.cc index b2367c3e..0cad8db3 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -137,7 +137,7 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) return 0; } - return CppOwnedPyObject_NEW(Self,&PyConfiguration_Type, + return CppPyObject_NEW(Self,&PyConfiguration_Type, new Configuration(Itm)); } @@ -473,7 +473,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppOwnedPyObject_NEW(NULL, type, new Configuration()); + return CppPyObject_NEW(NULL, type, new Configuration()); } // Type for a Normal Configuration object @@ -483,10 +483,10 @@ PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr diff --git a/python/depcache.cc b/python/depcache.cc index e78b9f4e..53459c32 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -219,7 +219,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return Py_None; } - CandidateObj = CppOwnedPyObject_NEW(PackageObj,&PyVersion_Type,I); + CandidateObj = CppPyObject_NEW(PackageObj,&PyVersion_Type,I); return CandidateObj; } @@ -625,8 +625,8 @@ static PyObject *PkgDepCacheGetPolicy(PyObject *Self,void*) { PyObject *Owner = GetOwner(Self); pkgDepCache *DepCache = GetCpp(Self); pkgPolicy *Policy = (pkgPolicy *)&DepCache->GetPolicy(); - CppOwnedPyObject *PyPolicy = - CppOwnedPyObject_NEW(Owner,&PyPolicy_Type,Policy); + CppPyObject *PyPolicy = + CppPyObject_NEW(Owner,&PyPolicy_Type,Policy); // Policy should not be deleted, it is managed by CacheFile. PyPolicy->NoDelete = true; return PyPolicy; @@ -668,8 +668,8 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds // and now the depcache pkgDepCache *depcache = (pkgDepCache *)(*CacheF); - CppOwnedPyObject *DepCachePyObj; - DepCachePyObj = CppOwnedPyObject_NEW(Owner,type,depcache); + CppPyObject *DepCachePyObj; + DepCachePyObj = CppPyObject_NEW(Owner,type,depcache); // Do not delete the underlying pointer, it is managed by the cachefile. DepCachePyObj->NoDelete = true; @@ -684,10 +684,10 @@ PyTypeObject PyDepCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DepCache", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -706,8 +706,8 @@ PyTypeObject PyDepCache_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgDepCache, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -751,8 +751,8 @@ static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObjec pkgDepCache *depcache = GetCpp(Owner); pkgProblemResolver *fixer = new pkgProblemResolver(depcache); - CppOwnedPyObject *PkgProblemResolverPyObj; - PkgProblemResolverPyObj = CppOwnedPyObject_NEW(Owner, + CppPyObject *PkgProblemResolverPyObj; + PkgProblemResolverPyObj = CppPyObject_NEW(Owner, type, fixer); HandleErrors(PkgProblemResolverPyObj); @@ -871,10 +871,10 @@ PyTypeObject PyProblemResolver_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ProblemResolver", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr,// tp_dealloc + CppDeallocPtr,// tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -893,8 +893,8 @@ PyTypeObject PyProblemResolver_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), "ProblemResolver Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -959,8 +959,8 @@ static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *k pkgDepCache *depcache = GetCpp(Owner); pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); - CppOwnedPyObject *PkgActionGroupPyObj; - PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, + CppPyObject *PkgActionGroupPyObj; + PkgActionGroupPyObj = CppPyObject_NEW(Owner, type, group); HandleErrors(PkgActionGroupPyObj); @@ -987,10 +987,10 @@ PyTypeObject PyActionGroup_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ActionGroup", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1009,8 +1009,8 @@ PyTypeObject PyActionGroup_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgActionGroup, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/generic.h b/python/generic.h index d5d6e9fb..2b413a02 100644 --- a/python/generic.h +++ b/python/generic.h @@ -111,13 +111,17 @@ template struct CppPyObject : public PyObject // However if T doesn't have a default c'tor C++ doesn't generate one for // CppPyObject (since it can't know how it should initialize Object). // - // This causes problems then in CppOwnedPyObject, for which C++ can't create + // This causes problems then in CppPyObject, for which C++ can't create // a c'tor that calls the base class c'tor (which causes a compilation // error). // So basically having the c'tor here removes the need for T to have a // default c'tor, which is not always desireable. CppPyObject() { }; + // The owner of the object. The object keeps a reference to it during its + // lifetime. + PyObject *Owner; + // Flag which causes the underlying object to not be deleted. bool NoDelete; @@ -125,11 +129,6 @@ template struct CppPyObject : public PyObject T Object; }; -template struct CppOwnedPyObject : public CppPyObject -{ - PyObject *Owner; -}; - template inline T &GetCpp(PyObject *Obj) { @@ -139,121 +138,73 @@ inline T &GetCpp(PyObject *Obj) template inline PyObject *GetOwner(PyObject *Obj) { - return ((CppOwnedPyObject *)Obj)->Owner; + return ((CppPyObject *)Obj)->Owner; } -// Generic 'new' functions -template -inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== ALLOCATING " << Type->tp_name << " ===\n"; - #endif - CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); - new (&New->Object) T; - return New; -} - -template -inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type,A const &Arg) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== ALLOCATING " << Type->tp_name << " ===\n"; - #endif - CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); - new (&New->Object) T(Arg); - return New; -} template -inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, - PyTypeObject *Type) +inline CppPyObject *CppPyObject_NEW(PyObject *Owner,PyTypeObject *Type) { #ifdef ALLOC_DEBUG std::cerr << "=== ALLOCATING " << Type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; New->Owner = Owner; Py_XINCREF(Owner); return New; } -template -inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, - PyTypeObject *Type,A const &Arg) +template +inline CppPyObject *CppPyObject_NEW(PyObject *Owner, PyTypeObject *Type,T const &Arg) { #ifdef ALLOC_DEBUG std::cerr << "=== ALLOCATING " << Type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); New->Owner = Owner; Py_XINCREF(Owner); return New; } -// Traversal and Clean for owned objects +// Traversal and Clean for objects template -int CppOwnedTraverse(PyObject *self, visitproc visit, void* arg) { - Py_VISIT(((CppOwnedPyObject *)self)->Owner); +int CppTraverse(PyObject *self, visitproc visit, void* arg) { + Py_VISIT(((CppPyObject *)self)->Owner); return 0; } template -int CppOwnedClear(PyObject *self) { - Py_CLEAR(((CppOwnedPyObject *)self)->Owner); +int CppClear(PyObject *self) { + Py_CLEAR(((CppPyObject *)self)->Owner); return 0; } -// Generic Dealloc type functions template -void CppDealloc(PyObject *Obj) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== DEALLOCATING " << Obj->ob_type->tp_name << " ===\n"; - #endif - if (!((CppPyObject*)Obj)->NoDelete) - GetCpp(Obj).~T(); - Obj->ob_type->tp_free(Obj); -} - -template -void CppOwnedDealloc(PyObject *iObj) +void CppDealloc(PyObject *iObj) { #ifdef ALLOC_DEBUG std::cerr << "=== DEALLOCATING " << iObj->ob_type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *Obj = (CppOwnedPyObject *)iObj; + CppPyObject *Obj = (CppPyObject *)iObj; if (!((CppPyObject*)Obj)->NoDelete) Obj->Object.~T(); - CppOwnedClear(iObj); + CppClear(iObj); iObj->ob_type->tp_free(iObj); } -// Pointer deallocation -// Generic Dealloc type functions -template -void CppDeallocPtr(PyObject *Obj) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== DEALLOCATING " << Obj->ob_type->tp_name << "* ===\n"; - #endif - if (!((CppPyObject*)Obj)->NoDelete) - delete GetCpp(Obj); - Obj->ob_type->tp_free(Obj); -} template -void CppOwnedDeallocPtr(PyObject *iObj) +void CppDeallocPtr(PyObject *iObj) { #ifdef ALLOC_DEBUG std::cerr << "=== DEALLOCATING " << iObj->ob_type->tp_name << "*+ ===\n"; #endif - CppOwnedPyObject *Obj = (CppOwnedPyObject *)iObj; + CppPyObject *Obj = (CppPyObject *)iObj; if (!((CppPyObject*)Obj)->NoDelete) delete Obj->Object; - CppOwnedClear(iObj); + CppClear(iObj); iObj->ob_type->tp_free(iObj); } diff --git a/python/hashes.cc b/python/hashes.cc index 0086c17a..d0b0fb0c 100644 --- a/python/hashes.cc +++ b/python/hashes.cc @@ -25,7 +25,7 @@ static PyObject *hashes_new(PyTypeObject *type,PyObject *args, PyObject *kwds) { - return CppPyObject_NEW(type); + return CppPyObject_NEW(NULL, type); } static int hashes_init(PyObject *self, PyObject *args, PyObject *kwds) diff --git a/python/hashstring.cc b/python/hashstring.cc index 90c80e4c..d4b7a3b2 100644 --- a/python/hashstring.cc +++ b/python/hashstring.cc @@ -31,7 +31,7 @@ static PyObject *hashstring_new(PyTypeObject *type,PyObject *Args, if (PyArg_ParseTupleAndKeywords(Args, kwds, "s|s:__new__", kwlist, &Type, &Hash) == 0) return 0; - CppPyObject *PyObj = CppPyObject_NEW(type); + CppPyObject *PyObj = CppPyObject_NEW(NULL, type); if (Hash) PyObj->Object = new HashString(Type,Hash); else // Type is the combined form now (i.e. type:hash) diff --git a/python/indexfile.cc b/python/indexfile.cc index 7accaa50..e8df9cf2 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -91,11 +91,11 @@ PyTypeObject PyIndexFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.IndexFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods // Not ..Ptr, because the pointer is managed somewhere else. - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -112,8 +112,8 @@ PyTypeObject PyIndexFile_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "IndexFile Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 2d21362d..5750bf6b 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -30,7 +30,7 @@ static PyObject *indexrecords_new(PyTypeObject *type,PyObject *Args, if (PyArg_ParseTupleAndKeywords(Args, kwds, "", kwlist) == 0) return 0; indexRecords *records = new indexRecords(); - CppPyObject *New = CppPyObject_NEW(type, + CppPyObject *New = CppPyObject_NEW(NULL, type, records); return New; } diff --git a/python/metaindex.cc b/python/metaindex.cc index 2c5b0bd9..dee54521 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -37,8 +37,8 @@ static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { for (vector::const_iterator I = indexFiles->begin(); I != indexFiles->end(); I++) { - CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PyIndexFile_Type,*I); + CppPyObject *Obj; + Obj = CppPyObject_NEW(Self, &PyIndexFile_Type,*I); // Do not delete pkgIndexFile*, they are managed by metaIndex. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -76,10 +76,10 @@ PyTypeObject PyMetaIndex_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.MetaIndex", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 58f2aaec..9b4a9ab7 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -31,7 +31,7 @@ static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); CppPyObject *PkgManagerObj = - CppPyObject_NEW(type,pm); + CppPyObject_NEW(NULL, type,pm); return PkgManagerObj; } diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index d34ba0d2..1e43b2e8 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -157,7 +157,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) &Owner) == 0) return 0; - return HandleErrors(CppOwnedPyObject_NEW(Owner,type, + return HandleErrors(CppPyObject_NEW(Owner,type, GetCpp(Owner))); } @@ -165,10 +165,10 @@ PyTypeObject PyPackageRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageRecords", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -187,8 +187,8 @@ PyTypeObject PyPackageRecords_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), "Records Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 0b54c2fe..41ee6276 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -123,8 +123,8 @@ static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { if (Struct.Last == 0) return 0; const pkgIndexFile &tmp = Struct.Last->Index(); - CppOwnedPyObject *PyObj; - PyObj = CppOwnedPyObject_NEW(Self,&PyIndexFile_Type, + CppPyObject *PyObj; + PyObj = CppPyObject_NEW(Self,&PyIndexFile_Type, (pkgIndexFile*)&tmp); // Do not delete the pkgIndexFile*, it is managed by PkgSrcRecords::Parser. PyObj->NoDelete=true; @@ -252,7 +252,7 @@ static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kw if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return HandleErrors(CppPyObject_NEW(type)); + return HandleErrors(CppPyObject_NEW(NULL, type)); } PyTypeObject PySourceRecords_Type = @@ -310,6 +310,6 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"") == 0) return 0; - return HandleErrors(CppPyObject_NEW(&PySourceRecords_Type)); + return HandleErrors(CppPyObject_NEW(NULL, &PySourceRecords_Type)); } #endif diff --git a/python/policy.cc b/python/policy.cc index 80670267..3e1ec589 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -34,7 +34,7 @@ static PyObject *policy_new(PyTypeObject *type,PyObject *Args, return 0; } pkgPolicy *policy = new pkgPolicy(GetCpp(cache)); - return CppOwnedPyObject_NEW(cache,&PyPolicy_Type,policy); + return CppPyObject_NEW(cache,&PyPolicy_Type,policy); } static char *policy_get_priority_doc = "get_priority(package: apt_pkg.Package)" @@ -61,7 +61,7 @@ PyObject *policy_get_candidate_ver(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetCandidateVer(pkg); - return CppOwnedPyObject_NEW(arg,&PyVersion_Type, + return CppPyObject_NEW(arg,&PyVersion_Type, ver); } else { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); @@ -81,7 +81,7 @@ static PyObject *policy_get_match(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetMatch(pkg); - return CppOwnedPyObject_NEW(arg,&PyVersion_Type,ver); + return CppPyObject_NEW(arg,&PyVersion_Type,ver); } static char *policy_read_pinfile_doc = "read_pinfile(filename: str) -> bool\n\n" @@ -163,10 +163,10 @@ static char *policy_doc = "Policy(cache)\n\n" PyTypeObject PyPolicy_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Policy", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -185,8 +185,8 @@ PyTypeObject PyPolicy_Type = { Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), policy_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/python-apt.h b/python/python-apt.h index f8c21adc..6f688c93 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -218,22 +218,11 @@ static int import_apt_pkg(void) { # define PyTagSection_ToCpp GetCpp # define PyVersion_ToCpp GetCpp -// Python object creation, using two inline template functions and one variadic -// macro per type. +// Template using a simpler version of from cpp template -inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp obj, - bool Delete=false) +inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) { - CppPyObject *Obj = CppPyObject_NEW(pytype, obj); - Obj->NoDelete = (!Delete); - return Obj; -} - -template -inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, - bool Delete=false, PyObject *Owner=NULL) -{ - CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); + CppPyObject *Obj = CppPyObject_NEW(Owner, pytype, obj); Obj->NoDelete = (!Delete); return Obj; } @@ -241,34 +230,34 @@ inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # ifndef APT_PKGMODULE_H # define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp #endif -# define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) -# define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) -# define PyAcquireWorker_FromCpp(...) FromCppOwned(&PyAcquireWorker_Type,##__VA_ARGS__) -# define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) -# define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) +# define PyAcquireFile_FromCpp(...) FromCpp(&PyAcquireFile_Type, ##__VA_ARGS__) +# define PyAcquireItem_FromCpp(...) FromCpp(&PyAcquireItem_Type,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCpp(&PyAcquireItemDesc_Type,##__VA_ARGS__) +# define PyAcquireWorker_FromCpp(...) FromCpp(&PyAcquireWorker_Type,##__VA_ARGS__) +# define PyActionGroup_FromCpp(...) FromCpp(&PyActionGroup_Type,##__VA_ARGS__) +# define PyCache_FromCpp(...) FromCpp(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) # define PyCdrom_FromCpp(...) FromCpp(&PyCdrom_Type,##__VA_ARGS__) -# define PyConfiguration_FromCpp(...) FromCppOwned(&PyConfiguration_Type, ##__VA_ARGS__) -# define PyDepCache_FromCpp(...) FromCppOwned(&PyDepCache_Type,##__VA_ARGS__) -# define PyDependency_FromCpp(...) FromCppOwned(&PyDependency_Type,##__VA_ARGS__) -//# define PyDependencyList_FromCpp(...) FromCppOwned(&PyDependencyList_Type,##__VA_ARGS__) -# define PyDescription_FromCpp(...) FromCppOwned(&PyDescription_Type,##__VA_ARGS__) +# define PyConfiguration_FromCpp(...) FromCpp(&PyConfiguration_Type, ##__VA_ARGS__) +# define PyDepCache_FromCpp(...) FromCpp(&PyDepCache_Type,##__VA_ARGS__) +# define PyDependency_FromCpp(...) FromCpp(&PyDependency_Type,##__VA_ARGS__) +//# define PyDependencyList_FromCpp(...) FromCpp(&PyDependencyList_Type,##__VA_ARGS__) +# define PyDescription_FromCpp(...) FromCpp(&PyDescription_Type,##__VA_ARGS__) # define PyHashes_FromCpp(...) FromCpp(&PyHashes_Type,##__VA_ARGS__) # define PyHashString_FromCpp(...) FromCpp(&PyHashString_Type,##__VA_ARGS__) # define PyIndexRecords_FromCpp(...) FromCpp(&PyIndexRecords_Type,##__VA_ARGS__) -# define PyMetaIndex_FromCpp(...) FromCppOwned(&PyMetaIndex_Type,##__VA_ARGS__) -# define PyPackage_FromCpp(...) FromCppOwned(&PyPackage_Type,##__VA_ARGS__) -# define PyIndexFile_FromCpp(...) FromCppOwned(&PyIndexFile_Type,##__VA_ARGS__) -# define PyPackageFile_FromCpp(...) FromCppOwned(&PyPackageFile_Type,##__VA_ARGS__) -//# define PyPackageList_FromCpp(...) FromCppOwned(&PyPackageList_Type,##__VA_ARGS__) +# define PyMetaIndex_FromCpp(...) FromCpp(&PyMetaIndex_Type,##__VA_ARGS__) +# define PyPackage_FromCpp(...) FromCpp(&PyPackage_Type,##__VA_ARGS__) +# define PyIndexFile_FromCpp(...) FromCpp(&PyIndexFile_Type,##__VA_ARGS__) +# define PyPackageFile_FromCpp(...) FromCpp(&PyPackageFile_Type,##__VA_ARGS__) +//# define PyPackageList_FromCpp(...) FromCpp(&PyPackageList_Type,##__VA_ARGS__) # define PyPackageManager_FromCpp(...) FromCpp(&PyPackageManager_Type,##__VA_ARGS__) -//# define PyPackageRecords_FromCpp(...) FromCppOwned(&PyPackageRecords_Type,##__VA_ARGS__) -# define PyPolicy_FromCpp(...) FromCppOwned(&PyPolicy_Type,##__VA_ARGS__) -# define PyProblemResolver_FromCpp(...) FromCppOwned(&PyProblemResolver_Type,##__VA_ARGS__) +//# define PyPackageRecords_FromCpp(...) FromCpp(&PyPackageRecords_Type,##__VA_ARGS__) +# define PyPolicy_FromCpp(...) FromCpp(&PyPolicy_Type,##__VA_ARGS__) +# define PyProblemResolver_FromCpp(...) FromCpp(&PyProblemResolver_Type,##__VA_ARGS__) # define PySourceList_FromCpp(...) FromCpp(&PySourceList_Type,##__VA_ARGS__) //# define PySourceRecords_FromCpp(...) FromCpp(&PySourceRecords_Type,##__VA_ARGS__) -# define PyTagFile_FromCpp(...) FromCppOwned(&PyTagFile_Type,##__VA_ARGS__) -# define PyTagSection_FromCpp(...) FromCppOwned(&PyTagSection_Type,##__VA_ARGS__) -# define PyVersion_FromCpp(...) FromCppOwned(&PyVersion_Type,##__VA_ARGS__) +# define PyTagFile_FromCpp(...) FromCpp(&PyTagFile_Type,##__VA_ARGS__) +# define PyTagSection_FromCpp(...) FromCpp(&PyTagSection_Type,##__VA_ARGS__) +# define PyVersion_FromCpp(...) FromCpp(&PyVersion_Type,##__VA_ARGS__) #endif diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 52c0e6a8..b705d8b8 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -26,7 +26,7 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { pkgSourceList *list = GetCpp(Self); PyObject *pyPkgFileIter; - CppOwnedPyObject *pyPkgIndexFile; + CppPyObject *pyPkgIndexFile; if (PyArg_ParseTuple(Args, "O!", &PyPackageFile_Type,&pyPkgFileIter) == 0) return 0; @@ -35,7 +35,7 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) pkgIndexFile *index; if(list->FindIndex(i, index)) { - pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PyIndexFile_Type,index); + pyPkgIndexFile = CppPyObject_NEW(pyPkgFileIter,&PyIndexFile_Type,index); // Do not delete the pkgIndexFile*, it is managed by pkgSourceList. pyPkgIndexFile->NoDelete = true; return pyPkgIndexFile; @@ -92,8 +92,8 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) for (vector::const_iterator I = list->begin(); I != list->end(); I++) { - CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PyMetaIndex_Type,*I); + CppPyObject *Obj; + Obj = CppPyObject_NEW(Self, &PyMetaIndex_Type,*I); // Never delete metaIndex*, they are managed by the pkgSourceList. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -115,7 +115,7 @@ static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kw char *kwlist[] = {0}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppPyObject_NEW(type,new pkgSourceList()); + return CppPyObject_NEW(NULL, type,new pkgSourceList()); } PyTypeObject PySourceList_Type = diff --git a/python/tag.cc b/python/tag.cc index b1a3e520..2aaf3beb 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -34,13 +34,13 @@ using namespace std; /*}}}*/ /* We need to keep a private copy of the data.. */ -struct TagSecData : public CppOwnedPyObject +struct TagSecData : public CppPyObject { char *Data; }; // The owner of the TagFile is a Python file object. -struct TagFileData : public CppOwnedPyObject +struct TagFileData : public CppPyObject { TagSecData *Section; FileFd Fd; @@ -68,7 +68,7 @@ void TagSecFree(PyObject *Obj) { TagSecData *Self = (TagSecData *)Obj; delete [] Self->Data; - CppOwnedDealloc(Obj); + CppDealloc(Obj); } /*}}}*/ // TagFileFree - Free a Tag File /*{{{*/ @@ -488,8 +488,8 @@ PyTypeObject PyTagSection_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_TagSec, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/tarfile.cc b/python/tarfile.cc index 775ae22e..aa9a39f6 100644 --- a/python/tarfile.cc +++ b/python/tarfile.cc @@ -102,8 +102,8 @@ bool PyDirStream::FinishedFile(Item &Itm,int Fd) return true; // The current member and data. - CppOwnedPyObject *py_member; - py_member = CppOwnedPyObject_NEW(0, &PyTarMember_Type); + CppPyObject *py_member; + py_member = CppPyObject_NEW(0, &PyTarMember_Type); // Clone our object, including the strings in it. py_member->Object = Itm; py_member->Object.Name = new char[strlen(Itm.Name)+1]; @@ -121,7 +121,7 @@ void tarmember_dealloc(PyObject *self) { // We cloned those strings, delete them again. delete[] GetCpp(self).Name; delete[] GetCpp(self).LinkTarget; - CppOwnedDealloc(self); + CppDealloc(self); } // The tarfile.TarInfo interface for our TarMember class. @@ -269,7 +269,7 @@ static const char *tarmember_doc = PyTypeObject PyTarMember_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_inst.TarMember", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods tarmember_dealloc, // tp_dealloc @@ -290,8 +290,8 @@ PyTypeObject PyTarMember_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, tarmember_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -318,7 +318,7 @@ static PyObject *tarfile_new(PyTypeObject *type,PyObject *args,PyObject *kwds) &max,&comp) == 0) return 0; - self = (PyTarFileObject*)CppOwnedPyObject_NEW(file,type); + self = (PyTarFileObject*)CppPyObject_NEW(file,type); // We receive a filename. if ((filename = (char*)PyObject_AsString(file))) @@ -450,7 +450,7 @@ PyTypeObject PyTarFile_Type = { sizeof(PyTarFileObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -468,8 +468,8 @@ PyTypeObject PyTarFile_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, tarfile_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter -- cgit v1.2.3