[Rpm-maint] [PATCH] python: use the more modern PyCapsule over PyCObject (RhBug:623864).
Ales Kozumplik
akozumpl at redhat.com
Tue Nov 15 14:56:45 UTC 2011
rpm.header.new() will still keep accepting PyCObject for now in case a
client library depends on this.
---
python/header-py.c | 3 +++
python/spec-py.c | 2 +-
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/python/header-py.c b/python/header-py.c
index 6d6c1e9..e41e202 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -384,7 +384,10 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
if (obj == NULL) {
h = headerNew();
} else if (PyCObject_Check(obj)) {
+ /* initializating via PyCObject deprecated since rpm-4.9.90 */
h = PyCObject_AsVoidPtr(obj);
+ } else if (PyCapsule_CheckExact(obj)) {
+ h = PyCapsule_GetPointer(obj, "rpm._C_Header");
} else if (hdrObject_Check(obj)) {
h = headerCopy(((hdrObject*) obj)->h);
} else if (PyBytes_Check(obj)) {
diff --git a/python/spec-py.c b/python/spec-py.c
index a829539..9f60626 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -34,7 +34,7 @@ static PyObject *makeHeader(Header h)
PyObject *rpmmod = PyImport_ImportModuleNoBlock("rpm");
if (rpmmod == NULL) return NULL;
- PyObject *ptr = PyCObject_FromVoidPtr(h, NULL);
+ PyObject *ptr = PyCapsule_New(h, "rpm._C_Header", NULL);
PyObject *hdr = PyObject_CallMethod(rpmmod, "hdr", "(O)", ptr);
Py_XDECREF(ptr);
Py_XDECREF(rpmmod);
--
1.7.7.3
More information about the Rpm-maint
mailing list