From 62d7f4b80d56ef1e27039441cd6584cfb71d6502 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Apr 2009 19:13:25 +0200 Subject: * python/*.cc: Use PyObject_AsFileDescriptor instead of fileno(PyFile_AsFile) Replace support for file objects with a more generic support for any object providing a fileno() method and for file descriptors (integers). This also helps us to port to Python 3, where the previously used PyFile_ functions are not available anymore. --- python/tar.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'python/tar.cc') diff --git a/python/tar.cc b/python/tar.cc index e5aaee6f..f0d57823 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -97,8 +97,7 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) PyObject *Function; char *Comp; - if (PyArg_ParseTuple(Args,"O!Os",&PyFile_Type,&File, - &Function,&Comp) == 0) + if (PyArg_ParseTuple(Args,"OOs",&File, &Function,&Comp) == 0) return 0; if (PyCallable_Check(Function) == 0) @@ -109,7 +108,11 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) { // Open the file and associate the tar - FileFd Fd(fileno(PyFile_AsFile(File)),false); + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) + return 0; + + FileFd Fd(fileno,false); ExtractTar Tar(Fd,0xFFFFFFFF,Comp); if (_error->PendingError() == true) return HandleErrors(); @@ -139,8 +142,7 @@ PyObject *debExtract(PyObject *Self,PyObject *Args) char *Chunk; const char *Comp = "gzip"; - if (PyArg_ParseTuple(Args,"O!Os",&PyFile_Type,&File, - &Function,&Chunk) == 0) + if (PyArg_ParseTuple(Args,"OOs",&File,&Function,&Chunk) == 0) return 0; if (PyCallable_Check(Function) == 0) @@ -149,10 +151,13 @@ PyObject *debExtract(PyObject *Self,PyObject *Args) return 0; } + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) + return 0; { // Open the file and associate the tar // Open the file and associate the .deb - FileFd Fd(fileno(PyFile_AsFile(File)),false); + FileFd Fd(fileno,false); debDebFile Deb(Fd); if (_error->PendingError() == true) return HandleErrors(); -- cgit v1.2.3 From 8413810c46f802490280b0be1beebaaadf1aa9f2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Apr 2009 00:47:23 +0200 Subject: * Remove any trailing whitespace --- apt/package.py | 3 +-- doc/source/apt_pkg/index.rst | 2 +- python/apt_pkgmodule.cc | 2 +- python/cache.cc | 2 +- python/cdrom.cc | 6 +++--- python/configuration.cc | 18 +++++++++--------- python/depcache.cc | 12 ++++++------ python/progress.cc | 2 +- python/tag.cc | 12 ++++++------ python/tar.cc | 2 +- tests/getcache_mem_corruption.py | 6 +++--- 11 files changed, 33 insertions(+), 34 deletions(-) (limited to 'python/tar.cc') diff --git a/apt/package.py b/apt/package.py index 5adef15c..3ea1105d 100644 --- a/apt/package.py +++ b/apt/package.py @@ -639,7 +639,6 @@ class Package(object): def installedPriority(self): """Return the priority (of the installed version). - .. deprecated:: 0.7.9 """ return getattr(self.installed, 'priority', None) @@ -800,7 +799,7 @@ class Package(object): contain multiple named variables which will be substitued. These variables are (src_section, prefix, src_pkg, src_ver). An example is the Ubuntu changelog:: - + "http://changelogs.ubuntu.com/changelogs/pool" \\ "/%(src_section)s/%(prefix)s/%(src_pkg)s" \\ "/%(src_pkg)s_%(src_ver)s/changelog" diff --git a/doc/source/apt_pkg/index.rst b/doc/source/apt_pkg/index.rst index 38310bb5..60c3ba9b 100644 --- a/doc/source/apt_pkg/index.rst +++ b/doc/source/apt_pkg/index.rst @@ -252,7 +252,7 @@ Dependencies >>> apt_pkg.ParseDepends("PkgA (>= VerA) | PkgB (>= VerB)") [[('PkgA', 'VerA', '>='), ('PkgB', 'VerB', '>=')]] - + Furthemore, this function also supports to limit the architectures, as used in e.g. Build-Depends:: diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5d0b2c0a..145a2bab 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -481,7 +481,7 @@ extern "C" void initapt_pkg() if (PyType_Ready(&PkgCdromType) == -1) return; if (PyType_Ready(&PkgProblemResolverType) == -1) return; if (PyType_Ready(&PkgActionGroupType) == -1) return; - + // Initialize the module PyObject *Module = Py_InitModule("apt_pkg",methods); diff --git a/python/cache.cc b/python/cache.cc index 4db097c7..31d8c45d 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -951,7 +951,7 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) progress.setCallbackInst(pyCallbackInst); if (Cache->Open(progress,false) == false) return HandleErrors(); - } + } else { OpTextProgress Prog; if (Cache->Open(Prog,false) == false) diff --git a/python/cdrom.cc b/python/cdrom.cc index 1278d6b7..0816d93e 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -84,16 +84,16 @@ PyTypeObject PkgCdromType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "Cdrom Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgCdromMethods, // tp_methods }; diff --git a/python/configuration.cc b/python/configuration.cc index a95ac029..b4adf357 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -498,16 +498,16 @@ PyTypeObject ConfigurationType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "Configuration Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; @@ -532,16 +532,16 @@ PyTypeObject ConfigurationPtrType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ConfigurationPtr Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; @@ -566,16 +566,16 @@ PyTypeObject ConfigurationSubType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ConfigurationSub Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; diff --git a/python/depcache.cc b/python/depcache.cc index b23eecd9..2c73a1a9 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -769,16 +769,16 @@ PyTypeObject PkgProblemResolverType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ProblemResolver Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgProblemResolverMethods, // tp_methods }; @@ -825,16 +825,16 @@ PyTypeObject PkgActionGroupType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ActionGroup Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgActionGroupMethods, // tp_methods }; diff --git a/python/progress.cc b/python/progress.cc index c5a1c138..bec40ce9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -185,7 +185,7 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) bool res = true; if(!PyArg_Parse(result, "b", &res)) { - // most of the time the user who subclasses the pulse() + // most of the time the user who subclasses the pulse() // method forgot to add a return {True,False} so we just // assume he wants a True return true; diff --git a/python/tag.cc b/python/tag.cc index baf97b59..cdea3e03 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -401,16 +401,16 @@ PyTypeObject TagSecType = 0, // tp_hash 0, // tp_call TagSecStr, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "TagSection Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext TagSecMethods // tp_methods }; @@ -459,16 +459,16 @@ PyTypeObject TagFileType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "TagFile Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext TagFileMethods, // tp_methods 0, // tp_members diff --git a/python/tar.cc b/python/tar.cc index f0d57823..217554c2 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -111,7 +111,7 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) int fileno = PyObject_AsFileDescriptor(File); if (fileno == -1) return 0; - + FileFd Fd(fileno,false); ExtractTar Tar(Fd,0xFFFFFFFF,Comp); if (_error->PendingError() == true) diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py index 42e9af00..c3f6eff3 100644 --- a/tests/getcache_mem_corruption.py +++ b/tests/getcache_mem_corruption.py @@ -6,16 +6,16 @@ import re import unittest class TestGetCache(unittest.TestCase): - + def setUp(self): apt_pkg.InitConfig() apt_pkg.InitSystem() - + def testWrongInvocation(self): # wrongly invoke GetCache() rather than GetDepCache() apt_cache = apt_pkg.GetCache() self.assertRaises(ValueError, apt_pkg.GetCache, apt_cache) - + def testProperInvocation(self): apt_cache = apt_pkg.GetCache(apt.progress.OpTextProgress()) apt_depcache = apt_pkg.GetDepCache(apt_cache) -- cgit v1.2.3 From a4e69e11e544844034c3fbdc6789d5573f802117 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 25 Jun 2009 18:31:00 +0200 Subject: python: Fix some build warnings. --- python/acquire.cc | 4 ++-- python/cache.cc | 9 ++++----- python/depcache.cc | 3 --- python/indexfile.cc | 2 +- python/pkgsrcrecords.cc | 1 - python/progress.cc | 2 -- python/tar.cc | 4 ++++ setup.py | 4 ++-- 8 files changed, 13 insertions(+), 16 deletions(-) (limited to 'python/tar.cc') diff --git a/python/acquire.cc b/python/acquire.cc index e13e47d6..a36012bc 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -93,8 +93,8 @@ static PyObject *AcquireItemRepr(PyObject *Self) char S[300]; snprintf(S,sizeof(S),"<%s object: " "Status: %i Complete: %i Local: %i IsTrusted: %i " - "FileSize: %i DestFile:'%s' " - "DescURI: '%s' ID:%i ErrorText: '%s'>", + "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(), diff --git a/python/cache.cc b/python/cache.cc index 2de9c76a..0f5e27eb 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -76,9 +76,6 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) // --------------------------------------------------------------------- static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) { - PyObject *CacheFilePy = GetOwner(Self); - pkgCacheFile *Cache = GetCpp(CacheFilePy); - PyObject *pyFetchProgressInst = 0; PyObject *pySourcesList = 0; if (PyArg_ParseTuple(Args, "OO", &pyFetchProgressInst,&pySourcesList) == 0) @@ -93,6 +90,7 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) return HandleErrors(PyRes); } +#ifdef COMPAT_0_7 static PyObject *PkgCacheClose(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Close() is deprecated, " @@ -137,7 +135,7 @@ static PyObject *PkgCacheOpen(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return HandleErrors(Py_None); } - +#endif static PyMethodDef PkgCacheMethods[] = { @@ -456,10 +454,10 @@ PyTypeObject PkgListType = CppOwnedClear, // tp_clear }; +#define Owner (GetOwner(Self)) #define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \ { \ pkgCache::PkgIterator &Pkg = GetCpp(Self); \ - PyObject *Owner = GetOwner(Self); \ return Ret; \ } @@ -477,6 +475,7 @@ MkGet(PackageGetAuto,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Auto) != 0) MkGet(PackageGetEssential,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Essential) != 0)); MkGet(PackageGetImportant,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Important) != 0)); #undef MkGet +#undef Owner static PyObject *PackageGetVersionList(PyObject *Self,void*) { diff --git a/python/depcache.cc b/python/depcache.cc index e1514300..9c0c9a6f 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -62,8 +62,6 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) { - PyObject *result; - pkgDepCache *depcache = GetCpp(Self); PyObject *pyInstallProgressInst = 0; @@ -196,7 +194,6 @@ static PyObject *PkgDepCacheSetCandidateVer(PyObject *Self,PyObject *Args) &VersionType, &VersionObj) == 0) return 0; - pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); pkgCache::VerIterator &I = GetCpp(VersionObj); if(I.end()) { return HandleErrors(Py_BuildValue("b",false)); diff --git a/python/indexfile.cc b/python/indexfile.cc index ef88c2f0..73f76ce6 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -62,7 +62,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) char S[1024]; snprintf(S,sizeof(S),"", File->GetType()->Label, File->Describe().c_str(), File->Exists(), File->HasPackages(), File->Size(), diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index f75934f9..9707dce2 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -58,7 +58,6 @@ static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) { PkgSrcRecordsStruct &Struct = GetCpp(Self); - char *Name = 0; if (PyArg_ParseTuple(Args,"") == 0) return 0; diff --git a/python/progress.cc b/python/progress.cc index c5035e62..44f27b0c 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -354,7 +354,6 @@ void PyInstallProgress::FinishUpdate() pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) { - void *dummy; pkgPackageManager::OrderResult res; int ret; pid_t child_id; @@ -426,7 +425,6 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) PyErr_Print(); return pkgPackageManager::Failed; } - int child_res; if(!PyArg_Parse(result, "i", &res) ) { std::cerr << "custom waitChild() result could not be parsed?"<< std::endl; return pkgPackageManager::Failed; diff --git a/python/tar.cc b/python/tar.cc index 217554c2..b93ba31a 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -72,8 +72,12 @@ bool ProcessTar::DoItem(Item &Itm,int &Fd) case Item::FIFO: Type = "FIFO"; break; + + default: + return false; } + if (PyObject_CallFunction(Function,"sssiiiiiii",Type,Itm.Name, Itm.LinkTarget,Itm.Mode,Itm.UID,Itm.GID,Itm.Size, Itm.MTime,Itm.Major,Itm.Minor) == 0) diff --git a/setup.py b/setup.py index 2afd0708..85f4c889 100755 --- a/setup.py +++ b/setup.py @@ -12,12 +12,12 @@ from DistUtilsExtra.command import build_extra, build_i18n # The apt_pkg module files = map(lambda source: "python/"+source, - parse_makefile("python/makefile")["APT_PKG_SRC"].split()) + sorted(parse_makefile("python/makefile")["APT_PKG_SRC"].split())) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) # The apt_inst module files = map(lambda source: "python/"+source, - parse_makefile("python/makefile")["APT_INST_SRC"].split()) + sorted(parse_makefile("python/makefile")["APT_INST_SRC"].split())) apt_inst = Extension("apt_inst", files, libraries=["apt-pkg", "apt-inst"]) # Replace the leading _ that is used in the templates for translation -- cgit v1.2.3 From 3f286a1033479a7cfe40bc0e81c662eb3cd1d0f3 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Aug 2009 13:49:42 +0200 Subject: python: Disable the functions in apt_inst if built without COMPAT_0_7. Developers should use the class-based API instead. --- python/apt_instmodule.cc | 19 ++++++++----------- python/apt_instmodule.h | 3 ++- python/tar.cc | 4 ++++ 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'python/tar.cc') diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 9cb166ed..2721509e 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -23,6 +23,8 @@ #include /*}}}*/ +#ifdef COMPAT_0_7 + // debExtractControl - Exctract an arbitary control member /*{{{*/ // --------------------------------------------------------------------- /* This is a common operation so this function will stay, but others that @@ -149,25 +151,20 @@ static PyObject *arCheckMember(PyObject *Self,PyObject *Args) static PyMethodDef methods[] = { // access to ar files - {"ar_check_member", arCheckMember, METH_VARARGS, doc_arCheckMember}, + {"arCheckMember", arCheckMember, METH_VARARGS, doc_arCheckMember}, // access to deb files - {"deb_extract_control",debExtractControl,METH_VARARGS,doc_debExtractControl}, - {"deb_extract_archive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, - - // access to tar streams - {"tar_extract",tarExtract,METH_VARARGS,doc_tarExtract}, - {"deb_extract",debExtract,METH_VARARGS,doc_debExtract}, - -#ifdef COMPAT_0_7 - {"arCheckMember", arCheckMember, METH_VARARGS, doc_arCheckMember}, {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, + + // access to tar streams {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, -#endif {} }; +#else +static PyMethodDef *methods = 0; +#endif // defined(COMPAT_0_7) static const char *apt_inst_doc = diff --git a/python/apt_instmodule.h b/python/apt_instmodule.h index 9f978e44..2b07261b 100644 --- a/python/apt_instmodule.h +++ b/python/apt_instmodule.h @@ -14,11 +14,12 @@ #include "generic.h" #include +#ifdef COMPAT_0_7 PyObject *debExtract(PyObject *Self,PyObject *Args); extern char *doc_debExtract; PyObject *tarExtract(PyObject *Self,PyObject *Args); extern char *doc_tarExtract; - +#endif extern PyTypeObject PyArMember_Type; extern PyTypeObject PyArArchive_Type; diff --git a/python/tar.cc b/python/tar.cc index b93ba31a..b994d4e7 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -4,10 +4,13 @@ /* ###################################################################### Tar Inteface + * THIS FILE IS COMPLETELY DEPRECATED, AND NOT USED ANYMORE IF BUILT * + * WITHOUT COMPATIBILITY. * ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#ifdef COMPAT_0_7 #include "generic.h" #include @@ -189,3 +192,4 @@ PyObject *debExtract(PyObject *Self,PyObject *Args) return HandleErrors(Py_None); } /*}}}*/ +#endif // defined(COMPAT_0_7) -- cgit v1.2.3