1 #ifndef H_SYSTEM_PYTHON
2 #define H_SYSTEM_PYTHON
8 #define PY_SSIZE_T_CLEAN
10 #include <structmember.h>
12 #if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) < 0x0205
13 typedef ssize_t Py_ssize_t;
14 typedef Py_ssize_t (*lenfunc)(PyObject *);
17 /* Compatibility macros for Python < 2.6 */
18 #ifndef PyVarObject_HEAD_INIT
19 #define PyVarObject_HEAD_INIT(type, size) \
20 PyObject_HEAD_INIT(type) size,
24 #define Py_TYPE(o) ((o)->ob_type)
27 #if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) < 0x0206
28 #define PyBytes_Check PyString_Check
29 #define PyBytes_FromString PyString_FromString
30 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
31 #define PyBytes_Size PyString_Size
32 #define PyBytes_AsString PyString_AsString
35 #if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) >= 0x0207
36 #define CAPSULE_BUILD(ptr,name) PyCapsule_New(ptr, name, NULL)
37 #define CAPSULE_CHECK(obj) PyCapsule_CheckExact(obj)
38 #define CAPSULE_EXTRACT(obj,name) PyCapsule_GetPointer(obj, name)
40 #define CAPSULE_BUILD(ptr,name) PyCObject_FromVoidPtr(ptr, NULL)
41 #define CAPSULE_CHECK(obj) PyCObject_Check(obj)
42 #define CAPSULE_EXTRACT(obj,name) PyCObject_AsVoidPtr(obj)
45 /* For Python 3, use the PyLong type throughout in place of PyInt */
46 #if PY_MAJOR_VERSION >= 3
47 #define PyInt_Check PyLong_Check
48 #define PyInt_AsLong PyLong_AsLong
49 #define PyInt_FromLong PyLong_FromLong
50 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
51 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
52 #define PyInt_AsSsize_t PyLong_AsSsize_t
55 #endif /* H_SYSTEM_PYTHON */