From d24964f86e1108f88d55a9580bbd6d2e482562dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 27 Jan 2010 15:11:39 +0100 Subject: Merge the CppOwnedPyObject C++ class into CppPyObject. --- python/python-apt.h | 61 ++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'python/python-apt.h') 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 -- cgit v1.2.3