From 65fc206205e13da3fab7438dcb4501231f6f88ac Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Mar 2005 18:30:03 +0000 Subject: * merged with the pkgDepCache tree Patches applied: * michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-10 * version number is 0.5.36ubuntu1 * michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-11 * return "None" in GetCandidateVer if no Candidate is found * michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-12 * changelog entry * michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-13 * never do "DepCache.Init()" implicit * michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-14 * reference counting added for Py_None --- python/cache.cc | 11 +++++++++-- python/depcache.cc | 31 ++++++++++++++----------------- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'python') diff --git a/python/cache.cc b/python/cache.cc index 9ad558da..126ab15d 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -20,9 +20,16 @@ #include #include "progress.h" -#include "cache.h" - /*}}}*/ + /*}}}*/ +struct PkgListStruct +{ + pkgCache::PkgIterator Iter; + unsigned long LastIndex; + + PkgListStruct(pkgCache::PkgIterator const &I) : Iter(I), LastIndex(0) {} + PkgListStruct() {abort();}; // G++ Bug.. +}; struct RDepListStruct { diff --git a/python/depcache.cc b/python/depcache.cc index 9c302b40..dcccf75c 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -21,7 +21,6 @@ #include #include "progress.h" -#include "cache.h" // DepCache Class /*{{{*/ // --------------------------------------------------------------------- @@ -62,6 +61,7 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) Struct.depcache->Init(0); } + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -75,6 +75,10 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); pkgCache::VerIterator I = Struct.depcache->GetCandidateVer(Pkg); + if(I.end()) { + Py_INCREF(Py_None); + return Py_None; + } CandidateObj = CppOwnedPyObject_NEW(PackageObj,&VersionType,I); return CandidateObj; @@ -93,6 +97,7 @@ static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) else pkgAllUpgrade(*Struct.depcache); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -104,11 +109,12 @@ static PyObject *PkgDepCacheReadPinFile(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"|s",&file) == 0) return 0; - if(file == NULL) + if(file == NULL) ReadPinFile(*Struct.policy); else ReadPinFile(*Struct.policy, file); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -122,6 +128,7 @@ static PyObject *PkgDepCacheFixBroken(PyObject *Self,PyObject *Args) pkgFixBroken(*Struct.depcache); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -137,6 +144,7 @@ static PyObject *PkgDepCacheMarkKeep(PyObject *Self,PyObject *Args) pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); Struct.depcache->MarkKeep(Pkg); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -152,6 +160,7 @@ static PyObject *PkgDepCacheMarkDelete(PyObject *Self,PyObject *Args) pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); Struct.depcache->MarkDelete(Pkg,purge); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -166,6 +175,7 @@ static PyObject *PkgDepCacheMarkInstall(PyObject *Self,PyObject *Args) pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); Struct.depcache->MarkInstall(Pkg); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -296,12 +306,8 @@ static PyObject *DepCacheAttr(PyObject *Self,char *Name) { PkgDepCacheStruct &Struct = GetCpp(Self); - // look like a cache - if (strcmp("Packages",Name) == 0) - return CppOwnedPyObject_NEW(Self,&PkgListType, - Struct.depcache->PkgBegin()); // size querries - else if(strcmp("KeepCount",Name) == 0) + if(strcmp("KeepCount",Name) == 0) return Py_BuildValue("l", Struct.depcache->KeepCount()); else if(strcmp("InstCount",Name) == 0) return Py_BuildValue("l", Struct.depcache->InstCount()); @@ -345,8 +351,7 @@ PyTypeObject PkgDepCacheType = PyObject *GetDepCache(PyObject *Self,PyObject *Args) { PyObject *Owner; - PyObject *pyCallbackInst = 0; - if (PyArg_ParseTuple(Args,"O!|O",&PkgCacheType,&Owner,&pyCallbackInst) == 0) + if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) return 0; PyObject *DepCachePyObj; @@ -356,14 +361,6 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) HandleErrors(DepCachePyObj); PkgDepCacheStruct &Struct = GetCpp(DepCachePyObj); - if(pyCallbackInst != 0) { - PyOpProgress progress; - progress.setCallbackInst(pyCallbackInst); - Struct.depcache->Init(&progress); - } else { - Struct.depcache->Init(0); - } - return DepCachePyObj; } -- cgit v1.2.3