diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-29 17:54:04 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-30 17:41:39 -0300 |
commit | 8af03b6247eb8620ebc91bed8006206a70e24d79 (patch) | |
tree | b64bae7361fa07f39becee1833d3bbfd0a314efa /libshiboken | |
parent | e5d554bb614ab0c1a9c057d2d191cb62b3355a82 (diff) |
Move all python2.5 compatibility code to a separate header.
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/basewrapper.h | 49 | ||||
-rw-r--r-- | libshiboken/python25compat.h | 88 |
2 files changed, 89 insertions, 48 deletions
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index f192928a6..c3fd926d1 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -36,6 +36,7 @@ #define BASEWRAPPER_H #include <Python.h> +#include "python25compat.h" #include "bindingmanager.h" #include <list> #include <map> @@ -189,54 +190,6 @@ inline bool isShibokenType(const PyObject* pyObj) #define SbkBaseWrapper_validCppObject(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->validCppObject) #define SbkBaseWrapper_setValidCppObject(pyobj,v) (((Shiboken::SbkBaseWrapper*)pyobj)->validCppObject = v) -/* The #defines below were taken from Cython-generated code to allow shiboken to be used with python2.5. - * Maybe not all of these defines are useful to us, time will tell which ones are really needed or not. - */ - -#if PY_VERSION_HEX < 0x02060000 -#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) -#define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, -#define PyType_Modified(t) - -typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; -} Py_buffer; - -#define PyBUF_SIMPLE 0 -#define PyBUF_WRITABLE 0x0001 -#define PyBUF_LOCK 0x0002 -#define PyBUF_FORMAT 0x0004 -#define PyBUF_ND 0x0008 -#define PyBUF_STRIDES (0x0010 | PyBUF_ND) -#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) -#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) -#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) -#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - -#endif -#if PY_MAJOR_VERSION < 3 -#define __Pyx_BUILTIN_MODULE_NAME "__builtin__" -#else -#define __Pyx_BUILTIN_MODULE_NAME "builtins" -#endif - -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) -#define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif - LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) SbkBaseWrapper_New(SbkBaseWrapperType* instanceType, void* cptr, diff --git a/libshiboken/python25compat.h b/libshiboken/python25compat.h new file mode 100644 index 000000000..3cbb8b9ba --- /dev/null +++ b/libshiboken/python25compat.h @@ -0,0 +1,88 @@ +/* +* This file is part of the Shiboken Python Bindings Generator project. +* +* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* version 2.1 as published by the Free Software Foundation. Please +* review the following information to ensure the GNU Lesser General +* Public License version 2.1 requirements will be met: +* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +* +* As a special exception to the GNU Lesser General Public License +* version 2.1, the object code form of a "work that uses the Library" +* may incorporate material from a header file that is part of the +* Library. You may distribute such object code under terms of your +* choice, provided that the incorporated material (i) does not exceed +* more than 5% of the total size of the Library; and (ii) is limited to +* numerical parameters, data structure layouts, accessors, macros, +* inline functions and templates. +* +* This program 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 program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +*/ + +#ifndef PYTHON25COMPAT_H +#define PYTHON25COMPAT_H + +/* + *The #defines below were taken from Cython-generated code to allow shiboken to be used with python2.5. + * Maybe not all of these defines are useful to us, time will tell which ones are really needed or not. + */ + +#if PY_VERSION_HEX < 0x02060000 +#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) +#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) +#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) +#define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#define PyType_Modified(t) + +typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; +} Py_buffer; + +#define PyBUF_SIMPLE 0 +#define PyBUF_WRITABLE 0x0001 +#define PyBUF_LOCK 0x0002 +#define PyBUF_FORMAT 0x0004 +#define PyBUF_ND 0x0008 +#define PyBUF_STRIDES (0x0010 | PyBUF_ND) +#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) +#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) +#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) +#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + +#endif +#if PY_MAJOR_VERSION < 3 +#define __Pyx_BUILTIN_MODULE_NAME "__builtin__" +#else +#define __Pyx_BUILTIN_MODULE_NAME "builtins" +#endif + +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) +#define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif + + +#endif |