From a0a7a3a90b7bb10d9e25f2d743752a0f52956785 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 28 Jul 2008 09:14:58 +0000 Subject: Move all compatibility into the same place, fixes build on python 2.4. 2008-07-28 Johan Dahlin * glib/pyglib-python-compat.h: * gobject/pygobject-private.h: Move all compatibility into the same place, fixes build on python 2.4. svn path=/trunk/; revision=890 --- glib/pyglib-python-compat.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'glib/pyglib-python-compat.h') 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 -- cgit