summaryrefslogtreecommitdiffstats
path: root/glib/pyglib-python-compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'glib/pyglib-python-compat.h')
-rw-r--r--glib/pyglib-python-compat.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h
index 83357a8..43a9185 100644
--- a/glib/pyglib-python-compat.h
+++ b/glib/pyglib-python-compat.h
@@ -21,19 +21,34 @@
#ifndef __PYGLIB_PYTHON_COMPAT_H__
#define __PYGLIB_PYTHON_COMPAT_H__
+/* Python 2.3 does not define Py_CLEAR */
+#ifndef Py_CLEAR
+#define Py_CLEAR(op) \
+ do { \
+ if (op) { \
+ PyObject *tmp = (PyObject *)(op); \
+ (op) = NULL; \
+ Py_DECREF(tmp); \
+ } \
+ } while (0)
+#endif
+
/* Compilation on Python 2.4 */
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+typedef inquiry lenfunc;
#endif
/* Compilation on Python 2.x */
#if PY_VERSION_HEX < 0x03000000
#define RO READONLY
-#define _PyUnicode_Check PyString_Check
+#define _PyUnicode_Check PyString_Check
#define _PyUnicode_AsString PyString_AsString
#define _PyUnicode_AsStringAndSize PyString_AsStringAndSize
-#define _PyUnicode_FromString PyString_FromString
-#define _PyUnicode_FromStringAndSize PyString_FromStringAndSize
+#define _PyUnicode_FromString PyString_FromString
+#define _PyUnicode_FromStringAndSize PyString_FromStringAndSize
#define _PyUnicode_FromFormat PyString_FromFormat
#define _PyUnicode_AS_STRING PyString_AS_STRING
#define _PyUnicode_GET_SIZE PyString_GET_SIZE
@@ -75,16 +90,16 @@ PyTypeObject symbol = { \
typename, \
sizeof(csymbol) \
};
-#define PYGLIB_REGISTER_TYPE(d, type, name) \
+#define PYGLIB_REGISTER_TYPE(d, type, name) \
if (!type.tp_alloc) \
- type.tp_alloc = PyType_GenericAlloc; \
+ type.tp_alloc = PyType_GenericAlloc; \
if (!type.tp_new) \
- type.tp_new = PyType_GenericNew; \
+ type.tp_new = PyType_GenericNew; \
if (PyType_Ready(&type)) \
- return; \
+ return; \
PyDict_SetItemString(d, name, (PyObject *)&type);
-#define _PyUnicode_Check PyUnicode_Check
+#define _PyUnicode_Check PyUnicode_Check
#define _PyUnicode_AsString PyUnicode_AsString
#define _PyUnicode_AsStringAndSize(obj, buf, size) PyUnicode_AsStringAndSize(obj, size)
#define _PyUnicode_FromString PyUnicode_FromString