[Rpm-maint] [PATCH 07/15] Use macros to hide "int" implementation differences between Python 2 and 3

David Malcolm dmalcolm at redhat.com
Thu Oct 15 19:15:01 UTC 2009


On Python 3, use macros to alias all usage of PyInt_ to PyLong_ equivalents,
as the former no longer exists.

Likewise, the "cmpfunc" typedef no longer exists; introduce a dummy definition
to enable our code to compile
---
 python/rpmsystem-py.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/python/rpmsystem-py.h b/python/rpmsystem-py.h
index 1544dd6..8875b3a 100644
--- a/python/rpmsystem-py.h
+++ b/python/rpmsystem-py.h
@@ -15,4 +15,15 @@ typedef ssize_t Py_ssize_t;
 typedef Py_ssize_t (*lenfunc)(PyObject *);
 #endif  
 
+#if PY_MAJOR_VERSION >= 3
+/* For Python 3, use the PyLong type throughout in place of PyInt: */
+#define PyInt_Check PyLong_Check
+#define PyInt_AsLong PyLong_AsLong
+#define PyInt_FromLong PyLong_FromLong
+
+/* In Python 3, "tp_compare" became "void *tp_reserved;": */
+#define cmpfunc void*
+
+#endif
+
 #endif	/* H_SYSTEM_PYTHON */
-- 
1.6.2.5



More information about the Rpm-maint mailing list