From 70609e1f497832502cd25e874190d13c8ff628f0 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 23 Jan 2010 19:34:53 +0100 Subject: python: Export a PyAcquire_FromCpp which sets up a correct PyAcquireObject. --- python/acquire.cc | 11 +++++++++++ python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 2 ++ python/python-apt.h | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/acquire.cc b/python/acquire.cc index ef8b10b6..789f994e 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -379,6 +379,17 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) return FetcherObj; } +/** + * 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; +} + static char *doc_PkgAcquire = "Acquire(progress: apt_pkg.AcquireProgress) -> Acquire() object.\n\n" "Create a new acquire object. The parameter *progress* can be used to\n" diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index df443c10..64db74d2 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -526,6 +526,7 @@ static PyMethodDef methods[] = static struct _PyAptPkgAPIStruct API = { &PyAcquire_Type, // acquire_type + &PyAcquire_FromCpp, // acquire_fromcpp &PyAcquireFile_Type, // acquirefile_type &PyAcquireItem_Type, // acquireitem_type &PyAcquireItemDesc_Type, // acquireitemdesc_type diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index bc2f747b..5a5a6c6f 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -121,6 +121,8 @@ extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; extern PyTypeObject PySystemLock_Type; extern PyTypeObject PyFileLock_Type; + +PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); #include "python-apt.h" #endif diff --git a/python/python-apt.h b/python/python-apt.h index 3e413dff..f8c21adc 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -26,6 +26,7 @@ struct _PyAptPkgAPIStruct { PyTypeObject *acquire_type; + PyObject* (*acquire_fromcpp)(pkgAcquire *acquire, bool Delete); PyTypeObject *acquirefile_type; PyTypeObject *acquireitem_type; PyTypeObject *acquireitemdesc_type; @@ -237,7 +238,9 @@ inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, return Obj; } -# define PyAcquire_FromCpp(...) FromCpp(&PyAcquire_Type, ##__VA_ARGS__) +# 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__) -- cgit v1.2.3