OLD | NEW |
(Empty) | |
| 1 /* Compatibility macros for Python 3 */ |
| 2 #if PY_VERSION_HEX >= 0x03000000 |
| 3 |
| 4 #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) |
| 5 #define PyInt_Check(x) PyLong_Check(x) |
| 6 #define PyInt_AsLong(x) PyLong_AsLong(x) |
| 7 #define PyInt_FromLong(x) PyLong_FromLong(x) |
| 8 #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) |
| 9 |
| 10 #endif |
| 11 |
| 12 #ifndef Py_TYPE |
| 13 # define Py_TYPE(op) ((op)->ob_type) |
| 14 #endif |
| 15 |
| 16 /* SWIG APIs for compatibility of both Python 2 & 3 */ |
| 17 |
| 18 #if PY_VERSION_HEX >= 0x03000000 |
| 19 # define SWIG_Python_str_FromFormat PyUnicode_FromFormat |
| 20 #else |
| 21 # define SWIG_Python_str_FromFormat PyString_FromFormat |
| 22 #endif |
| 23 |
| 24 |
| 25 /* Warning: This function will allocate a new string in Python 3, |
| 26 * so please call SWIG_Python_str_DelForPy3(x) to free the space. |
| 27 */ |
| 28 SWIGINTERN char* |
| 29 SWIG_Python_str_AsChar(PyObject *str) |
| 30 { |
| 31 #if PY_VERSION_HEX >= 0x03000000 |
| 32 char *cstr; |
| 33 char *newstr; |
| 34 Py_ssize_t len; |
| 35 str = PyUnicode_AsUTF8String(str); |
| 36 PyBytes_AsStringAndSize(str, &cstr, &len); |
| 37 newstr = (char *) malloc(len+1); |
| 38 memcpy(newstr, cstr, len+1); |
| 39 Py_XDECREF(str); |
| 40 return newstr; |
| 41 #else |
| 42 return PyString_AsString(str); |
| 43 #endif |
| 44 } |
| 45 |
| 46 #if PY_VERSION_HEX >= 0x03000000 |
| 47 # define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) |
| 48 #else |
| 49 # define SWIG_Python_str_DelForPy3(x) |
| 50 #endif |
| 51 |
| 52 |
| 53 SWIGINTERN PyObject* |
| 54 SWIG_Python_str_FromChar(const char *c) |
| 55 { |
| 56 #if PY_VERSION_HEX >= 0x03000000 |
| 57 return PyUnicode_FromString(c); |
| 58 #else |
| 59 return PyString_FromString(c); |
| 60 #endif |
| 61 } |
| 62 |
| 63 /* Add PyOS_snprintf for old Pythons */ |
| 64 #if PY_VERSION_HEX < 0x02020000 |
| 65 # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) |
| 66 # define PyOS_snprintf _snprintf |
| 67 # else |
| 68 # define PyOS_snprintf snprintf |
| 69 # endif |
| 70 #endif |
| 71 |
| 72 /* A crude PyString_FromFormat implementation for old Pythons */ |
| 73 #if PY_VERSION_HEX < 0x02020000 |
| 74 |
| 75 #ifndef SWIG_PYBUFFER_SIZE |
| 76 # define SWIG_PYBUFFER_SIZE 1024 |
| 77 #endif |
| 78 |
| 79 static PyObject * |
| 80 PyString_FromFormat(const char *fmt, ...) { |
| 81 va_list ap; |
| 82 char buf[SWIG_PYBUFFER_SIZE * 2]; |
| 83 int res; |
| 84 va_start(ap, fmt); |
| 85 res = vsnprintf(buf, sizeof(buf), fmt, ap); |
| 86 va_end(ap); |
| 87 return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); |
| 88 } |
| 89 #endif |
| 90 |
| 91 /* Add PyObject_Del for old Pythons */ |
| 92 #if PY_VERSION_HEX < 0x01060000 |
| 93 # define PyObject_Del(op) PyMem_DEL((op)) |
| 94 #endif |
| 95 #ifndef PyObject_DEL |
| 96 # define PyObject_DEL PyObject_Del |
| 97 #endif |
| 98 |
| 99 /* A crude PyExc_StopIteration exception for old Pythons */ |
| 100 #if PY_VERSION_HEX < 0x02020000 |
| 101 # ifndef PyExc_StopIteration |
| 102 # define PyExc_StopIteration PyExc_RuntimeError |
| 103 # endif |
| 104 # ifndef PyObject_GenericGetAttr |
| 105 # define PyObject_GenericGetAttr 0 |
| 106 # endif |
| 107 #endif |
| 108 |
| 109 /* Py_NotImplemented is defined in 2.1 and up. */ |
| 110 #if PY_VERSION_HEX < 0x02010000 |
| 111 # ifndef Py_NotImplemented |
| 112 # define Py_NotImplemented PyExc_RuntimeError |
| 113 # endif |
| 114 #endif |
| 115 |
| 116 /* A crude PyString_AsStringAndSize implementation for old Pythons */ |
| 117 #if PY_VERSION_HEX < 0x02010000 |
| 118 # ifndef PyString_AsStringAndSize |
| 119 # define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *l
en = *s ? strlen(*s) : 0;} |
| 120 # endif |
| 121 #endif |
| 122 |
| 123 /* PySequence_Size for old Pythons */ |
| 124 #if PY_VERSION_HEX < 0x02000000 |
| 125 # ifndef PySequence_Size |
| 126 # define PySequence_Size PySequence_Length |
| 127 # endif |
| 128 #endif |
| 129 |
| 130 /* PyBool_FromLong for old Pythons */ |
| 131 #if PY_VERSION_HEX < 0x02030000 |
| 132 static |
| 133 PyObject *PyBool_FromLong(long ok) |
| 134 { |
| 135 PyObject *result = ok ? Py_True : Py_False; |
| 136 Py_INCREF(result); |
| 137 return result; |
| 138 } |
| 139 #endif |
| 140 |
| 141 /* Py_ssize_t for old Pythons */ |
| 142 /* This code is as recommended by: */ |
| 143 /* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ |
| 144 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) |
| 145 typedef int Py_ssize_t; |
| 146 # define PY_SSIZE_T_MAX INT_MAX |
| 147 # define PY_SSIZE_T_MIN INT_MIN |
| 148 #endif |
OLD | NEW |