]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pyrun.swg
Updated SWIG patches and wxPython's SWIG runtime
[wxWidgets.git] / wxPython / src / pyrun.swg
1 /***********************************************************************
2 * pyrun.swg for wxPython
3 *
4 * Include only the function prototypes and such from SWIG's pyrun.swg,
5 * but not the runtime functions themselves. This helps keep the
6 * wrapper files clean of unnecessary stuff that is in the libpy.c file
7 * anyway.
8 *
9 ************************************************************************/
10
11 #include "Python.h"
12
13 #include <limits.h>
14 #include <float.h>
15
16 #ifdef __cplusplus
17 #define SWIG_STATIC_INLINE static inline
18 #else
19 #define SWIG_STATIC_INLINE static
20 #endif
21
22 SWIG_STATIC_INLINE long
23 SPyObj_AsLong(PyObject * obj)
24 {
25 return PyInt_Check(obj) ? PyInt_AsLong(obj) : PyLong_AsLong(obj);
26 }
27
28 SWIG_STATIC_INLINE unsigned long
29 SPyObj_AsUnsignedLong(PyObject * obj)
30 {
31 if (PyLong_Check(obj)) {
32 return PyLong_AsUnsignedLong(obj);
33 } else {
34 long i = PyInt_AsLong(obj);
35 if ( !PyErr_Occurred() && (i < 0)) {
36 PyErr_SetString(PyExc_TypeError, "negative value for unsigned type");
37 }
38 return i;
39 }
40 }
41
42 SWIG_STATIC_INLINE PyObject*
43 SPyObj_FromLongLong(long long value)
44 {
45 return (value > (long)(LONG_MAX)) ?
46 PyLong_FromLongLong(value) : PyInt_FromLong((long)value);
47 }
48
49 SWIG_STATIC_INLINE PyObject*
50 SPyObj_FromUnsignedLong(unsigned long value)
51 {
52 return (value > (unsigned long)(LONG_MAX)) ?
53 PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)value);
54 }
55
56 SWIG_STATIC_INLINE PyObject*
57 SPyObj_FromUnsignedLongLong(unsigned long long value)
58 {
59 return (value > (unsigned long long)(LONG_MAX)) ?
60 PyLong_FromUnsignedLongLong(value) : PyInt_FromLong((long)value);
61 }
62
63 SWIG_STATIC_INLINE long
64 SPyObj_AsLongInRange(PyObject * obj, long min_value, long max_value)
65 {
66 long value = SPyObj_AsLong(obj);
67 if (!PyErr_Occurred()) {
68 if (value < min_value) {
69 PyErr_SetString(PyExc_OverflowError,"value is smaller than type minimum");
70 } else if (value > max_value) {
71 PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum");
72 }
73 }
74 return value;
75 }
76
77 SWIG_STATIC_INLINE unsigned long
78 SPyObj_AsUnsignedLongInRange(PyObject *obj, unsigned long max_value)
79 {
80 unsigned long value = SPyObj_AsUnsignedLong(obj);
81 if (!PyErr_Occurred()) {
82 if (value > max_value) {
83 PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum");
84 }
85 }
86 return value;
87 }
88
89 SWIG_STATIC_INLINE signed char
90 SPyObj_AsSignedChar(PyObject *obj) {
91 return SPyObj_AsLongInRange(obj, SCHAR_MIN, SCHAR_MAX);
92 }
93
94 SWIG_STATIC_INLINE short
95 SPyObj_AsShort(PyObject *obj) {
96 return SPyObj_AsLongInRange(obj, SHRT_MIN, SHRT_MAX);
97 }
98
99 SWIG_STATIC_INLINE int
100 SPyObj_AsInt(PyObject *obj) {
101 return SPyObj_AsLongInRange(obj, INT_MIN, INT_MAX);
102 }
103
104 SWIG_STATIC_INLINE unsigned char
105 SPyObj_AsUnsignedChar(PyObject *obj) {
106 return SPyObj_AsUnsignedLongInRange(obj, UCHAR_MAX);
107 }
108
109 SWIG_STATIC_INLINE unsigned short
110 SPyObj_AsUnsignedShort(PyObject *obj) {
111 return SPyObj_AsUnsignedLongInRange(obj, USHRT_MAX);
112 }
113
114 SWIG_STATIC_INLINE unsigned int
115 SPyObj_AsUnsignedInt(PyObject *obj) {
116 return SPyObj_AsUnsignedLongInRange(obj, UINT_MAX);
117 }
118
119 SWIG_STATIC_INLINE long long
120 SPyObj_AsLongLong(PyObject *obj) {
121 return PyInt_Check(obj) ?
122 PyInt_AsLong(obj) : PyLong_AsLongLong(obj);
123 }
124
125 SWIG_STATIC_INLINE unsigned long long
126 SPyObj_AsUnsignedLongLong(PyObject *obj) {
127 return PyLong_Check(obj) ?
128 PyLong_AsUnsignedLongLong(obj) : SPyObj_AsUnsignedLong(obj);
129 }
130
131 SWIG_STATIC_INLINE double
132 SPyObj_AsDouble(PyObject *obj) {
133 return (PyFloat_Check(obj)) ? PyFloat_AsDouble(obj) :
134 (double)((PyInt_Check(obj)) ? PyInt_AsLong(obj) : PyLong_AsLongLong(obj));
135 }
136
137 SWIG_STATIC_INLINE float
138 SPyObj_AsFloat(PyObject *obj) {
139 double value = SPyObj_AsDouble(obj);
140 if (!PyErr_Occurred()) {
141 if (value < FLT_MIN) {
142 PyErr_SetString(PyExc_OverflowError,"float is smaller than flt_min");
143 } else if (value > FLT_MAX) {
144 PyErr_SetString(PyExc_OverflowError,"float is greater than flt_max");
145 }
146 }
147 return (float) value;
148 }
149
150 SWIG_STATIC_INLINE char
151 SPyObj_AsChar(PyObject *obj) {
152 char c = (PyString_Check(obj) && PyString_Size(obj) == 1) ?
153 PyString_AsString(obj)[0]
154 : (char) SPyObj_AsLongInRange(obj, CHAR_MIN, CHAR_MAX);
155 if (PyErr_Occurred()) {
156 PyErr_Clear();
157 PyErr_SetString(PyExc_TypeError, "a char is required");
158 }
159 return c;
160 }
161
162 SWIG_STATIC_INLINE PyObject *
163 SPyObj_FromChar(char c) {
164 return PyString_FromStringAndSize(&c,1);
165 }
166
167 SWIG_STATIC_INLINE PyObject *
168 SPyObj_FromCharPtr(const char* cptr) {
169 return cptr ? PyString_FromString(cptr) : Py_BuildValue((char*)"");
170 }
171
172 SWIG_STATIC_INLINE int
173 SPyObj_AsBool(PyObject *obj) {
174 return SPyObj_AsLongLong(obj) ? 1 : 0;
175 }
176
177
178
179 #ifdef __cplusplus
180 extern "C" {
181 #endif
182
183 #define SWIG_PY_INT 1
184 #define SWIG_PY_FLOAT 2
185 #define SWIG_PY_STRING 3
186 #define SWIG_PY_POINTER 4
187 #define SWIG_PY_BINARY 5
188
189 /* Flags for pointer conversion */
190
191 #define SWIG_POINTER_EXCEPTION 0x1
192 #define SWIG_POINTER_DISOWN 0x2
193
194 /* Exception handling in wrappers */
195 #define SWIG_fail goto fail
196
197 /* Constant information structure */
198 typedef struct swig_const_info {
199 int type;
200 char *name;
201 long lvalue;
202 double dvalue;
203 void *pvalue;
204 swig_type_info **ptype;
205 } swig_const_info;
206
207 /* Common SWIG API */
208 #define SWIG_ConvertPtr(obj, pp, type, flags) \
209 SWIG_Python_ConvertPtr(obj, pp, type, flags)
210 #define SWIG_NewPointerObj(p, type, flags) \
211 SWIG_Python_NewPointerObj(p, type, flags)
212 #define SWIG_MustGetPtr(p, type, argnum, flags) \
213 SWIG_Python_MustGetPtr(p, type, argnum, flags)
214
215 /* Python-specific SWIG API */
216 #define SWIG_newvarlink() \
217 SWIG_Python_newvarlink()
218 #define SWIG_addvarlink(p, name, get_attr, set_attr) \
219 SWIG_Python_addvarlink(p, name, get_attr, set_attr)
220 #define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \
221 SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
222 #define SWIG_NewPackedObj(ptr, sz, type) \
223 SWIG_Python_NewPackedObj(ptr, sz, type)
224 #define SWIG_InstallConstants(d, constants) \
225 SWIG_Python_InstallConstants(d, constants)
226
227
228 SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);
229 SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);
230 SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);
231 SWIGIMPORT(PyObject *) SWIG_Python_newvarlink(void);
232 SWIGIMPORT(void) SWIG_Python_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
233 SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, int sz, swig_type_info *, int);
234 SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, int sz, swig_type_info *);
235 SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]);
236
237
238
239 /* Contract support */
240
241 #define SWIG_contract_assert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg ); goto fail; } else
242
243 #ifdef __cplusplus
244 }
245 #endif
246