From 6ba42d2e31f161fc0ebe5405cf63b616c3e822b4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 22 Jul 2009 17:21:08 +0200 Subject: python: First step of fixing acquire stuff. Basically, we only want to have on PyAcquireItem per pkgAcquire::Item, and one PyAcquireItemDesc per pkgAcquire::ItemDesc. Therefore, we store them so we can return them at a later time. --- python/acquire-item.cc | 357 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 357 insertions(+) create mode 100644 python/acquire-item.cc (limited to 'python/acquire-item.cc') diff --git a/python/acquire-item.cc b/python/acquire-item.cc new file mode 100644 index 00000000..cf0a628e --- /dev/null +++ b/python/acquire-item.cc @@ -0,0 +1,357 @@ +/* + * acquire-item.cc - Wrapper around pkgAcquire::Item and pkgAcqFile. + * + * Copyright 2004-2009 Canonical Ltd. + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include "apt_pkgmodule.h" + +#include +#include + +using namespace std; + + + +struct PyAcquireItems { + CppOwnedPyObject *file; + CppOwnedPyObject *item; + CppOwnedPyObject *desc; +}; + +typedef map item_map; + +// Keep a vector to PyAcquireItemObject pointers, so we can set the Object +// pointers to NULL when deallocating the main object (mostly AcquireFile). +struct PyAcquireObject : public CppPyObject { + item_map items; +}; + +inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) +{ + pkgAcquire::Item *itm = GetCpp(self); + if (itm == 0) + PyErr_SetString(PyExc_ValueError, "Acquire() has been shut down or " + "the AcquireFile() object has been deallocated."); + return itm; +} + +static PyObject *acquireitem_get_complete(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->Complete) : 0; +} + +static PyObject *acquireitem_get_desc_uri(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->DescURI()) : 0; +} + +static PyObject *acquireitem_get_destfile(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->DestFile) : 0; +} + + +static PyObject *acquireitem_get_error_text(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->ErrorText) : 0; +} + +static PyObject *acquireitem_get_filesize(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("i", item->FileSize) : 0; +} + +static PyObject *acquireitem_get_id(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("k", item->ID) : 0; +} + +static PyObject *acquireitem_get_mode(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("s", item->Mode) : 0; +} + +static PyObject *acquireitem_get_is_trusted(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->IsTrusted()) : 0; +} + +static PyObject *acquireitem_get_local(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->Local) : 0; +} + +static PyObject *acquireitem_get_status(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("i", item->Status) : 0; +} + +static int acquireitem_set_id(PyObject *self, PyObject *value, void *closure) +{ + pkgAcquire::Item *Itm = acquireitem_tocpp(self); + if (Itm == 0) + return -1; + if (PyLong_Check(value)) { + Itm->ID = PyLong_AsLong(value); + } + else if (PyInt_Check(value)) { + Itm->ID = PyInt_AsLong(value); + } + else { + PyErr_SetString(PyExc_TypeError, "value must be integer."); + return -1; + } + return 0; +} + + +static PyGetSetDef acquireitem_getset[] = { + {"complete",acquireitem_get_complete}, + {"desc_uri",acquireitem_get_desc_uri}, + {"destfile",acquireitem_get_destfile}, + {"error_text",acquireitem_get_error_text}, + {"filesize",acquireitem_get_filesize}, + {"id",acquireitem_get_id,acquireitem_set_id}, + {"mode",acquireitem_get_mode}, + {"is_trusted",acquireitem_get_is_trusted}, + {"local",acquireitem_get_local}, + {"status",acquireitem_get_status}, +#ifdef COMPAT_0_7 + {"Complete",acquireitem_get_complete}, + {"DescURI",acquireitem_get_desc_uri}, + {"DestFile",acquireitem_get_destfile}, + {"ErrorText",acquireitem_get_error_text}, + {"FileSize",acquireitem_get_filesize}, + {"ID",acquireitem_get_id}, + {"IsTrusted",acquireitem_get_is_trusted}, + {"Local",acquireitem_get_local}, + {"Status",acquireitem_get_status}, +#endif + {} +}; + +static PyObject *acquireitem_repr(PyObject *Self) +{ + pkgAcquire::Item *Itm = acquireitem_tocpp(Self); + if (Itm == 0) + return 0; + + return PyString_FromFormat("<%s object: " + "Status: %i Complete: %i Local: %i IsTrusted: %i " + "FileSize: %lu DestFile:'%s' " + "DescURI: '%s' ID:%lu ErrorText: '%s'>", + Self->ob_type->tp_name, + Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), + Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), + Itm->ID,Itm->ErrorText.c_str()); +} + +static void acquireitem_dealloc(PyObject *self) +{ + // TODO: Unregister the object in the owner. + if (!((CppOwnedPyObject*)self)->NoDelete) { + pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); + PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); + + PyAcquireItems item_struct = Owner->items[item]; + + if (item_struct.file != 0 && item_struct.file != self) + item_struct.file->Object = 0; + if (item_struct.item != 0 && item_struct.item != self) { + item_struct.item->Object = 0; + Py_DECREF(item_struct.item); + } + if (item_struct.desc != 0) { + item_struct.desc->Object = 0; + Py_DECREF(item_struct.desc); + } + Owner->items.erase(item); + } + + CppOwnedDeallocPtr(self); +} + +PyTypeObject PyAcquireItem_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireItem", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + acquireitem_dealloc, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + acquireitem_repr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "AcquireItem Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + acquireitem_getset, // tp_getset +}; + +static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * kwds) +{ + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size = 0; + uri = md5 = descr = shortDescr = destDir = destFile = ""; + + char *kwlist[] = {"owner","uri", "md5", "size", "descr", "short_descr", + "destdir", "destfile", NULL + }; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PyAcquire_Type, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); + AcqFileObj->Object = af; + + + ((PyAcquireObject *)pyfetcher)->items[af].file = AcqFileObj; + return AcqFileObj; +} + + +static char *acquirefile_doc = + "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir," + "destfile]) -> New AcquireFile() object\n\n" + "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" + "*destdir* OR *destfile* to specify the destination directory/file."; + +PyTypeObject PyAcquireFile_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireFile", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + acquireitem_dealloc, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC, + acquirefile_doc, // tp_doc + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + 0, // tp_getset + &PyAcquireItem_Type, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + acquirefile_new, // tp_new +}; + +#ifdef COMPAT_0_7 +char *doc_GetPkgAcqFile = + "GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; +PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) +{ + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " + "deprecated. Please see apt_pkg.AcquireFile() for the " + "replacement", 1); + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size = 0; + uri = md5 = descr = shortDescr = destDir = destFile = ""; + + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", + "destDir", "destFile", NULL + }; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PyAcquire_Type, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); + AcqFileObj->Object = af; + AcqFileObj->NoDelete = true; + + return AcqFileObj; +} +#endif -- cgit v1.2.3 From 544f14e0f2fb70b5a1f30786a93023a42d88290d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 22 Jul 2009 18:16:28 +0200 Subject: python: 2nd part of the acquire fixes (one PyObject per C++ object). --- python/acquire-item.cc | 14 +++++++---- python/acquire.cc | 63 +++++++++++++++++++++++++------------------------- python/apt_pkgmodule.h | 5 ++++ python/progress.cc | 10 ++++---- python/python-apt.h | 5 ++-- 5 files changed, 54 insertions(+), 43 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index cf0a628e..1fb66080 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -176,13 +176,11 @@ static PyObject *acquireitem_repr(PyObject *Self) static void acquireitem_dealloc(PyObject *self) { + pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); + PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); + PyAcquireItems item_struct = Owner->items[item]; // TODO: Unregister the object in the owner. if (!((CppOwnedPyObject*)self)->NoDelete) { - pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); - PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - - PyAcquireItems item_struct = Owner->items[item]; - if (item_struct.file != 0 && item_struct.file != self) item_struct.file->Object = 0; if (item_struct.item != 0 && item_struct.item != self) { @@ -195,6 +193,12 @@ static void acquireitem_dealloc(PyObject *self) } Owner->items.erase(item); } + else { + if (item_struct.file == self) + item_struct.file = 0; + if (item_struct.item == self) + item_struct.item = 0; + } CppOwnedDeallocPtr(self); } diff --git a/python/acquire.cc b/python/acquire.cc index 5e03586e..1085d0a2 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -40,26 +40,17 @@ static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) Py_RETURN_NONE; } - PyAcquireObject *PyAcquire = (PyAcquireObject *)GetOwner(self); + PyObject *PyAcquire = GetOwner(self); - pkgAcquire::Item *Item = worker->CurrentItem->Owner; - - PyObject *PyItem; - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false && PyAcquire->items[Item].item) { - Py_INCREF(PyItem); - PyItem = PyAcquire->items[Item].item; - } + if (PyAcquire) + return PyAcquire_GetItemDesc(PyAcquire, worker->CurrentItem); else { - PyItem = PyAcquireItem_FromCpp(Item,false,PyAcquire); - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false) - PyAcquire->items[Item].item = (CppOwnedPyObject*)PyItem; + PyObject *PyItem = PyAcquireItem_FromCpp(worker->CurrentItem->Owner); + PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false, + PyItem); + Py_DECREF(PyItem); + return ret; } - - PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false,PyItem); - Py_DECREF(PyItem); - return ret; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -146,7 +137,7 @@ static PyObject *acquireitemdesc_get_owner(CppOwnedPyObjectOwner); return self->Owner; } - else if (self->Object && self->Object->Owner != NULL) { + else if (self->Object) { self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); Py_INCREF(self->Owner); return self->Owner; @@ -210,7 +201,27 @@ PyTypeObject PyAcquireItemDesc_Type = }; +// Acquire + +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item]; + if (! item_struct.item) { + item_struct.item = PyAcquireItem_FromCpp(item,false,self); + } + Py_INCREF(item_struct.item); + return item_struct.item; +} +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item->Owner]; + if (! item_struct.item) + item_struct.item = PyAcquireItem_FromCpp(item->Owner,false,self); + if (! item_struct.desc) + item_struct.desc = PyAcquireItemDesc_FromCpp(item,false, + item_struct.item); + Py_INCREF(item_struct.desc); + return item_struct.desc; +} static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { @@ -294,23 +305,13 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); PyObject *List = PyList_New(0); - CppOwnedPyObject *Obj; + PyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - - if (((PyAcquireObject *)Self)->items[*I].item) - PyList_Append(List, ((PyAcquireObject *)Self)->items[*I].item); - else { - Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); - Obj->NoDelete = true; - + Obj = PyAcquire_GetItem(Self, *I); PyList_Append(List,Obj); - ((PyAcquireObject *)Self)->items[*I].item = Obj; - - - // Not DECREFING it, we want to manage it somewhere else. - } + Py_DECREF(Obj); } return List; } diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 04bce2cc..3edba5d2 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -12,6 +12,7 @@ #include #include +#include // Configuration Stuff #define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) @@ -49,6 +50,10 @@ PyObject *StrTimeRFC1123(PyObject *self,PyObject *Args); PyObject *StrStrToTime(PyObject *self,PyObject *Args); PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item); +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item); +bool PyAcquire_DropItem(PyObject *self, pkgAcquire::Item *item); + // Cache Stuff extern PyTypeObject PyCache_Type; extern PyTypeObject PyCacheFile_Type; diff --git a/python/progress.cc b/python/progress.cc index 1b135a75..7873d894 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -175,7 +175,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLHit); PyCbObj_BEGIN_ALLOW_THREADS @@ -185,7 +185,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLQueued); PyCbObj_BEGIN_ALLOW_THREADS @@ -195,7 +195,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLDone); PyCbObj_BEGIN_ALLOW_THREADS @@ -205,7 +205,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); return; } @@ -220,7 +220,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLFailed); PyCbObj_BEGIN_ALLOW_THREADS diff --git a/python/python-apt.h b/python/python-apt.h index 80ad03bd..fb84b394 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -220,7 +220,8 @@ static int import_apt_pkg(void) { // Python object creation, using two inline template functions and one variadic // macro per type. template -inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) +inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp obj, + bool Delete=false) { CppPyObject *Obj = CppPyObject_NEW(pytype, obj); Obj->NoDelete = (!Delete); @@ -228,7 +229,7 @@ inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) } template -inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, +inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) { CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); -- cgit v1.2.3 From 89752fb6d465c78026befcc5a61e8af655587ad7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 23 Jan 2010 19:24:04 +0100 Subject: python/acquire-item.cc: Support items without an owner set. --- debian/changelog | 2 ++ python/acquire-item.cc | 38 ++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/debian/changelog b/debian/changelog index 3fa0852f..87202817 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low - Fix Cache.update() to not raise errors on successful updates. * python/progress.cc: - Fix some threading issues (add some missing PyCbObj_BEGIN_ALLOW_THREADS) + * python/acquire-item.cc: + - Support items without an owner set. -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 1fb66080..73aec1d6 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -178,26 +178,28 @@ static void acquireitem_dealloc(PyObject *self) { pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - PyAcquireItems item_struct = Owner->items[item]; - // TODO: Unregister the object in the owner. - if (!((CppOwnedPyObject*)self)->NoDelete) { - if (item_struct.file != 0 && item_struct.file != self) - item_struct.file->Object = 0; - if (item_struct.item != 0 && item_struct.item != self) { - item_struct.item->Object = 0; - Py_DECREF(item_struct.item); + if (Owner != NULL) { + PyAcquireItems item_struct = Owner->items[item]; + // TODO: Unregister the object in the owner. + if (!((CppOwnedPyObject*)self)->NoDelete) { + if (item_struct.file != 0 && item_struct.file != self) + item_struct.file->Object = 0; + if (item_struct.item != 0 && item_struct.item != self) { + item_struct.item->Object = 0; + Py_DECREF(item_struct.item); + } + if (item_struct.desc != 0) { + item_struct.desc->Object = 0; + Py_DECREF(item_struct.desc); + } + Owner->items.erase(item); } - if (item_struct.desc != 0) { - item_struct.desc->Object = 0; - Py_DECREF(item_struct.desc); + else { + if (item_struct.file == self) + item_struct.file = 0; + if (item_struct.item == self) + item_struct.item = 0; } - Owner->items.erase(item); - } - else { - if (item_struct.file == self) - item_struct.file = 0; - if (item_struct.item == self) - item_struct.item = 0; } CppOwnedDeallocPtr(self); -- cgit v1.2.3 From 1e2f8799f0b6fb2da2770150749b4dd6a208e494 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 24 Jan 2010 14:14:11 +0100 Subject: python/acquire-item.cc: Add GC support to AcquireItem. AcquireItem is owned and owned items need to support the GC in case someone subclasses Acquire and creates a circular reference. --- python/acquire-item.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 73aec1d6..24780f1c 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -226,10 +226,11 @@ PyTypeObject PyAcquireItem_Type = { 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_HAVE_GC, // tp_flags "AcquireItem Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter -- cgit v1.2.3 From 2bb149489844096c55e9e90379795930171a6f73 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 27 Jan 2010 13:51:27 +0100 Subject: Drop the segfault prevention measures from the Acquire code, as they fail to work. A replacement will be added once destruction callbacks are added in APT. --- debian/changelog | 3 ++ python/acquire-item.cc | 48 +------------------ python/acquire.cc | 124 +++++++++++++------------------------------------ python/apt_pkgmodule.h | 1 + python/progress.cc | 47 ++++++++++--------- python/progress.h | 1 + 6 files changed, 64 insertions(+), 160 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/debian/changelog b/debian/changelog index 276f1e89..9b505a58 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,9 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low - Do not segfault if TarFile.go() is called without a member name. - Clone all pkgDirStream::Item's so apt_pkg.TarMember object can be used outside of the callback function passed to go(). + * Drop the segfault prevention measures from the Acquire code, as they fail + to work. A replacement will be added once destruction callbacks are added + in APT. -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 24780f1c..059f1802 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -28,22 +28,6 @@ using namespace std; - - -struct PyAcquireItems { - CppOwnedPyObject *file; - CppOwnedPyObject *item; - CppOwnedPyObject *desc; -}; - -typedef map item_map; - -// Keep a vector to PyAcquireItemObject pointers, so we can set the Object -// pointers to NULL when deallocating the main object (mostly AcquireFile). -struct PyAcquireObject : public CppPyObject { - item_map items; -}; - inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) { pkgAcquire::Item *itm = GetCpp(self); @@ -163,45 +147,18 @@ static PyObject *acquireitem_repr(PyObject *Self) pkgAcquire::Item *Itm = acquireitem_tocpp(Self); if (Itm == 0) return 0; - return PyString_FromFormat("<%s object: " "Status: %i Complete: %i Local: %i IsTrusted: %i " "FileSize: %lu DestFile:'%s' " "DescURI: '%s' ID:%lu ErrorText: '%s'>", Self->ob_type->tp_name, Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), - Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), + Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), Itm->ID,Itm->ErrorText.c_str()); } static void acquireitem_dealloc(PyObject *self) { - pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); - PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - if (Owner != NULL) { - PyAcquireItems item_struct = Owner->items[item]; - // TODO: Unregister the object in the owner. - if (!((CppOwnedPyObject*)self)->NoDelete) { - if (item_struct.file != 0 && item_struct.file != self) - item_struct.file->Object = 0; - if (item_struct.item != 0 && item_struct.item != self) { - item_struct.item->Object = 0; - Py_DECREF(item_struct.item); - } - if (item_struct.desc != 0) { - item_struct.desc->Object = 0; - Py_DECREF(item_struct.desc); - } - Owner->items.erase(item); - } - else { - if (item_struct.file == self) - item_struct.file = 0; - if (item_struct.item == self) - item_struct.item = 0; - } - } - CppOwnedDeallocPtr(self); } @@ -267,9 +224,6 @@ static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * destFile); // short-desc CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); AcqFileObj->Object = af; - - - ((PyAcquireObject *)pyfetcher)->items[af].file = AcqFileObj; return AcqFileObj; } diff --git a/python/acquire.cc b/python/acquire.cc index 789f994e..bcb76d67 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -30,43 +30,18 @@ #include -typedef CppOwnedPyObject PyAcquireWorkerObject; -struct PyAcquireItems { - CppOwnedPyObject *file; - CppOwnedPyObject *item; - CppOwnedPyObject *desc; -}; - -typedef map item_map; -typedef map worker_map; - -// Keep a vector to PyAcquireItemObject pointers, so we can set the Object -// pointers to NULL when deallocating the main object (mostly AcquireFile). -struct PyAcquireObject : public CppPyObject { - item_map items; - worker_map workers; -}; - - static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) { pkgAcquire::Worker *worker = GetCpp(self); - - if (worker->CurrentItem == NULL) { + pkgAcquire::ItemDesc *desc = worker->CurrentItem; + if (desc == NULL) { Py_RETURN_NONE; } - - PyObject *PyAcquire = GetOwner(self); - - if (PyAcquire) - return PyAcquire_GetItemDesc(PyAcquire, worker->CurrentItem); - else { - PyObject *PyItem = PyAcquireItem_FromCpp(worker->CurrentItem->Owner); - PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false, - PyItem); - Py_DECREF(PyItem); - return ret; - } + PyObject *PyAcq = GetOwner(self); + PyObject *PyItem = PyAcquireItem_FromCpp(desc->Owner, false, PyAcq); + PyObject *PyDesc = PyAcquireItemDesc_FromCpp(desc, false, PyItem); + Py_XDECREF(PyItem); + return PyDesc; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -134,17 +109,28 @@ PyTypeObject PyAcquireWorker_Type = { acquireworker_getset, // tp_getset }; + +static pkgAcquire::ItemDesc* acquireitemdesc_tocpp(PyObject *self) { + pkgAcquire::ItemDesc *item = GetCpp(self); + if (item == NULL) + PyErr_SetString(PyExc_ValueError, "Acquire has been shutdown"); + return item; +} + static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->URI); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->URI) : NULL; } static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->Description); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->Description) : NULL; } static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->ShortDesc); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->ShortDesc) : NULL; } static PyObject *acquireitemdesc_get_owner(CppOwnedPyObject *self, void *closure) { @@ -153,7 +139,7 @@ static PyObject *acquireitemdesc_get_owner(CppOwnedPyObjectOwner; } else if (self->Object) { - self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); + self->Owner = PyAcquireItem_FromCpp(self->Object->Owner, false, NULL); Py_INCREF(self->Owner); return self->Owner; } @@ -214,31 +200,6 @@ PyTypeObject PyAcquireItemDesc_Type = { 0, // tp_new }; - -// Acquire - -PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item) -{ - PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item]; - if (! item_struct.item) { - item_struct.item = PyAcquireItem_FromCpp(item,false,self); - } - Py_INCREF(item_struct.item); - return item_struct.item; -} - -PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item) -{ - PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item->Owner]; - if (! item_struct.item) - item_struct.item = PyAcquireItem_FromCpp(item->Owner,false,self); - if (! item_struct.desc) - item_struct.desc = PyAcquireItemDesc_FromCpp(item,false, - item_struct.item); - Py_INCREF(item_struct.desc); - return item_struct.desc; -} - static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { pkgAcquire *fetcher = GetCpp(Self); @@ -252,34 +213,19 @@ static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("i",run)); } + static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) { pkgAcquire *fetcher = GetCpp(Self); - if (PyArg_ParseTuple(Args, "") == 0) return 0; - fetcher->Shutdown(); - - // TODO: Delete all objects here - item_map &items = ((PyAcquireObject *)Self)->items; - for (item_map::iterator I = items.begin(); I != items.end(); I++) { - if ((*I).second.file) - (*I).second.file->Object = NULL; - if ((*I).second.item) { - (*I).second.item->Object = NULL; - Py_DECREF((*I).second.item); - } - if ((*I).second.desc) { - (*I).second.desc->Object = NULL; - Py_DECREF((*I).second.desc); - } - } - items.clear(); Py_INCREF(Py_None); return HandleErrors(Py_None); } + + static PyMethodDef PkgAcquireMethods[] = { {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, @@ -312,8 +258,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) CppOwnedPyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { - PyWorker = CppOwnedPyObject_NEW(self,&PyAcquireWorker_Type, Worker); - PyWorker->NoDelete = true; + PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); PyList_Append(List, PyWorker); Py_DECREF(PyWorker); } @@ -326,7 +271,7 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) PyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - Obj = PyAcquire_GetItem(Self, *I); + Obj = PyAcquireItem_FromCpp(*I, false, Self); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -368,14 +313,11 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) fetcher = new pkgAcquire(); } - PyAcquireObject *FetcherObj = (PyAcquireObject *) - CppPyObject_NEW(type, fetcher); + PyObject *FetcherObj = CppPyObject_NEW(type, fetcher); if (progress != 0) progress->setPyAcquire(FetcherObj); // prepare our map of items. - new (&FetcherObj->items) item_map(); - new (&FetcherObj->workers) worker_map(); return FetcherObj; } @@ -383,11 +325,9 @@ 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) { - PyAcquireObject *FetcherObj = (PyAcquireObject *)CppPyObject_NEW(&PyAcquire_Type, fetcher); - new (&FetcherObj->items) item_map(); - new (&FetcherObj->workers) worker_map(); - FetcherObj->NoDelete = (!Delete); - return FetcherObj; + CppPyObject *obj = CppPyObject_NEW(&PyAcquire_Type, fetcher); + obj->NoDelete = (!Delete); + return obj; } static char *doc_PkgAcquire = @@ -399,7 +339,7 @@ static char *doc_PkgAcquire = PyTypeObject PyAcquire_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Acquire", // tp_name - sizeof(PyAcquireObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods CppDeallocPtr, // tp_dealloc diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 5a5a6c6f..ec6cf10e 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -123,6 +123,7 @@ extern PyTypeObject PySystemLock_Type; extern PyTypeObject PyFileLock_Type; PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); +PyObject *PyAcquireItem_FromCpp(pkgAcquire::Item *item, bool Delete, PyObject *owner); #include "python-apt.h" #endif diff --git a/python/progress.cc b/python/progress.cc index 0fc01085..b69149d5 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -17,7 +17,6 @@ #include "generic.h" #include "apt_pkgmodule.h" - /** * Set an attribute on an object, after creating the value with * Py_BuildValue(fmt, arg). Afterwards, decrease its refcount and return @@ -118,6 +117,16 @@ void PyOpProgress::Done() // apt interface +PyObject *PyFetchProgress::GetDesc(pkgAcquire::ItemDesc *item) { + if (!pyAcquire && item->Owner && item->Owner->GetOwner()) { + pyAcquire = PyAcquire_FromCpp(item->Owner->GetOwner(), false); + } + PyObject *pyItem = PyAcquireItem_FromCpp(item->Owner, false, pyAcquire); + PyObject *pyDesc = PyAcquireItemDesc_FromCpp(item, false, pyItem); + Py_DECREF(pyItem); + return pyDesc; +} + bool PyFetchProgress::MediaChange(string Media, string Drive) { PyCbObj_END_ALLOW_THREADS @@ -171,7 +180,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "ims_hit")) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLHit); PyCbObj_BEGIN_ALLOW_THREADS @@ -181,7 +190,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "fetch")) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fetch", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLQueued); PyCbObj_BEGIN_ALLOW_THREADS @@ -191,7 +200,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "done")) - RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("done", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLDone); PyCbObj_BEGIN_ALLOW_THREADS @@ -201,7 +210,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "fail")) { - RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fail", TUPLEIZE(GetDesc(&Itm))); PyCbObj_BEGIN_ALLOW_THREADS return; } @@ -219,7 +228,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_HasAttrString(callbackInst, "fail")) - RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fail", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLFailed); PyCbObj_BEGIN_ALLOW_THREADS @@ -279,24 +288,15 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) setattr(callbackInst, "elapsed_time", "k", ElapsedTime); setattr(callbackInst, "current_items", "k", CurrentItems); setattr(callbackInst, "total_items", "k", TotalItems); -#ifdef COMPAT_0_7 - setattr(callbackInst, "currentCPS", "d", CurrentCPS); - setattr(callbackInst, "currentBytes", "d", CurrentBytes); - setattr(callbackInst, "totalBytes", "d", TotalBytes); - setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); - setattr(callbackInst, "currentItems", "k", CurrentItems); - setattr(callbackInst, "totalItems", "k", TotalItems); -#endif // New style -#ifdef COMPAT_0_7 if (!PyObject_HasAttrString(callbackInst, "updateStatus")) { -#else - { -#endif PyObject *result1; bool res1 = true; + if (pyAcquire == NULL) { + pyAcquire = PyAcquire_FromCpp(Owner, false); + } Py_INCREF(pyAcquire); if (RunSimpleCallback("pulse", TUPLEIZE(pyAcquire) , &result1)) { @@ -308,11 +308,14 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) } PyCbObj_BEGIN_ALLOW_THREADS return true; - - - } #ifdef COMPAT_0_7 + setattr(callbackInst, "currentCPS", "d", CurrentCPS); + setattr(callbackInst, "currentBytes", "d", CurrentBytes); + setattr(callbackInst, "totalBytes", "d", TotalBytes); + setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); + setattr(callbackInst, "currentItems", "k", CurrentItems); + setattr(callbackInst, "totalItems", "k", TotalItems); // Go through the list of items and add active items to the // activeItems vector. map activeItemMap; @@ -401,6 +404,8 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyCbObj_BEGIN_ALLOW_THREADS // fetching can be canceld by returning false return res; +#else + return false; #endif } diff --git a/python/progress.h b/python/progress.h index 7e75652b..4e66c771 100644 --- a/python/progress.h +++ b/python/progress.h @@ -64,6 +64,7 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj { protected: PyObject *pyAcquire; + PyObject *GetDesc(pkgAcquire::ItemDesc *item); public: enum { DLDone, DLQueued, DLFailed, DLHit, DLIgnored -- cgit v1.2.3 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. --- debian/changelog | 1 + 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 ++++----- 24 files changed, 219 insertions(+), 278 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/debian/changelog b/debian/changelog index 9b505a58..08bf564b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,7 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low * Drop the segfault prevention measures from the Acquire code, as they fail to work. A replacement will be added once destruction callbacks are added in APT. + * Merge the CppOwnedPyObject C++ class into CppPyObject. -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 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 From a169fd15520d61303639c0dfa2aabec3f6446fb6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 27 Feb 2010 17:31:39 +0100 Subject: * python: - Handle deprecated attributes and methods in the tp_gettattro slot, this allows us to easily warn if a deprecated function is used. --- debian/changelog | 7 ++-- python/acquire-item.cc | 13 +------- python/acquire.cc | 12 +------ python/cache.cc | 88 ++++--------------------------------------------- python/cdrom.cc | 8 +++-- python/configuration.cc | 16 +-------- python/depcache.cc | 46 ++------------------------ python/generic.cc | 62 ++++++++++++++++++++++++++++++++++ python/generic.h | 6 ++++ python/indexfile.cc | 13 +------- python/metaindex.cc | 8 +---- python/pkgmanager.cc | 7 +--- python/pkgrecords.cc | 19 +---------- python/pkgsrcrecords.cc | 14 +------- python/sourcelist.cc | 10 +----- python/tag.cc | 19 ++--------- 16 files changed, 98 insertions(+), 250 deletions(-) (limited to 'python/acquire-item.cc') diff --git a/debian/changelog b/debian/changelog index 25553644..e5945ef4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.7.93.2) UNRELEASED; urgency=low +python-apt (0.7.93.2) unstable; urgency=low [ Julian Andres Klode ] * Fix some places where the old API was still used: @@ -8,6 +8,9 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * utils/migrate-0.8.py: - Improve C++ parsing and add apt.progress.old to the modules, reduces false positives. + * python: + - Handle deprecated attributes and methods in the tp_gettattro slot, this + allows us to easily warn if a deprecated function is used. * python/tagfile.cc: - Implement the iterator protocol in TagFile. * python/cache.cc: @@ -35,7 +38,7 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * python/progress.cc: - try to call compatibility functions first, then new functions - -- Julian Andres Klode Sun, 07 Feb 2010 19:58:40 +0100 + -- Julian Andres Klode Sat, 27 Feb 2010 14:00:43 +0100 python-apt (0.7.93.1) unstable; urgency=low diff --git a/python/acquire-item.cc b/python/acquire-item.cc index d5f9ad10..09f0d643 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -128,17 +128,6 @@ static PyGetSetDef acquireitem_getset[] = { {"is_trusted",acquireitem_get_is_trusted}, {"local",acquireitem_get_local}, {"status",acquireitem_get_status}, -#ifdef COMPAT_0_7 - {"Complete",acquireitem_get_complete}, - {"DescURI",acquireitem_get_desc_uri}, - {"DestFile",acquireitem_get_destfile}, - {"ErrorText",acquireitem_get_error_text}, - {"FileSize",acquireitem_get_filesize}, - {"ID",acquireitem_get_id}, - {"IsTrusted",acquireitem_get_is_trusted}, - {"Local",acquireitem_get_local}, - {"Status",acquireitem_get_status}, -#endif {} }; @@ -180,7 +169,7 @@ PyTypeObject PyAcquireItem_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | diff --git a/python/acquire.cc b/python/acquire.cc index 5e22280e..cc9ee310 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -229,10 +229,6 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) static PyMethodDef PkgAcquireMethods[] = { {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#ifdef COMPAT_0_7 - {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, - {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#endif {} }; @@ -284,12 +280,6 @@ static PyGetSetDef PkgAcquireGetSet[] = { {"workers",PkgAcquireGetWorkers}, {"partial_present",PkgAcquireGetPartialPresent}, {"total_needed",PkgAcquireGetTotalNeeded}, -#ifdef COMPAT_0_7 - {"FetchNeeded",PkgAcquireGetFetchNeeded}, - {"Items",PkgAcquireGetItems}, - {"PartialPresent",PkgAcquireGetPartialPresent}, - {"TotalNeeded",PkgAcquireGetTotalNeeded}, -#endif {} }; @@ -354,7 +344,7 @@ PyTypeObject PyAcquire_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/cache.cc b/python/cache.cc index 5743d9df..3c9bc785 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -153,7 +153,6 @@ static PyMethodDef PkgCacheMethods[] = { {"update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, #ifdef COMPAT_0_7 - {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, {"Open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, {"Close", PkgCacheClose, METH_VARARGS,"Close the cache"}, #endif @@ -216,16 +215,6 @@ static PyGetSetDef PkgCacheGetSet[] = { {"provides_count",PkgCacheGetProvidesCount}, {"ver_file_count",PkgCacheGetVerFileCount}, {"version_count",PkgCacheGetVersionCount}, -#ifdef COMPAT_0_7 - {"DependsCount",PkgCacheGetDependsCount}, - {"FileList",PkgCacheGetFileList}, - {"PackageCount",PkgCacheGetPackageCount}, - {"PackageFileCount",PkgCacheGetPackageFileCount}, - {"Packages",PkgCacheGetPackages}, - {"ProvidesCount",PkgCacheGetProvidesCount}, - {"VerFileCount",PkgCacheGetVerFileCount}, - {"VersionCount",PkgCacheGetVersionCount}, -#endif {} }; @@ -349,7 +338,7 @@ PyTypeObject PyCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -543,21 +532,6 @@ static PyGetSetDef PackageGetSet[] = { {"important",PackageGetImportant}, {"version_list",PackageGetVersionList}, {"current_ver",PackageGetCurrentVer}, - #ifdef COMPAT_0_7 - {"Name",PackageGetName}, - {"Section",PackageGetSection}, - {"RevDependsList",PackageGetRevDependsList}, - {"ProvidesList",PackageGetProvidesList}, - {"SelectedState",PackageGetSelectedState}, - {"InstState",PackageGetInstState}, - {"CurrentState",PackageGetCurrentState}, - {"ID",PackageGetID}, - {"Auto",PackageGetAuto}, - {"Essential",PackageGetEssential}, - {"Important",PackageGetImportant}, - {"VersionList",PackageGetVersionList}, - {"CurrentVer",PackageGetCurrentVer}, - #endif {} }; @@ -590,7 +564,7 @@ PyTypeObject PyPackage_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -641,10 +615,6 @@ static PyGetSetDef DescriptionGetSet[] = { {"language_code",DescriptionGetLanguageCode}, {"md5",DescriptionGetMd5}, {"file_list",DescriptionGetFileList}, - #ifdef COMPAT_0_7 - {"LanguageCode",DescriptionGetLanguageCode}, - {"FileList",DescriptionGetFileList}, - #endif {} }; @@ -675,7 +645,7 @@ PyTypeObject PyDescription_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -886,24 +856,6 @@ static PyGetSetDef VersionGetSet[] = { {"size",VersionGetSize}, {"translated_description",VersionGetTranslatedDescription}, {"ver_str",VersionGetVerStr}, -#ifdef COMPAT_0_7 - {"Arch",VersionGetArch}, - {"DependsList",VersionGetDependsList}, - {"DependsListStr",VersionGetDependsListStr}, - {"Downloadable",VersionGetDownloadable}, - {"FileList",VersionGetFileList}, - {"Hash",VersionGetHash}, - {"ID",VersionGetID}, - {"InstalledSize",VersionGetInstalledSize}, - {"ParentPkg",VersionGetParentPkg}, - {"Priority",VersionGetPriority}, - {"PriorityStr",VersionGetPriorityStr}, - {"ProvidesList",VersionGetProvidesList}, - {"Section",VersionGetSection}, - {"Size",VersionGetSize}, - {"TranslationDescription",VersionGetTranslatedDescription}, - {"VerStr",VersionGetVerStr}, -#endif {} }; @@ -926,7 +878,7 @@ PyTypeObject PyVersion_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1053,21 +1005,6 @@ static PyGetSetDef PackageFileGetSet[] = { {(char*)"site",PackageFile_GetSite}, {(char*)"size",PackageFile_GetSize}, {(char*)"version",PackageFile_GetVersion}, - #ifdef COMPAT_0_7 - {"Architecture",PackageFile_GetArchitecture}, - {"Archive",PackageFile_GetArchive}, - {"Component",PackageFile_GetComponent}, - {"FileName",PackageFile_GetFileName}, - {"ID",PackageFile_GetID}, - {"IndexType",PackageFile_GetIndexType}, - {"Label",PackageFile_GetLabel}, - {"NotAutomatic",PackageFile_GetNotAutomatic}, - {"NotSource",PackageFile_GetNotSource}, - {"Origin",PackageFile_GetOrigin}, - {"Site",PackageFile_GetSite}, - {"Size",PackageFile_GetSize}, - {"Version",PackageFile_GetVersion}, - #endif {} }; @@ -1088,7 +1025,7 @@ PyTypeObject PyPackageFile_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1158,10 +1095,6 @@ static PyMethodDef DependencyMethods[] = { {"smart_target_pkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, {"all_targets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#ifdef COMPAT_0_7 - {"SmartTargetPkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, - {"AllTargets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#endif {} }; @@ -1240,15 +1173,6 @@ static PyGetSetDef DependencyGetSet[] = { {"parent_ver",DependencyGetParentVer}, {"target_pkg",DependencyGetTargetPkg}, {"target_ver",DependencyGetTargetVer}, -#ifdef COMPAT_0_7 - {"CompType",DependencyGetCompType}, - {"DepType",DependencyGetDepType}, - {"ID",DependencyGetID}, - {"ParentPkg",DependencyGetParentPkg}, - {"ParentVer",DependencyGetParentVer}, - {"TargetPkg",DependencyGetTargetPkg}, - {"TargetVer",DependencyGetTargetVer}, -#endif {} }; @@ -1272,7 +1196,7 @@ PyTypeObject PyDependency_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/cdrom.cc b/python/cdrom.cc index 0b9ae578..9eae49dc 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -78,6 +78,9 @@ static PyObject *cdrom_ident(PyObject *Self,PyObject *Args) #ifdef COMPAT_0_7 static PyObject *cdrom_ident_old(PyObject *Self,PyObject *Args) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Method 'Ident' of the " + "'apt_pkg.Cdrom' object is deprecated, use 'ident' instead.", + 1); pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; @@ -101,8 +104,7 @@ static PyMethodDef cdrom_methods[] = { {"add",cdrom_add,METH_VARARGS,cdrom_add_doc}, {"ident",cdrom_ident,METH_VARARGS,cdrom_ident_doc}, #ifdef COMPAT_0_7 - {"Add",cdrom_add,METH_VARARGS,"Add(progress) -> Add a cdrom"}, - {"Ident",cdrom_ident_old,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, + {"Ident",cdrom_ident_old,METH_VARARGS,"DEPRECATED. DO NOT USE"}, #endif {} }; @@ -134,7 +136,7 @@ PyTypeObject PyCdrom_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/configuration.cc b/python/configuration.cc index 974f6f3d..299e06ec 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -446,20 +446,6 @@ static PyMethodDef CnfMethods[] = {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, {"clear",CnfClear,METH_VARARGS,doc_Clear}, -#ifdef COMPAT_0_7 - {"Find",CnfFind,METH_VARARGS,doc_Find}, - {"FindFile",CnfFindFile,METH_VARARGS,doc_FindFile}, - {"FindDir",CnfFindDir,METH_VARARGS,doc_FindDir}, - {"FindI",CnfFindI,METH_VARARGS,doc_FindI}, - {"FindB",CnfFindB,METH_VARARGS,doc_FindB}, - {"Set",CnfSet,METH_VARARGS,doc_Set}, - {"Exists",CnfExists,METH_VARARGS,doc_Exists}, - {"SubTree",CnfSubTree,METH_VARARGS,doc_SubTree}, - {"List",CnfList,METH_VARARGS,doc_List}, - {"ValueList",CnfValueList,METH_VARARGS,doc_ValueList}, - {"MyTag",CnfMyTag,METH_VARARGS,doc_MyTag}, - {"Clear",CnfClear,METH_VARARGS,doc_Clear}, -#endif // Python Special {"keys",CnfKeys,METH_VARARGS,doc_Keys}, #if PY_MAJOR_VERSION < 3 @@ -498,7 +484,7 @@ PyTypeObject PyConfiguration_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/depcache.cc b/python/depcache.cc index 53459c32..8b4e02b5 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -569,34 +569,8 @@ static PyMethodDef PkgDepCacheMethods[] = {"marked_keep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, {"marked_reinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, {"marked_downgrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - // Action {"commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#ifdef COMPAT_0_7 - {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, - {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, - {"SetCandidateVer",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, - {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, - {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, - {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, - {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, - {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, - {"MarkInstall",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"SetReInstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, - {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, - {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, - {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, - {"IsGarbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, - {"IsAutoInstalled",PkgDepCacheIsAutoInstalled,METH_VARARGS,"Is pkg marked as auto installed"}, - {"MarkedInstall",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, - {"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, - {"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, - {"MarkedKeep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, - {"MarkedReinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, - {"MarkedDowngrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - {"Commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#endif {} }; @@ -641,14 +615,6 @@ static PyGetSetDef PkgDepCacheGetSet[] = { {"keep_count",PkgDepCacheGetKeepCount}, {"usr_size",PkgDepCacheGetUsrSize}, {"policy",PkgDepCacheGetPolicy}, - #ifdef COMPAT_0_7 - {"BrokenCount",PkgDepCacheGetBrokenCount}, - {"DebSize",PkgDepCacheGetDebSize}, - {"DelCount",PkgDepCacheGetDelCount}, - {"InstCount",PkgDepCacheGetInstCount}, - {"KeepCount",PkgDepCacheGetKeepCount}, - {"UsrSize",PkgDepCacheGetUsrSize}, - #endif {} }; @@ -699,7 +665,7 @@ PyTypeObject PyDepCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -856,14 +822,6 @@ static PyMethodDef PkgProblemResolverMethods[] = // Actions {"resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, {"resolve_by_keep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #ifdef COMPAT_0_7 - {"Protect", PkgProblemResolverProtect, METH_VARARGS, "Protect(PkgIterator)"}, - {"Remove", PkgProblemResolverRemove, METH_VARARGS, "Remove(PkgIterator)"}, - {"Clear", PkgProblemResolverClear, METH_VARARGS, "Clear(PkgIterator)"}, - {"InstallProtect", PkgProblemResolverInstallProtect, METH_VARARGS, "ProtectInstalled()"}, - {"Resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, - {"ResolveByKeep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #endif {} }; @@ -886,7 +844,7 @@ PyTypeObject PyProblemResolver_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/generic.cc b/python/generic.cc index 640f0862..7af34d39 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -48,6 +48,68 @@ PyObject *HandleErrors(PyObject *Res) PyErr_SetString(PyExc_SystemError,Err.c_str()); return 0; } + +# ifdef COMPAT_0_7 +// Helpers for deprecation. + +// Given the name of the old attribute, return the name of the new attribute +// in a PyObject. +static PyObject *_PyApt_NewNameForAttribute(const char *attr) { + // Some exceptions from the standard algorithm. + if (strcasecmp(attr, "FileName") == 0) return PyString_FromString("filename"); + if (strcasecmp(attr, "DestFile") == 0) return PyString_FromString("destfile"); + if (strcasecmp(attr, "FileSize") == 0) return PyString_FromString("filesize"); + if (strcasecmp(attr, "SubTree") == 0) return PyString_FromString("subtree"); + if (strcasecmp(attr, "ReadPinFile") == 0) return PyString_FromString("read_pinfile"); + if (strcasecmp(attr, "SetReInstall") == 0) return PyString_FromString("set_reinstall"); + if (strcasecmp(attr, "URI") == 0) return PyString_FromString("uri"); + if (strcasecmp(attr, "MD5Hash") == 0) return PyString_FromString("md5_hash"); + if (strcasecmp(attr, "SHA1Hash") == 0) return PyString_FromString("sha1_hash"); + if (strcasecmp(attr, "SHA256Hash") == 0) return PyString_FromString("sha256_hash"); + size_t attrlen = strlen(attr); + // Reserve the old name + 5, this should reduce resize to a minimum. + string new_name; + new_name.reserve(attrlen + 5); + for(unsigned int i=0; i < attrlen; i++) { + // Replace all uppercase ASCII characters with their lower-case ones. + if (attr[i] > 64 && attr[i] < 91) { + if (i > 0) + new_name += "_"; + new_name += attr[i] + 32; + } else { + new_name += attr[i]; + } + } + return CppPyString(new_name); +} + +// Handle deprecated attributes by setting a warning and returning the new +// attribute. +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { + PyObject *value = PyObject_GenericGetAttr(self, attr); + if (value == NULL) { + PyObject *ptype, *pvalue, *ptraceback; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + const char *attrname = PyObject_AsString(attr); + PyObject *newattr = _PyApt_NewNameForAttribute(attrname); + value = PyObject_GenericGetAttr(self, newattr); + if (value != NULL) { + const char *newattrname = PyString_AsString(newattr); + const char *cls = self->ob_type->tp_name; + char *warning_string = new char[strlen(newattrname) + strlen(cls) + + strlen(attrname) + 66]; + sprintf(warning_string, "Attribute '%s' of the '%s' object is " + "deprecated, use '%s' instead.", attrname, cls, newattrname); + PyErr_WarnEx(PyExc_DeprecationWarning, warning_string, 1); + delete[] warning_string; + } else { + PyErr_Restore(ptype, pvalue, ptraceback); + } + Py_DECREF(newattr); + } + return value; +} +# endif //COMPAT_0_7 /*}}}*/ // ListToCharChar - Convert a list to an array of char char /*{{{*/ // --------------------------------------------------------------------- diff --git a/python/generic.h b/python/generic.h index 7d2d6d3e..31c1bc2d 100644 --- a/python/generic.h +++ b/python/generic.h @@ -227,4 +227,10 @@ PyObject *HandleErrors(PyObject *Res = 0); const char **ListToCharChar(PyObject *List,bool NullTerm = false); PyObject *CharCharToList(const char **List,unsigned long Size = 0); +# ifdef COMPAT_0_7 +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr); +# else +# define _PyAptObject_getattro 0 +# endif + #endif diff --git a/python/indexfile.cc b/python/indexfile.cc index e8df9cf2..c6d0b1cc 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -28,9 +28,6 @@ static PyObject *IndexFileArchiveURI(PyObject *Self,PyObject *Args) static PyMethodDef IndexFileMethods[] = { {"archive_uri",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #ifdef COMPAT_0_7 - {"ArchiveURI",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #endif {} }; @@ -76,14 +73,6 @@ static PyGetSetDef IndexFileGetSet[] = { {"is_trusted",IndexFileGetIsTrusted}, {"label",IndexFileGetLabel}, {"size",IndexFileGetSize}, - #ifdef COMPAT_0_7 - {"Describe",IndexFileGetDescribe}, - {"Exists",IndexFileGetExists}, - {"HasPackages",IndexFileGetHasPackages}, - {"IsTrusted",IndexFileGetIsTrusted}, - {"Label",IndexFileGetLabel}, - {"Size",IndexFileGetSize}, - #endif {} }; @@ -107,7 +96,7 @@ PyTypeObject PyIndexFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/metaindex.cc b/python/metaindex.cc index dee54521..2dcade7d 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -52,12 +52,6 @@ static PyGetSetDef MetaIndexGetSet[] = { {"index_files",MetaIndexGetIndexFiles}, {"is_trusted",MetaIndexGetIsTrusted}, {"uri",MetaIndexGetURI}, - #ifdef COMPAT_0_7 - {"Dist",MetaIndexGetDist}, - {"IndexFiles",MetaIndexGetIndexFiles}, - {"IsTrusted",MetaIndexGetIsTrusted}, - {"URI",MetaIndexGetURI}, - #endif {} }; @@ -91,7 +85,7 @@ PyTypeObject PyMetaIndex_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9b4a9ab7..2fda14ee 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -100,11 +100,6 @@ static PyMethodDef PkgManagerMethods[] = {"get_archives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, {"do_install",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, {"fix_missing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, -#ifdef COMPAT_0_7 - {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, - {"DoInstall",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, - {"FixMissing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, -#endif {} }; @@ -128,7 +123,7 @@ PyTypeObject PyPackageManager_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 1e43b2e8..0e00edcd 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -50,9 +50,6 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) static PyMethodDef PkgRecordsMethods[] = { {"lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #ifdef COMPAT_0_7 - {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #endif {} }; @@ -132,20 +129,6 @@ static PyGetSetDef PkgRecordsGetSet[] = { {"short_desc",PkgRecordsGetShortDesc}, {"source_pkg",PkgRecordsGetSourcePkg}, {"source_ver",PkgRecordsGetSourceVer}, -#ifdef COMPAT_0_7 - {"FileName",PkgRecordsGetFileName}, - {"Homepage",PkgRecordsGetHomepage}, - {"LongDesc",PkgRecordsGetLongDesc}, - {"MD5Hash",PkgRecordsGetMD5Hash}, - {"Maintainer",PkgRecordsGetMaintainer}, - {"Name",PkgRecordsGetName}, - {"Record",PkgRecordsGetRecord}, - {"SHA1Hash",PkgRecordsGetSHA1Hash}, - {"SHA256Hash",PkgRecordsGetSHA256Hash}, - {"ShortDesc",PkgRecordsGetShortDesc}, - {"SourcePkg",PkgRecordsGetSourcePkg}, - {"SourceVer",PkgRecordsGetSourceVer}, -#endif {} }; @@ -180,7 +163,7 @@ PyTypeObject PyPackageRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 41ee6276..95f35f23 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -71,10 +71,6 @@ static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#ifdef COMPAT_0_7 - {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, - {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#endif {} }; @@ -234,15 +230,7 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {"section",PkgSrcRecordsGetSection}, {"version",PkgSrcRecordsGetVersion}, #ifdef COMPAT_0_7 - {"Binaries",PkgSrcRecordsGetBinaries}, {"BuildDepends",PkgSrcRecordsGetBuildDepends_old,0,"Deprecated function and deprecated output format."}, - {"Files",PkgSrcRecordsGetFiles}, - {"Index",PkgSrcRecordsGetIndex}, - {"Maintainer",PkgSrcRecordsGetMaintainer}, - {"Package",PkgSrcRecordsGetPackage}, - {"Record",PkgSrcRecordsGetRecord}, - {"Section",PkgSrcRecordsGetSection}, - {"Version",PkgSrcRecordsGetVersion}, #endif {} }; @@ -274,7 +262,7 @@ PyTypeObject PySourceRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/sourcelist.cc b/python/sourcelist.cc index b705d8b8..6184fee3 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -77,11 +77,6 @@ static PyMethodDef PkgSourceListMethods[] = {"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, {"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#ifdef COMPAT_0_7 - {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, - {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, - {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#endif {} }; @@ -104,9 +99,6 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) static PyGetSetDef PkgSourceListGetSet[] = { {"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#ifdef COMPAT_0_7 - {"List",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#endif {} }; @@ -137,7 +129,7 @@ PyTypeObject PySourceList_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/tag.cc b/python/tag.cc index 4971a03d..6d327d27 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -458,12 +458,6 @@ static PyMethodDef TagSecMethods[] = {"find_raw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, {"find_flag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, {"bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#ifdef COMPAT_0_7 - {"Find",TagSecFind,METH_VARARGS,doc_Find}, - {"FindRaw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, - {"FindFlag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, - {"Bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#endif // Python Special {"keys",TagSecKeys,METH_VARARGS,doc_Keys}, @@ -503,7 +497,7 @@ PyTypeObject PyTagSection_Type = 0, // tp_hash 0, // tp_call TagSecStr, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -536,11 +530,6 @@ static PyMethodDef TagFileMethods[] = {"step",TagFileStep,METH_VARARGS,doc_Step}, {"offset",TagFileOffset,METH_VARARGS,doc_Offset}, {"jump",TagFileJump,METH_VARARGS,doc_Jump}, -#ifdef COMPAT_0_7 - {"Step",TagFileStep,METH_VARARGS,doc_Step}, - {"Offset",TagFileOffset,METH_VARARGS,doc_Offset}, - {"Jump",TagFileJump,METH_VARARGS,doc_Jump}, -#endif {} }; @@ -554,12 +543,10 @@ static PyObject *TagFileGetSection(PyObject *Self,void*) { static PyGetSetDef TagFileGetSet[] = { {"section",TagFileGetSection,0,"Return a TagSection.",0}, -#ifdef COMPAT_0_7 - {"Section",TagFileGetSection,0,"Return a TagSection.",0}, -#endif {} }; + static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "TagFile() objects provide access to debian control files, which consists\n" "of multiple RFC822-like formatted sections.\n\n" @@ -593,7 +580,7 @@ PyTypeObject PyTagFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags -- cgit v1.2.3 From fec077050264e24d5259d4d9c3f43abb4fd4d294 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 1 Mar 2010 16:13:40 +0100 Subject: * python/acquire-item.cc: - Add AcquireItem.partialsize member. --- debian/changelog | 7 +++++++ python/acquire-item.cc | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'python/acquire-item.cc') diff --git a/debian/changelog b/debian/changelog index fd3161be..2d1c1892 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.7.93.4) unstable; urgency=low + + * python/acquire-item.cc: + - Add AcquireItem.partialsize member. + + -- Julian Andres Klode Mon, 01 Mar 2010 16:13:22 +0100 + python-apt (0.7.93.3) unstable; urgency=low * data/templates/Ubuntu.info.in: diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 09f0d643..cdb4a4bc 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -92,6 +92,12 @@ static PyObject *acquireitem_get_local(PyObject *self, void *closure) return item ? PyBool_FromLong(item->Local) : 0; } +static PyObject *acquireitem_get_partialsize(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("i", item->PartialSize) : 0; +} + static PyObject *acquireitem_get_status(PyObject *self, void *closure) { pkgAcquire::Item *item = acquireitem_tocpp(self); @@ -127,6 +133,7 @@ static PyGetSetDef acquireitem_getset[] = { {"mode",acquireitem_get_mode}, {"is_trusted",acquireitem_get_is_trusted}, {"local",acquireitem_get_local}, + {"partialsize",acquireitem_get_partialsize}, {"status",acquireitem_get_status}, {} }; -- cgit v1.2.3