1
/* Compatibility macros for Python 3 */
2
#if PY_VERSION_HEX >= 0x03000000
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)
13
# define Py_TYPE(op) ((op)->ob_type)
16
/* SWIG APIs for compatibility of both Python 2 & 3 */
18
#if PY_VERSION_HEX >= 0x03000000
19
# define SWIG_Python_str_FromFormat PyUnicode_FromFormat
21
# define SWIG_Python_str_FromFormat PyString_FromFormat
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.
29
SWIG_Python_str_AsChar(PyObject *str)
31
#if PY_VERSION_HEX >= 0x03000000
35
str = PyUnicode_AsUTF8String(str);
36
PyBytes_AsStringAndSize(str, &cstr, &len);
37
newstr = (char *) malloc(len+1);
38
memcpy(newstr, cstr, len+1);
42
return PyString_AsString(str);
46
#if PY_VERSION_HEX >= 0x03000000
47
# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
49
# define SWIG_Python_str_DelForPy3(x)
54
SWIG_Python_str_FromChar(const char *c)
56
#if PY_VERSION_HEX >= 0x03000000
57
return PyUnicode_FromString(c);
59
return PyString_FromString(c);
2
63
/* Add PyOS_snprintf for old Pythons */
3
64
#if PY_VERSION_HEX < 0x02020000