summaryrefslogtreecommitdiffstats
path: root/glib/pyglib-python-compat.h
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-07-26 13:23:28 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-26 13:23:28 +0000
commite889e0030877bb0b3a7e83f945b8b07230973c01 (patch)
treed8dd4045f066a3e83dac29435102eeaeb4ad7986 /glib/pyglib-python-compat.h
parent83627fd48cdd1a39eec874627ef97ed560e231b8 (diff)
downloadpygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.tar.gz
pygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.tar.xz
pygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.zip
Add macros for supporting additional python versions. Start using them for
2008-07-26 Johan Dahlin <johan@gnome.org> * glib/glibmodule.c (get_handler_priority), (pyglib_idle_add), (pyglib_timeout_add), (pyglib_timeout_add_seconds), (pyglib_io_add_watch), (pyglib_child_watch_add), (pyglib_markup_escape_text), (pyglib_main_depth), (pyglib_filename_from_utf8), (pyglib_get_application_name), (pyglib_get_prgname), (PYGLIB_MODULE_START): * glib/pygiochannel.c (py_io_channel_next), (py_io_channel_shutdown), (py_io_channel_get_buffer_size), (py_io_channel_get_buffered), (py_io_channel_get_encoding), (py_io_channel_read_chars), (py_io_channel_write_chars), (py_io_channel_write_lines), (py_io_channel_flush), (py_io_channel_set_flags), (py_io_channel_get_flags), (py_io_channel_get_buffer_condition), (py_io_channel_win32_poll), (py_io_channel_read_line), (py_io_channel_read_lines), (py_io_channel_seek), (pyglib_iochannel_register_types): * glib/pyglib-private.h: * glib/pyglib-python-compat.h: * glib/pyglib.c (pyglib_init), (pyglib_error_check), (pyglib_gerror_exception_check), (pyglib_register_exception_for_domain): Add macros for supporting additional python versions. Start using them for the glib module. Tested on python 2.5 and 3.0. svn path=/trunk/; revision=870
Diffstat (limited to 'glib/pyglib-python-compat.h')
-rw-r--r--glib/pyglib-python-compat.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h
new file mode 100644
index 0000000..ccf2b85
--- /dev/null
+++ b/glib/pyglib-python-compat.h
@@ -0,0 +1,110 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYGLIB_PYTHON_COMPAT_H__
+#define __PYGLIB_PYTHON_COMPAT_H__
+
+/* Compilation on Python 2.4 */
+#if PY_VERSION_HEX < 0x02050000
+typedef int Py_ssize_t;
+#endif
+
+/* Compilation on Python 2.x */
+#if PY_VERSION_HEX < 0x03000000
+#define PYGLIB_MODULE_START(symbol, modname) \
+DL_EXPORT(void) init##symbol(void) \
+{ \
+ PyObject *module; \
+ module = Py_InitModule(modname, symbol##_functions);
+#define PYGLIB_MODULE_END }
+#define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol) \
+PyTypeObject symbol = { \
+ PyObject_HEAD_INIT(NULL) \
+ 0, \
+ typename, \
+ sizeof(csymbol) \
+};
+#define PYGLIB_REGISTER_TYPE(d, type, name) \
+ if (!type.tp_alloc) \
+ type.tp_alloc = PyType_GenericAlloc; \
+ if (!type.tp_new) \
+ type.tp_new = PyType_GenericNew; \
+ if (PyType_Ready(&type)) \
+ return; \
+ PyDict_SetItemString(d, name, (PyObject *)&type);
+
+#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_AS_STRING PyString_AS_STRING
+#define _PyUnicode_GET_SIZE PyString_GET_SIZE
+#define _PyUnicode_Resize _PyString_Resize
+#define _PyLong_Check PyInt_Check
+#define _PyLong_FromLong PyInt_FromLong
+#define _PyLong_AsLong PyInt_AsLong
+#else
+#define PYGLIB_MODULE_START(symbol, modname) \
+ static struct PyModuleDef _##symbol##module = { \
+ PyModuleDef_HEAD_INIT, \
+ modname, \
+ NULL, \
+ -1, \
+ symbol##_functions, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL \
+}; \
+PyMODINIT_FUNC PyInit_##symbol(void) \
+{ \
+ PyObject *module; \
+ module = PyModule_Create(&_##symbol##module);
+#define PYGLIB_MODULE_END return module; }
+#define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol) \
+PyTypeObject symbol = { \
+ PyVarObject_HEAD_INIT(NULL, 0) \
+ typename, \
+ sizeof(csymbol) \
+};
+#define PYGLIB_REGISTER_TYPE(d, type, name) \
+ if (!type.tp_alloc) \
+ type.tp_alloc = PyType_GenericAlloc; \
+ if (!type.tp_new) \
+ type.tp_new = PyType_GenericNew; \
+ if (PyType_Ready(&type)) \
+ return; \
+ PyDict_SetItemString(d, name, (PyObject *)&type);
+
+#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
+#define _PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
+#define _PyUnicode_AS_STRING _PyUnicode_AsString
+#define _PyUnicode_GET_SIZE PyUnicode_GET_SIZE
+#define _PyUnicode_Resize PyUnicode_Resize
+#define _PyLong_Check PyLong_Check
+#define _PyLong_FromLong PyLong_FromLong
+#define _PyLong_AsLong PyLong_AsLong
+#endif
+
+#endif /* __PYGLIB_PYTHON_COMPAT_H__ */