1#ifndef PyObjC_H
2#define PyObjC_H
3
4/*
5 * Central include file for PyObjC.
6 */
7
8#define OBJC_VERSION "2.5.1"
9
10// Loading in AppKit on Mac OS X 10.3 results in
11// a bit less than 1500 classes.
12#define PYOBJC_EXPECTED_CLASS_COUNT 3000
13#define PY_SSIZE_T_CLEAN
14
15#include <Python.h>
16#include "structmember.h"
17#include "pyobjc-compat.h"
18
19#ifdef __clang__
20
21/* This is a crude hack to disable a otherwise useful warning in the context of
22 * PyTuple_SET_ITEM, without disabling it everywhere
23 */
24#pragma clang diagnostic push
25#pragma clang diagnostic ignored "-Warray-bounds"
26static inline void _PyObjCTuple_SetItem(PyObject* tuple, Py_ssize_t idx, PyObject* value)
27{
28	PyTuple_SET_ITEM(tuple, idx, value);
29}
30#undef PyTuple_SET_ITEM
31#define PyTuple_SET_ITEM(a, b, c) _PyObjCTuple_SetItem(a, b, c)
32
33static inline PyObject* _PyObjCTuple_GetItem(PyObject* tuple, Py_ssize_t idx)
34{
35	return PyTuple_GET_ITEM(tuple, idx);
36}
37#undef PyTuple_GET_ITEM
38#define PyTuple_GET_ITEM(a, b) _PyObjCTuple_GetItem(a, b)
39
40#pragma clang diagnostic pop
41
42#endif /* __clang__ */
43
44
45/* PyObjC_DEBUG: If defined the bridge will perform more internal checks */
46#ifdef Py_DEBUG
47   /* Enable when Python is compiled with internal checks enabled */
48#  define PyObjC_DEBUG
49#endif
50
51/* PyObjC_ERROR_ABORT: If defined an internal error will result in an abort() */
52#define	PyObjC_ERROR_ABORT 1
53
54
55#include <objc/objc-runtime.h>
56#include <objc/objc.h>
57
58/* Define PyObjC_UNICODE_FAST_PATH when
59 * 1) We're before Python 3.3, and
60 * 2) Py_UNICODE has the same size as unichar
61 *
62 * Python 3.3 has an optimized representation that
63 * makes it impossible to use the "fast path"
64 */
65#if PY_VERSION_HEX >= 0x03030000
66#undef PyObjC_UNICODE_FAST_PATH
67#elif Py_UNICODE_SIZE == 2
68#define PyObjC_UNICODE_FAST_PATH
69#endif
70
71/*
72 * XXX: disable the fast path for
73 * unicode strings due to unexplained
74 * test failures.
75 */
76#if 0
77#ifdef PyObjC_UNICODE_FAST_PATH
78#undef PyObjC_UNICODE_FAST_PATH
79#endif
80#endif
81
82#include "objc-runtime-compat.h"
83#include "proxy-registry.h"
84#include "objc_support.h"
85#include "pointer-support.h"
86#include "OC_PythonObject.h"
87#include "OC_PythonArray.h"
88#include "OC_PythonData.h"
89#include "OC_PythonDictionary.h"
90#include "OC_PythonUnicode.h"
91
92#if PY_MAJOR_VERSION == 2
93#include "OC_PythonString.h"
94#endif
95
96#include "OC_PythonEnumerator.h"
97#include "OC_PythonDate.h"
98#include "OC_PythonNumber.h"
99#include "OC_PythonSet.h"
100#include "method-signature.h"
101#include "objc_util.h"
102#include "objc-class.h"
103#include "objc-object.h"
104#include "selector.h"
105#include "libffi_support.h"
106#include "super-call.h"
107#include "instance-var.h"
108#include "class-builder.h"
109#include "ObjCPointer.h"
110#include "informal-protocol.h"
111#include "formal-protocol.h"
112#include "alloc_hack.h"
113#include "unicode-object.h"
114#include "class-descriptor.h"
115#include "class-list.h"
116#include "struct-wrapper.h"
117#include "method-imp.h"
118#include "bundle-variables.h"
119#include "function.h"
120#include "varlist.h"
121#include "objc_super.h"
122#include "fsref.h"
123#include "fsspec.h"
124
125
126/*
127 * XXX: All definitions below here should be moved to different/new
128 * headers
129 */
130
131/* On MacOS X, +signatureWithObjCTypes: is a method of NSMethodSignature,
132 * but that method is not present in the header files. We add the definition
133 * here to avoid warnings.
134 *
135 * XXX: We use an undocumented API, but we also don't have much choice: we
136 * must create the things and this is the only way to do it...
137 */
138@interface NSMethodSignature (WarningKiller)
139	+(instancetype)signatureWithObjCTypes:(const char*)types;
140@end /* interface NSMethodSignature */
141
142
143extern BOOL PyObjC_useKVO;
144extern BOOL PyObjC_nativeProperties;
145extern int PyObjC_VerboseLevel;
146extern int PyObjC_HideProtected;
147#if PY_MAJOR_VERSION == 2
148extern int PyObjC_StrBridgeEnabled;
149#endif
150extern PyObject *PyObjCStrBridgeWarning;
151extern PyObject *PyObjC_NSNumberWrapper;
152
153
154int PyObjCAPI_Register(PyObject* module);
155#define PYOBJC_BUILD
156#include "pyobjc-api.h"
157#include "registry.h"
158#include "corefoundation.h"
159#include "closure_pool.h"
160#include "block_support.h"
161
162extern PyObject* PyObjCMethodAccessor_New(PyObject* base, int class_method);
163
164/* Needed by method-accessor, name will be changed soon */
165extern PyTypeObject PyObjCMethodAccessor_Type;
166char* PyObjC_SELToPythonName(SEL, char*, size_t);
167
168
169/* toll-free-bridging.m */
170id PyObjC_CFTypeToID(PyObject* argument);
171PyObject* PyObjC_IDToCFType(id argument);
172
173/* opaque-pointer.m */
174PyObject* PyObjCCreateOpaquePointerType(const char* name,
175		const char* typestr, const char* docstr);
176
177/* objc-NULL.m */
178extern PyObject* PyObjC_NULL;
179extern PyObject* PyObjCInitNULL(void);
180
181/* socketsupport.m */
182int PyObjC_SockAddrFromPython(PyObject*, void*);
183PyObject* PyObjC_SockAddrToPython(void*);
184
185/* module.m */
186extern PyObject* PyObjC_TypeStr2CFTypeID;
187extern PyObject* PyObjC_AdjustSelf(PyObject* self);
188
189
190
191
192#ifdef PyObjC_DEBUG
193
194#ifdef PyObjCErr_InternalError
195#define _PyObjC_InternalError_Bailout()	abort()
196#else
197#define _PyObjC_InternalError_Bailout()	((void)0)
198#endif
199
200#define PyObjCErr_InternalError() \
201    do { \
202	PyErr_Format(PyObjCExc_InternalError, \
203	   "PyObjC: internal error in %s at %s:%d", \
204	   __FUNCTION__, __FILE__, __LINE__); \
205	   _PyObjC_InternalError_Bailout(); \
206    } while (0)
207
208#define PyObjCErr_InternalErrorMesg(msg) \
209    do { \
210	PyErr_Format(PyObjCExc_InternalError, \
211	  "PyObjC: internal error in %s at %s:%d: %s", \
212	   __FUNCTION__, __FILE__, __LINE__, msg); \
213	   _PyObjC_InternalError_Bailout(); \
214    } while (0)
215
216#define PyObjC_Assert(expr, retval) \
217	do { \
218	if (!(expr)) { PyObjCErr_InternalErrorMesg(\
219			"assertion failed: " #expr); return (retval); } \
220	} while (0)
221#else
222
223#define PyObjCErr_InternalError()	((void)0)
224#define PyObjCErr_InternalErrorMesg(mesg)	((void)0)
225
226#define PyObjC_Assert(expr, retval)	((void)0)
227
228#endif
229
230#endif /* PyObjC_H */
231