--- python/header-py.c.orig 2012-04-23 09:13:33.000000000 +0000 +++ python/header-py.c 2012-04-23 09:14:25.000000000 +0000 @@ -368,8 +368,8 @@ static PyObject *hdr_new(PyTypeObject *s if (obj == NULL) { h = headerNew(); - } else if (PyCObject_Check(obj)) { - h = PyCObject_AsVoidPtr(obj); + } else if (CAPSULE_CHECK(obj)) { + h = CAPSULE_EXTRACT(obj, "rpm._C_Header"); } else if (hdrObject_Check(obj)) { h = headerCopy(((hdrObject*) obj)->h); } else if (PyBytes_Check(obj)) { --- python/rpmsystem-py.h.orig 2012-04-23 09:12:49.000000000 +0000 +++ python/rpmsystem-py.h 2012-04-23 09:13:19.000000000 +0000 @@ -33,6 +33,16 @@ typedef Py_ssize_t (*lenfunc)(PyObject * #define PyBytes_AsString PyString_AsString #endif +#if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) >= 0x0207 +#define CAPSULE_BUILD(ptr,name) PyCapsule_New(ptr, name, NULL) +#define CAPSULE_CHECK(obj) PyCapsule_CheckExact(obj) +#define CAPSULE_EXTRACT(obj,name) PyCapsule_GetPointer(obj, name) +#else +#define CAPSULE_BUILD(ptr,name) PyCObject_FromVoidPtr(ptr, NULL) +#define CAPSULE_CHECK(obj) PyCObject_Check(obj) +#define CAPSULE_EXTRACT(obj,name) PyCObject_AsVoidPtr(obj) +#endif + /* For Python 3, use the PyLong type throughout in place of PyInt */ #if PY_MAJOR_VERSION >= 3 #define PyInt_Check PyLong_Check --- python/spec-py.c.orig 2012-04-23 09:13:41.000000000 +0000 +++ python/spec-py.c 2012-04-23 09:14:56.000000000 +0000 @@ -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 = CAPSULE_BUILD(h, "rpm._C_Header"); PyObject *hdr = PyObject_CallMethod(rpmmod, "hdr", "(O)", ptr); Py_XDECREF(ptr); Py_XDECREF(rpmmod);