Add librpm-tizen.spec file & Debian packaging.
[tools/librpm-tizen.git] / python / rpmsystem-py.h
1 #ifndef H_SYSTEM_PYTHON
2 #define H_SYSTEM_PYTHON
3
4 #if defined(__APPLE__)
5 #include <sys/types.h>
6 #endif
7
8 #define PY_SSIZE_T_CLEAN
9 #include <Python.h>
10 #include <structmember.h>
11
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 *);
15 #endif  
16
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,
21 #endif 
22
23 #ifndef Py_TYPE
24 #define Py_TYPE(o) ((o)->ob_type)
25 #endif
26
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
33 #endif
34
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)
39 #else
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)
43 #endif
44
45 /* In Python 3, we return all strings as surrogate-escaped utf-8 */
46 #if PY_MAJOR_VERSION >= 3
47 #define utf8FromString(_s) PyUnicode_DecodeUTF8(_s, strlen(_s), "surrogateescape")
48 #else
49 #define utf8FromString(_s) PyBytes_FromString(_s)
50 #endif
51
52 #endif  /* H_SYSTEM_PYTHON */