1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef PYTHON25COMPAT_H
41 #define PYTHON25COMPAT_H
42 #include "sbkpython.h"
43 #include <cstring>
44 
45 /*
46  *The #defines below were taken from Cython-generated code to allow shiboken to be used with python2.5.
47  * Maybe not all of these defines are useful to us, time will tell which ones are really needed or not.
48  */
49 
50 #if PY_VERSION_HEX < 0x02060000
51 #define Py_REFCNT(ob) (((PyObject *)(ob))->ob_refcnt)
52 #define Py_TYPE(ob)   (((PyObject *)(ob))->ob_type)
53 #define Py_SIZE(ob)   (((PyVarObject *)(ob))->ob_size)
54 #define PyVarObject_HEAD_INIT(type, size) \
55         PyObject_HEAD_INIT(type) size,
56 #define PyType_Modified(t)
57 
58 typedef struct {
59     void *buf;
60     PyObject *obj;
61     Py_ssize_t len;
62     Py_ssize_t itemsize;
63     int readonly;
64     int ndim;
65     char *format;
66     Py_ssize_t *shape;
67     Py_ssize_t *strides;
68     Py_ssize_t *suboffsets;
69     void *internal;
70 } Py_buffer;
71 
72 #define PyBUF_SIMPLE 0
73 #define PyBUF_WRITABLE 0x0001
74 #define PyBUF_LOCK 0x0002
75 #define PyBUF_FORMAT 0x0004
76 #define PyBUF_ND 0x0008
77 #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
78 #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
79 #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
80 #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
81 #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
82 
83 #define PyBytes_Check PyString_Check
84 #define PyBytes_FromString PyString_FromString
85 #define PyBytes_FromFormat PyString_FromFormat
86 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
87 #define PyBytes_GET_SIZE PyString_GET_SIZE
88 #define PyBytes_AS_STRING PyString_AS_STRING
89 #define PyBytes_AsString PyString_AsString
90 #define PyBytes_Concat PyString_Concat
91 #define PyBytes_Size PyString_Size
92 
PyUnicode_FromString(const char * s)93 inline PyObject *PyUnicode_FromString(const char *s)
94 {
95     std::size_t len = std::strlen(s);
96     return PyUnicode_DecodeUTF8(s, len, 0);
97 }
98 
99 #define PyLong_FromSize_t _PyLong_FromSize_t
100 #define PyLong_AsSsize_t _PyLong_AsSsize_t
101 
102 #endif
103 
104 #endif
105