1#ifndef PyObjC_COMPAT_H
2#define PyObjC_COMPAT_H
3
4#import <Cocoa/Cocoa.h>
5#import <Foundation/NSObjCRuntime.h>
6
7
8
9
10
11
12/*
13 * Compatibilty definitions
14 */
15
16#ifdef __GNUC__
17#define unlikely(x)	__builtin_expect (!!(x), 0)
18#define likely(x)	__builtin_expect (!!(x), 1)
19#else
20#define likely(x)	x
21#define likely(x)	x
22#endif
23
24#import <AvailabilityMacros.h>
25/* On 10.1 there are no defines for the OS version. */
26#ifndef MAC_OS_X_VERSION_10_1
27#define MAC_OS_X_VERSION_10_1 1010
28#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_1
29
30#error "MAC_OS_X_VERSION_10_1 not defined. You aren't running 10.1 are you?"
31
32#endif
33
34
35#ifndef MAC_OS_X_VERSION_10_2
36#define MAC_OS_X_VERSION_10_2 1020
37#endif
38
39#ifndef MAC_OS_X_VERSION_10_3
40#define MAC_OS_X_VERSION_10_3 1030
41#endif
42
43#ifndef MAC_OS_X_VERSION_10_4
44#define MAC_OS_X_VERSION_10_4 1040
45#endif
46
47#ifndef MAC_OS_X_VERSION_10_5
48#define MAC_OS_X_VERSION_10_5 1050
49#endif
50
51#ifndef MAC_OS_X_VERSION_10_6
52#define MAC_OS_X_VERSION_10_6 1060
53#endif
54
55
56/* On some versions of GCC <limits.h> defines LONG_LONG_MAX but not LLONG_MAX,
57 * compensate.
58 */
59#ifndef LLONG_MIN
60#ifdef LONG_LONG_MIN
61#define LLONG_MIN LONG_LONG_MIN
62#define LLONG_MAX LONG_LONG_MAX
63#define ULLONG_MAX ULONG_LONG_MAX
64#endif
65#endif
66
67#if (PY_VERSION_HEX < 0x02050000)
68typedef int Py_ssize_t;
69#define PY_FORMAT_SIZE_T ""
70#define Py_ARG_SIZE_T "i"
71#define PY_SSIZE_T_MAX INT_MAX
72
73#else
74
75#ifndef Py_ARG_SIZE_T
76#define Py_ARG_SIZE_T "n"
77#endif
78
79
80#endif
81
82#if PY_MAJOR_VERSION == 2
83
84#ifndef Py_ARG_BYTES
85#define Py_ARG_BYTES "z"
86#endif
87
88#else
89
90#ifndef Py_ARG_BYTES
91#define Py_ARG_BYTES "y"
92#endif
93
94#endif
95
96#if __LP64__
97#define Py_ARG_NSInteger "l"
98#define Py_ARG_NSUInteger "k"
99#else
100#define Py_ARG_NSInteger "i"
101#define Py_ARG_NSUInteger "I"
102#endif
103
104#if PY_MAJOR_VERSION == 2
105#define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
106#define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
107#define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
108
109
110/* Source-level backward compatibility: use PyCapsule API in sources, fall back to
111 * PyCObject when needed.
112 */
113#if PY_MINOR_VERSION < 7
114#define PyCapsule_New(pointer, name, destructor) PyCObject_FromVoidPtr(pointer, destructor)
115#define PyCapsule_GetPointer(object, name) PyCObject_AsVoidPtr(object)
116#define PyCapsule_CheckExact(object)	PyCObject_Check(object)
117#endif
118
119#endif
120
121#if PY_MAJOR_VERSION == 2
122
123#define PyErr_Format PyObjCErr_Format
124
125extern PyObject* PyObjCErr_Format(PyObject* exception, const char* format, ...);
126
127#define PyText_Check PyString_Check
128#define PyText_FromFormat PyString_FromFormat
129#define PyText_FromString PyString_FromString
130#define PyText_FromStringAndSize PyString_FromStringAndSize
131#define PyText_InternFromString PyString_InternFromString
132#define PyText_InternInPlace PyString_InternInPlace
133#define PyText_Append PyString_ConcatAndDel
134#define PyText_AsString	PyString_AsString
135
136#ifndef PyBytes_FromString
137#define PyBytes_AsString	PyString_AsString
138#define PyBytes_Size		PyString_Size
139#define PyBytes_FromString	PyString_FromString
140#define PyBytes_FromStringAndSize	PyString_FromStringAndSize
141#define PyBytes_AS_STRING	PyString_AS_STRING
142#endif
143
144#define PyBytes_InternFromString	PyString_InternFromString
145#define PyBytes_InternFromStringAndSize	PyObjCString_InternFromStringAndSize
146
147extern PyObject* PyObjCString_InternFromStringAndSize(const char* v, Py_ssize_t l);
148
149#else
150
151#define PyText_Check PyUnicode_Check
152#define PyText_FromFormat PyUnicode_FromFormat
153#define PyText_FromString PyUnicode_FromString
154#define PyText_FromStringAndSize PyUnicode_FromStringAndSize
155#define PyText_InternFromString PyUnicode_InternFromString
156#define PyText_InternInPlace PyUnicode_InternInPlace
157#define PyText_Append PyUnicode_Append
158#define PyText_AsString	_PyUnicode_AsString
159
160#endif
161
162#if PY_MAJOR_VERSION == 3
163#define PyInt_FromLong		PyLong_FromLong
164#define PyInt_FromString	PyLong_FromString
165
166extern int PyObject_Cmp (PyObject *o1, PyObject *o2, int *result);
167extern PyObject* PyBytes_InternFromString(const char* v);
168extern PyObject* PyBytes_InternFromStringAndSize(const char* v, Py_ssize_t l);
169#endif
170
171extern void      PyObjC_ClearIntern(void);
172extern PyObject* PyObjC_InternValue(PyObject* orig);
173extern PyObject* PyObjC_IntFromString(char* v, char**pend, int base);
174extern PyObject* PyObjC_IntFromLong(long v);
175
176#endif /* PyObjC_COMPAT_H */
177