diff options
| author | Julian Andres Klode <jak@debian.org> | 2010-02-02 17:19:25 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2010-02-02 17:19:25 +0100 |
| commit | b2a1af65654e4584d6b54c5d4e12175ff0dffad9 (patch) | |
| tree | 9eeceac339bd99486b2603c0f83dc7be79d7b5d2 | |
| parent | eda5f5556f353c2403f846d74104d000c00aff90 (diff) | |
| download | python-apt-b2a1af65654e4584d6b54c5d4e12175ff0dffad9.tar.gz | |
Remove inline functions from the C++ API, export them instead (part 2).
| -rw-r--r-- | python/acquire.cc | 2 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 36 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 42 | ||||
| -rw-r--r-- | python/configuration.cc | 8 | ||||
| -rw-r--r-- | python/generic.cc | 2 | ||||
| -rw-r--r-- | python/indexrecords.cc | 2 | ||||
| -rw-r--r-- | python/python-apt-helpers.cc | 68 | ||||
| -rw-r--r-- | python/python-apt.h | 124 | ||||
| -rw-r--r-- | setup.py | 2 |
9 files changed, 217 insertions, 69 deletions
diff --git a/python/acquire.cc b/python/acquire.cc index cd7f7709..04e00b02 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -255,7 +255,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) { PyObject *List = PyList_New(0); pkgAcquire *Owner = GetCpp<pkgAcquire*>(self); - CppPyObject<pkgAcquire::Worker*> *PyWorker = NULL; + PyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d2472395..e3da1820 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -529,64 +529,94 @@ static struct _PyAptPkgAPIStruct API = { &PyAcquire_FromCpp, // acquire_fromcpp &PyAcquire_ToCpp, // acquire_tocpp &PyAcquireFile_Type, // acquirefile_type + &PyAcquireFile_FromCpp, // acquirefile_fromcpp &PyAcquireFile_ToCpp, // acquirefile_tocpp &PyAcquireItem_Type, // acquireitem_type + &PyAcquireItem_FromCpp, // acquireitem_fromcpp &PyAcquireItem_ToCpp, // acquireitem_type &PyAcquireItemDesc_Type, // acquireitemdesc_type + &PyAcquireItemDesc_FromCpp,// acquireitemdesc_fromcpp &PyAcquireItemDesc_ToCpp, // acquireitemdesc_tocpp &PyAcquireWorker_Type, // acquireworker_type + &PyAcquireWorker_FromCpp, // acquireworker_fromcpp &PyAcquireWorker_ToCpp, // acquireworker_tocpp &PyActionGroup_Type, // actiongroup_type - &PyActionGroup_ToCpp, // actiongroup_type + &PyActionGroup_FromCpp, // actiongroup_fromcpp + &PyActionGroup_ToCpp, // actiongroup_tocpp &PyCache_Type, // cache_type + &PyCache_FromCpp, // cache_fromcpp &PyCache_ToCpp, // cache_tocpp &PyCacheFile_Type, // cachefile_type + &PyCacheFile_FromCpp, // cachefile_fromcpp &PyCacheFile_ToCpp, // cachefile_tocpp &PyCdrom_Type, // cdrom_type + &PyCdrom_FromCpp, // cdrom_fromcpp &PyCdrom_ToCpp, // cdrom_tocpp &PyConfiguration_Type, // configuration_type + &PyConfiguration_FromCpp, // configuration_fromcpp &PyConfiguration_ToCpp, // configuration_tocpp &PyDepCache_Type, // depcache_type + &PyDepCache_FromCpp, // depcache_fromcpp &PyDepCache_ToCpp, // depcache_tocpp &PyDependency_Type, // dependency_type - &PyDependency_ToCpp, // dependency_type + &PyDependency_FromCpp, // dependency_fromcpp + &PyDependency_ToCpp, // dependency_tocpp &PyDependencyList_Type, // dependencylist_type + 0, // FIXME: dependencylist_fromcpp 0, // FIXME: dependencylist_tocpp &PyDescription_Type, // description_type + &PyDescription_FromCpp, // description_fromcpp &PyDescription_ToCpp, // description_tocpp &PyHashes_Type, // hashes_type + &PyHashes_FromCpp, // hashes_fromcpp &PyHashes_ToCpp, // hashes_tocpp &PyHashString_Type, // hashstring_type + &PyHashString_FromCpp, // hashstring_fromcpp &PyHashString_ToCpp, // hashstring_tocpp &PyIndexRecords_Type, // indexrecords_type + &PyIndexRecords_FromCpp, // indexrecords_tocpp &PyIndexRecords_ToCpp, // indexrecords_tocpp &PyMetaIndex_Type, // metaindex_type + &PyMetaIndex_FromCpp, // metaindex_tocpp &PyMetaIndex_ToCpp, // metaindex_tocpp &PyPackage_Type, // package_type + &PyPackage_FromCpp, // package_tocpp &PyPackage_ToCpp, // package_tocpp &PyPackageFile_Type, // packagefile_type + &PyPackageFile_FromCpp, // packagefile_tocpp &PyPackageFile_ToCpp, // packagefile_tocpp &PyIndexFile_Type, // packageindexfile_type + &PyIndexFile_FromCpp, // packageindexfile_tocpp &PyIndexFile_ToCpp, // packageindexfile_tocpp &PyPackageList_Type, // packagelist_type + 0, // FIXME: packagelist_fromcpp 0, // FIXME: packagelist_tocpp &PyPackageManager_Type, // packagemanager_type + &PyPackageManager_FromCpp, // packagemanager_type &PyPackageManager_ToCpp, // packagemanager_type &PyPackageRecords_Type, // packagerecords_type + 0, // FIXME: packagerecords_fromcpp 0, // FIXME: packagerecords_tocpp &PyPolicy_Type, // policy_type + &PyPolicy_FromCpp, // policy_tocpp &PyPolicy_ToCpp, // policy_tocpp &PyProblemResolver_Type, // problemresolver_type + &PyProblemResolver_FromCpp, // problemresolver_tocpp &PyProblemResolver_ToCpp, // problemresolver_tocpp &PySourceList_Type, // sourcelist_type + &PySourceList_FromCpp, // sourcelist_tocpp &PySourceList_ToCpp, // sourcelist_tocpp &PySourceRecords_Type, // sourcerecords_type - 0, // sourcerecords_tocpp + 0, // FIXME: sourcerecords_fromcpp + 0, // FIXME: sourcerecords_tocpp &PyTagFile_Type, // tagfile_type + &PyTagFile_FromCpp, // tagfile_tocpp &PyTagFile_ToCpp, // tagfile_tocpp &PyTagSection_Type, // tagsection_type + &PyTagSection_FromCpp, // tagsection_tocpp &PyTagSection_ToCpp, // tagsection_tocpp &PyVersion_Type, // version_type + &PyVersion_FromCpp, // version_tocpp &PyVersion_ToCpp, // version_tocpp }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index a22a25f0..3dcf8069 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -13,10 +13,20 @@ #include <Python.h> #include <apt-pkg/hashes.h> #include <apt-pkg/acquire-item.h> +#include <apt-pkg/configuration.h> +#include <apt-pkg/packagemanager.h> +#include <apt-pkg/version.h> +#include <apt-pkg/deblistparser.h> +#include <apt-pkg/pkgcache.h> +#include <apt-pkg/cachefile.h> +#include <apt-pkg/tagfile.h> +#include <apt-pkg/init.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/cdrom.h> +#include <apt-pkg/algorithms.h> #include "generic.h" // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; extern PyTypeObject PyVersion_Type; @@ -157,6 +167,36 @@ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); # define PyTagSection_ToCpp GetCpp<pkgTagSection> # define PyVersion_ToCpp GetCpp<pkgCache::VerIterator> +PyObject* PyAcquireFile_FromCpp(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItem_FromCpp(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItemDesc_FromCpp(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireWorker_FromCpp(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); +PyObject* PyActionGroup_FromCpp(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCache_FromCpp(pkgCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCacheFile_FromCpp(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCdrom_FromCpp(pkgCdrom const &obj, bool Delete, PyObject *Owner); +PyObject* PyConfiguration_FromCpp(Configuration* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDepCache_FromCpp(pkgDepCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDependency_FromCpp(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyDependencyList_FromCpp(RDepListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyDescription_FromCpp(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashes_FromCpp(Hashes const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashString_FromCpp(HashString* const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexRecords_FromCpp(indexRecords* const &obj, bool Delete, PyObject *Owner); +PyObject* PyMetaIndex_FromCpp(metaIndex* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackage_FromCpp(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexFile_FromCpp(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageFile_FromCpp(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageList_FromCpp(PkgListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageManager_FromCpp(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageRecords_FromCpp(PkgRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPolicy_FromCpp(pkgPolicy* const &obj, bool Delete, PyObject *Owner); +PyObject* PyProblemResolver_FromCpp(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); +PyObject* PySourceList_FromCpp(pkgSourceList* const &obj, bool Delete, PyObject *Owner); +//PyObject* PySourceRecords_FromCpp(PkgSrcRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagFile_FromCpp(pkgTagFile const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagSection_FromCpp(pkgTagSection const &obj, bool Delete, PyObject *Owner); +PyObject* PyVersion_FromCpp(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); #include "python-apt.h" #endif diff --git a/python/configuration.cc b/python/configuration.cc index 0cad8db3..974f6f3d 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -280,7 +280,7 @@ PyObject *LoadConfig(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -298,7 +298,7 @@ PyObject *LoadConfigISC(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -316,7 +316,7 @@ PyObject *LoadConfigDir(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -348,7 +348,7 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"OO!O!",&Self, &PyList_Type,&POList,&PyList_Type,&Pargv) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; diff --git a/python/generic.cc b/python/generic.cc index 51439a1b..640f0862 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -9,6 +9,8 @@ /*}}}*/ // Include Files /*{{{*/ #include "generic.h" +using namespace std; + #include <apt-pkg/error.h> /*}}}*/ diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 5750bf6b..80960160 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -60,7 +60,7 @@ static PyObject *indexrecords_lookup(PyObject *self,PyObject *args) } // Copy the HashString(), to prevent crashes and to not require the // indexRecords object to exist. - PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash)); + PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash), true, NULL); PyObject *value = Py_BuildValue("(Oi)",py_hash,result->Size); Py_DECREF(py_hash); return value; diff --git a/python/python-apt-helpers.cc b/python/python-apt-helpers.cc new file mode 100644 index 00000000..7a0f20c4 --- /dev/null +++ b/python/python-apt-helpers.cc @@ -0,0 +1,68 @@ +/* + * python-apt.h - Common object creation functions for the public API + * + * Copyright 2010 Julian Andres Klode <jak@debian.org> + * + * 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 "apt_pkgmodule.h" + +/** + * Short macro to be used for the generic FromCpp functions. + * + */ +#define NEW_FROM(NAME,TYPE,Cpp) \ +PyObject* NAME(Cpp const &obj, bool Delete, PyObject *Owner) \ +{ \ + CppPyObject<Cpp> *Obj = CppPyObject_NEW<Cpp>(Owner, TYPE, obj); \ + Obj->NoDelete = (!Delete); \ + return Obj; \ +} + +// Create all those functions +NEW_FROM(PyAcquireFile_FromCpp,&PyAcquireFile_Type,pkgAcqFile*) +NEW_FROM(PyAcquireItem_FromCpp,&PyAcquireItem_Type,pkgAcquire::Item*) +NEW_FROM(PyAcquireItemDesc_FromCpp,&PyAcquireItemDesc_Type,pkgAcquire::ItemDesc*) +NEW_FROM(PyAcquireWorker_FromCpp,&PyAcquireWorker_Type,pkgAcquire::Worker*) +NEW_FROM(PyActionGroup_FromCpp,&PyActionGroup_Type,pkgDepCache::ActionGroup*) +NEW_FROM(PyCache_FromCpp,&PyCache_Type,pkgCache*) +NEW_FROM(PyCacheFile_FromCpp,&PyCacheFile_Type,pkgCacheFile*) +NEW_FROM(PyCdrom_FromCpp,&PyCdrom_Type,pkgCdrom) +NEW_FROM(PyConfiguration_FromCpp,&PyConfiguration_Type,Configuration*) +NEW_FROM(PyDepCache_FromCpp,&PyDepCache_Type,pkgDepCache*) +NEW_FROM(PyDependency_FromCpp,&PyDependency_Type,pkgCache::DepIterator) +//NEW_FROM(PyDependencyList_FromCpp,&PyDependencyList_Type,RDepListStruct) +NEW_FROM(PyDescription_FromCpp,&PyDescription_Type,pkgCache::DescIterator) +NEW_FROM(PyHashes_FromCpp,&PyHashes_Type,Hashes) +NEW_FROM(PyHashString_FromCpp,&PyHashString_Type,HashString*) +NEW_FROM(PyIndexRecords_FromCpp,&PyIndexRecords_Type,indexRecords*) +NEW_FROM(PyMetaIndex_FromCpp,&PyMetaIndex_Type,metaIndex*) +NEW_FROM(PyPackage_FromCpp,&PyPackage_Type,pkgCache::PkgIterator) +NEW_FROM(PyIndexFile_FromCpp,&PyIndexFile_Type,pkgIndexFile*) +NEW_FROM(PyPackageFile_FromCpp,&PyPackageFile_Type,pkgCache::PkgFileIterator) +//NEW_FROM(PyPackageList_FromCpp,&PyPackageList_Type,PkgListStruct) +NEW_FROM(PyPackageManager_FromCpp,&PyPackageManager_Type,pkgPackageManager*) +//NEW_FROM(PyPackageRecords_FromCpp,&PyPackageRecords_Type,PkgRecordsStruct) +NEW_FROM(PyPolicy_FromCpp,&PyPolicy_Type,pkgPolicy*) +NEW_FROM(PyProblemResolver_FromCpp,&PyProblemResolver_Type,pkgProblemResolver*) +NEW_FROM(PySourceList_FromCpp,&PySourceList_Type,pkgSourceList*) +//NEW_FROM(PySourceRecords_FromCpp,&PySourceRecords_Type,PkgSrcRecordsStruct) +NEW_FROM(PyTagFile_FromCpp,&PyTagFile_Type,pkgTagFile) +NEW_FROM(PyTagSection_FromCpp,&PyTagSection_Type,pkgTagSection) +NEW_FROM(PyVersion_FromCpp,&PyVersion_Type,pkgCache::VerIterator) + +#undef NEW_FROM diff --git a/python/python-apt.h b/python/python-apt.h index 7b34c249..0c25ff02 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -47,94 +47,126 @@ struct _PyAptPkgAPIStruct { pkgAcquire*& (*acquire_tocpp)(PyObject *self); // apt_pkg.AcquireFile PyTypeObject *acquirefile_type; + PyObject* (*acquirefile_fromcpp)(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); pkgAcqFile*& (*acquirefile_tocpp)(PyObject *self); + // apt_pkg.AcquireItem PyTypeObject *acquireitem_type; + PyObject* (*acquireitem_fromcpp)(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Item*& (*acquireitem_tocpp)(PyObject *self); // apt_pkg.AcquireItemDesc PyTypeObject *acquireitemdesc_type; + PyObject* (*acquireitemdesc_fromcpp)(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); pkgAcquire::ItemDesc*& (*acquireitemdesc_tocpp)(PyObject *self); PyTypeObject *acquireworker_type; + PyObject* (*acquireworker_fromcpp)(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Worker*& (*acquireworker_tocpp)(PyObject *self); PyTypeObject *actiongroup_type; + PyObject* (*actiongroup_fromcpp)(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); pkgDepCache::ActionGroup*& (*actiongroup_tocpp)(PyObject *self); PyTypeObject *cache_type; + PyObject* (*cache_fromcpp)(pkgCache* const &obj, bool Delete, PyObject *Owner); pkgCache*& (*cache_tocpp)(PyObject *self); PyTypeObject *cachefile_type; + PyObject* (*cachefile_fromcpp)(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); pkgCacheFile*& (*cachefile_tocpp)(PyObject *self); PyTypeObject *cdrom_type; + PyObject* (*cdrom_fromcpp)(pkgCdrom const &obj, bool Delete, PyObject *Owner); pkgCdrom& (*cdrom_tocpp)(PyObject *self); PyTypeObject *configuration_type; + PyObject* (*configuration_fromcpp)(Configuration* const &obj, bool Delete, PyObject *Owner); Configuration*& (*configuration_tocpp)(PyObject *self); PyTypeObject *depcache_type; + PyObject* (*depcache_fromcpp)(pkgDepCache* const &obj, bool Delete, PyObject *Owner); pkgDepCache*& (*depcache_tocpp)(PyObject *self); PyTypeObject *dependency_type; + PyObject* (*dependency_fromcpp)(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DepIterator& (*dependency_tocpp)(PyObject *self); PyTypeObject *dependencylist_type; - void *dependencylist_tocpp; // FIXME: need packagelist_tocpp + void *dependencylist_fromcpp; // FIXME: need dependencylist_fromcpp + void *dependencylist_tocpp; // FIXME: need dependencylist_tocpp PyTypeObject *description_type; + PyObject* (*description_fromcpp)(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DescIterator& (*description_tocpp)(PyObject *self); PyTypeObject *hashes_type; + PyObject* (*hashes_fromcpp)(Hashes const &obj, bool Delete, PyObject *Owner); Hashes& (*hashes_tocpp)(PyObject *self); PyTypeObject *hashstring_type; + PyObject* (*hashstring_fromcpp)(HashString* const &obj, bool Delete, PyObject *Owner); HashString*& (*hashstring_tocpp)(PyObject *self); PyTypeObject *indexrecords_type; + PyObject* (*indexrecords_fromcpp)(indexRecords* const &obj, bool Delete, PyObject *Owner); indexRecords*& (*indexrecords_tocpp)(PyObject *self); PyTypeObject *metaindex_type; + PyObject* (*metaindex_fromcpp)(metaIndex* const &obj, bool Delete, PyObject *Owner); metaIndex*& (*metaindex_tocpp)(PyObject *self); PyTypeObject *package_type; + PyObject* (*package_fromcpp)(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgIterator& (*package_tocpp)(PyObject *self); PyTypeObject *packagefile_type; + PyObject* (*packagefile_fromcpp)(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgFileIterator& (*packagefile_tocpp)(PyObject *self); PyTypeObject *packageindexfile_type; + PyObject* (*indexfile_fromcpp)(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); pkgIndexFile*& (*packageindexfile_tocpp)(PyObject *self); PyTypeObject *packagelist_type; + void *packagelist_fromcpp; // FIXME: need packagelist_fromcpp void *packagelist_tocpp; // FIXME: need packagelist_tocpp PyTypeObject *packagemanager_type; + PyObject* (*packagemanager_fromcpp)(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); pkgPackageManager*& (*packagemanager_tocpp)(PyObject *self); PyTypeObject *packagerecords_type; + void *packagerecords_fromcpp; // FIXME: need packagerecords_fromcpp void *packagerecords_tocpp; // FIXME: need packagerecords_tocpp PyTypeObject *policy_type; + PyObject* (*policy_fromcpp)(pkgPolicy* const &obj, bool Delete, PyObject *Owner); pkgPolicy*& (*policy_tocpp)(PyObject *self); PyTypeObject *problemresolver_type; + PyObject* (*problemresolver_fromcpp)(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); pkgProblemResolver*& (*problemresolver_tocpp)(PyObject *self); PyTypeObject *sourcelist_type; + PyObject* (*sourcelist_fromcpp)(pkgSourceList* const &obj, bool Delete, PyObject *Owner); pkgSourceList*& (*sourcelist_tocpp)(PyObject *self); PyTypeObject *sourcerecords_type; + void *sourcerecords_fromcpp; // FIXME: need sourcerecords_fromcpp void *sourcerecords_tocpp; // FIXME: need sourcerecords_tocpp PyTypeObject *tagfile_type; + PyObject* (*tagfile_fromcpp)(pkgTagFile const &obj, bool Delete, PyObject *Owner); pkgTagFile& (*tagfile_tocpp)(PyObject *self); PyTypeObject *tagsection_type; + PyObject* (*tagsection_fromcpp)(pkgTagSection const &obj, bool Delete, PyObject *Owner); pkgTagSection& (*tagsection_tocpp)(PyObject *self); PyTypeObject *version_type; + PyObject* (*version_fromcpp)(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); pkgCache::VerIterator& (*version_tocpp)(PyObject *self); + }; // Checking macros. @@ -208,24 +240,10 @@ static struct _PyAptPkgAPIStruct *_PyAptPkg_API; static int import_apt_pkg(void) { # if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCapsule_Import("apt_pkg._C_API", 0); - return (_PyAptPkg_API != NULL) ? 0 : -1; # else - - PyObject *module = PyImport_ImportModule("apt_pkg"); - - if (module == NULL) { - return -1; - } - if (module != NULL) { - PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API"); - if (c_api_object == NULL) - return -1; - if (PyCObject_Check(c_api_object)) - _PyAptPkg_API = (struct _PyAptPkgAPIStruct *)PyCObject_AsVoidPtr(c_api_object); - Py_DECREF(c_api_object); - } - return 0; + _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCObject_Import("apt_pkg", "_C_API"); # endif // PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 + return (_PyAptPkg_API != NULL) ? 0 : -1; } # define PyAcquire_Type *(_PyAptPkg_API->acquire_type) @@ -292,48 +310,38 @@ static int import_apt_pkg(void) { # define PyTagSection_ToCpp _PyAptPkg_API->tagsection_tocpp # define PyVersion_ToCpp _PyAptPkg_API->version_tocpp // Get the C++ object -# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquireFile_FromCpp _PyAptPkg_API->acquirefile_fromcpp +# define PyAcquireItem_FromCpp _PyAptPkg_API->acquireitem_fromcpp +# define PyAcquireItemDesc_FromCpp _PyAptPkg_API->acquireitemdesc_fromcpp +# define PyAcquireWorker_FromCpp _PyAptPkg_API->acquireworker_fromcpp +# define PyActionGroup_FromCpp _PyAptPkg_API->actiongroup_fromcpp +# define PyCache_FromCpp _PyAptPkg_API->cache_fromcpp +# define PyCacheFile_FromCpp _PyAptPkg_API->cachefile_fromcpp +# define PyCdrom_FromCpp _PyAptPkg_API->cdrom_fromcpp +# define PyConfiguration_FromCpp _PyAptPkg_API->configuration_fromcpp +# define PyDepCache_FromCpp _PyAptPkg_API->depcache_fromcpp +# define PyDependency_FromCpp _PyAptPkg_API->dependency_fromcpp +# define PyDependencyList_FromCpp _PyAptPkg_API->dependencylist_fromcpp // NULL +# define PyDescription_FromCpp _PyAptPkg_API->description_fromcpp +# define PyHashes_FromCpp _PyAptPkg_API->hashes_fromcpp +# define PyHashString_FromCpp _PyAptPkg_API->hashstring_fromcpp +# define PyIndexRecords_FromCpp _PyAptPkg_API->indexrecords_fromcpp +# define PyMetaIndex_FromCpp _PyAptPkg_API->metaindex_fromcpp +# define PyPackage_FromCpp _PyAptPkg_API->package_fromcpp +# define PyPackageFile_FromCpp _PyAptPkg_API->packagefile_fromcpp +# define PyIndexFile_FromCpp _PyAptPkg_API->packageindexfile_fromcpp +# define PyPackageList_FromCpp _PyAptPkg_API->packagelist_fromcpp // NULL +# define PyPackageManager_FromCpp _PyAptPkg_API->packagemanager_fromcpp +# define PyPackageRecords_FromCpp _PyAptPkg_API->packagerecords_fromcpp +# define PyPolicy_FromCpp _PyAptPkg_API->policy_fromcpp +# define PyProblemResolver_FromCpp _PyAptPkg_API->problemresolver_fromcpp +# define PySourceList_FromCpp _PyAptPkg_API->sourcelist_fromcpp +# define PySourceRecords_FromCpp _PyAptPkg_API->sourcerecords_fromcpp // NULL +# define PyTagFile_FromCpp _PyAptPkg_API->tagfile_fromcpp +# define PyTagSection_FromCpp _PyAptPkg_API->tagsection_fromcpp +# define PyVersion_FromCpp _PyAptPkg_API->version_fromcpp # endif // APT_PKGMODULE_H -// Template using a simpler version of from cpp -template<class Cpp> -inline CppPyObject<Cpp> *FromCpp(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) -{ - CppPyObject<Cpp> *Obj = CppPyObject_NEW<Cpp>(Owner, pytype, obj); - Obj->NoDelete = (!Delete); - return Obj; -} - - -# define PyAcquireFile_FromCpp(...) FromCpp<pkgAcqFile*>(&PyAcquireFile_Type, ##__VA_ARGS__) -# define PyAcquireItem_FromCpp(...) FromCpp<pkgAcquire::Item*>(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCpp<pkgAcquire::ItemDesc*>(&PyAcquireItemDesc_Type,##__VA_ARGS__) -# define PyAcquireWorker_FromCpp(...) FromCpp<pkgAcquire::Worker*>(&PyAcquireWorker_Type,##__VA_ARGS__) -# define PyActionGroup_FromCpp(...) FromCpp<pkgDepCache::ActionGroup*>(&PyActionGroup_Type,##__VA_ARGS__) -# define PyCache_FromCpp(...) FromCpp<pkgCache*>(&PyCache_Type,##__VA_ARGS__) -# define PyCacheFile_FromCpp(...) FromCpp<pkgCacheFile*>(&PyCacheFile_Type,##__VA_ARGS__) -# define PyCdrom_FromCpp(...) FromCpp<pkgCdrom>(&PyCdrom_Type,##__VA_ARGS__) -# define PyConfiguration_FromCpp(...) FromCpp<Configuration*>(&PyConfiguration_Type, ##__VA_ARGS__) -# define PyDepCache_FromCpp(...) FromCpp<pkgDepCache*>(&PyDepCache_Type,##__VA_ARGS__) -# define PyDependency_FromCpp(...) FromCpp<pkgCache::DepIterator>(&PyDependency_Type,##__VA_ARGS__) -//# define PyDependencyList_FromCpp(...) FromCpp<RDepListStruct>(&PyDependencyList_Type,##__VA_ARGS__) -# define PyDescription_FromCpp(...) FromCpp<pkgCache::DescIterator>(&PyDescription_Type,##__VA_ARGS__) -# define PyHashes_FromCpp(...) FromCpp<Hashes>(&PyHashes_Type,##__VA_ARGS__) -# define PyHashString_FromCpp(...) FromCpp<HashString*>(&PyHashString_Type,##__VA_ARGS__) -# define PyIndexRecords_FromCpp(...) FromCpp<indexRecords*>(&PyIndexRecords_Type,##__VA_ARGS__) -# define PyMetaIndex_FromCpp(...) FromCpp<metaIndex*>(&PyMetaIndex_Type,##__VA_ARGS__) -# define PyPackage_FromCpp(...) FromCpp<pkgCache::PkgIterator>(&PyPackage_Type,##__VA_ARGS__) -# define PyIndexFile_FromCpp(...) FromCpp<pkgIndexFile*>(&PyIndexFile_Type,##__VA_ARGS__) -# define PyPackageFile_FromCpp(...) FromCpp<pkgCache::PkgFileIterator>(&PyPackageFile_Type,##__VA_ARGS__) -//# define PyPackageList_FromCpp(...) FromCpp<PkgListStruct>(&PyPackageList_Type,##__VA_ARGS__) -# define PyPackageManager_FromCpp(...) FromCpp<pkgPackageManager*>(&PyPackageManager_Type,##__VA_ARGS__) -//# define PyPackageRecords_FromCpp(...) FromCpp<PkgRecordsStruct>(&PyPackageRecords_Type,##__VA_ARGS__) -# define PyPolicy_FromCpp(...) FromCpp<pkgPolicy*>(&PyPolicy_Type,##__VA_ARGS__) -# define PyProblemResolver_FromCpp(...) FromCpp<pkgProblemResolver*>(&PyProblemResolver_Type,##__VA_ARGS__) -# define PySourceList_FromCpp(...) FromCpp<pkgSourceList*>(&PySourceList_Type,##__VA_ARGS__) -//# define PySourceRecords_FromCpp(...) FromCpp<PkgSrcRecordsStruct>(&PySourceRecords_Type,##__VA_ARGS__) -# define PyTagFile_FromCpp(...) FromCpp<pkgTagFile>(&PyTagFile_Type,##__VA_ARGS__) -# define PyTagSection_FromCpp(...) FromCpp<pkgTagSection>(&PyTagSection_Type,##__VA_ARGS__) -# define PyVersion_FromCpp(...) FromCpp<pkgCache::VerIterator>(&PyVersion_Type,##__VA_ARGS__) #endif @@ -35,7 +35,7 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'lock.cc', 'acquire-item.cc'] + 'lock.cc', 'acquire-item.cc', 'python-apt-helpers.cc'] files = sorted(['python/' + fname for fname in files], key=lambda s: s[:-3]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) |
