]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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 | ||
d14a1e28 RD |
11 | #include "Python.h" |
12 | ||
1de47c7c RD |
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 | ||
8b79f983 | 42 | #if !defined(_MSC_VER) |
1de47c7c RD |
43 | SWIG_STATIC_INLINE PyObject* |
44 | SPyObj_FromLongLong(long long value) | |
45 | { | |
46 | return (value > (long)(LONG_MAX)) ? | |
47 | PyLong_FromLongLong(value) : PyInt_FromLong((long)value); | |
48 | } | |
8b79f983 | 49 | #endif |
1de47c7c RD |
50 | |
51 | SWIG_STATIC_INLINE PyObject* | |
52 | SPyObj_FromUnsignedLong(unsigned long value) | |
53 | { | |
54 | return (value > (unsigned long)(LONG_MAX)) ? | |
55 | PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)value); | |
56 | } | |
57 | ||
8b79f983 | 58 | #if !defined(_MSC_VER) |
1de47c7c RD |
59 | SWIG_STATIC_INLINE PyObject* |
60 | SPyObj_FromUnsignedLongLong(unsigned long long value) | |
61 | { | |
62 | return (value > (unsigned long long)(LONG_MAX)) ? | |
63 | PyLong_FromUnsignedLongLong(value) : PyInt_FromLong((long)value); | |
64 | } | |
8b79f983 | 65 | #endif |
1de47c7c RD |
66 | |
67 | SWIG_STATIC_INLINE long | |
68 | SPyObj_AsLongInRange(PyObject * obj, long min_value, long max_value) | |
69 | { | |
70 | long value = SPyObj_AsLong(obj); | |
71 | if (!PyErr_Occurred()) { | |
72 | if (value < min_value) { | |
73 | PyErr_SetString(PyExc_OverflowError,"value is smaller than type minimum"); | |
74 | } else if (value > max_value) { | |
75 | PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum"); | |
76 | } | |
77 | } | |
78 | return value; | |
79 | } | |
80 | ||
81 | SWIG_STATIC_INLINE unsigned long | |
82 | SPyObj_AsUnsignedLongInRange(PyObject *obj, unsigned long max_value) | |
83 | { | |
84 | unsigned long value = SPyObj_AsUnsignedLong(obj); | |
85 | if (!PyErr_Occurred()) { | |
86 | if (value > max_value) { | |
87 | PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum"); | |
88 | } | |
89 | } | |
90 | return value; | |
91 | } | |
92 | ||
93 | SWIG_STATIC_INLINE signed char | |
94 | SPyObj_AsSignedChar(PyObject *obj) { | |
8b79f983 | 95 | return (signed char)SPyObj_AsLongInRange(obj, SCHAR_MIN, SCHAR_MAX); |
1de47c7c RD |
96 | } |
97 | ||
98 | SWIG_STATIC_INLINE short | |
99 | SPyObj_AsShort(PyObject *obj) { | |
8b79f983 | 100 | return (short)SPyObj_AsLongInRange(obj, SHRT_MIN, SHRT_MAX); |
1de47c7c RD |
101 | } |
102 | ||
103 | SWIG_STATIC_INLINE int | |
104 | SPyObj_AsInt(PyObject *obj) { | |
105 | return SPyObj_AsLongInRange(obj, INT_MIN, INT_MAX); | |
106 | } | |
107 | ||
108 | SWIG_STATIC_INLINE unsigned char | |
109 | SPyObj_AsUnsignedChar(PyObject *obj) { | |
8b79f983 | 110 | return (unsigned char)SPyObj_AsUnsignedLongInRange(obj, UCHAR_MAX); |
1de47c7c RD |
111 | } |
112 | ||
113 | SWIG_STATIC_INLINE unsigned short | |
114 | SPyObj_AsUnsignedShort(PyObject *obj) { | |
8b79f983 | 115 | return (unsigned short)SPyObj_AsUnsignedLongInRange(obj, USHRT_MAX); |
1de47c7c RD |
116 | } |
117 | ||
118 | SWIG_STATIC_INLINE unsigned int | |
119 | SPyObj_AsUnsignedInt(PyObject *obj) { | |
120 | return SPyObj_AsUnsignedLongInRange(obj, UINT_MAX); | |
121 | } | |
122 | ||
8b79f983 | 123 | #if !defined(_MSC_VER) |
1de47c7c RD |
124 | SWIG_STATIC_INLINE long long |
125 | SPyObj_AsLongLong(PyObject *obj) { | |
126 | return PyInt_Check(obj) ? | |
127 | PyInt_AsLong(obj) : PyLong_AsLongLong(obj); | |
128 | } | |
129 | ||
130 | SWIG_STATIC_INLINE unsigned long long | |
131 | SPyObj_AsUnsignedLongLong(PyObject *obj) { | |
132 | return PyLong_Check(obj) ? | |
133 | PyLong_AsUnsignedLongLong(obj) : SPyObj_AsUnsignedLong(obj); | |
134 | } | |
8b79f983 | 135 | #endif |
1de47c7c RD |
136 | |
137 | SWIG_STATIC_INLINE double | |
138 | SPyObj_AsDouble(PyObject *obj) { | |
139 | return (PyFloat_Check(obj)) ? PyFloat_AsDouble(obj) : | |
140 | (double)((PyInt_Check(obj)) ? PyInt_AsLong(obj) : PyLong_AsLongLong(obj)); | |
141 | } | |
142 | ||
143 | SWIG_STATIC_INLINE float | |
144 | SPyObj_AsFloat(PyObject *obj) { | |
145 | double value = SPyObj_AsDouble(obj); | |
146 | if (!PyErr_Occurred()) { | |
147 | if (value < FLT_MIN) { | |
148 | PyErr_SetString(PyExc_OverflowError,"float is smaller than flt_min"); | |
149 | } else if (value > FLT_MAX) { | |
150 | PyErr_SetString(PyExc_OverflowError,"float is greater than flt_max"); | |
151 | } | |
152 | } | |
153 | return (float) value; | |
154 | } | |
155 | ||
156 | SWIG_STATIC_INLINE char | |
157 | SPyObj_AsChar(PyObject *obj) { | |
158 | char c = (PyString_Check(obj) && PyString_Size(obj) == 1) ? | |
159 | PyString_AsString(obj)[0] | |
160 | : (char) SPyObj_AsLongInRange(obj, CHAR_MIN, CHAR_MAX); | |
161 | if (PyErr_Occurred()) { | |
162 | PyErr_Clear(); | |
163 | PyErr_SetString(PyExc_TypeError, "a char is required"); | |
164 | } | |
165 | return c; | |
166 | } | |
167 | ||
168 | SWIG_STATIC_INLINE PyObject * | |
169 | SPyObj_FromChar(char c) { | |
170 | return PyString_FromStringAndSize(&c,1); | |
171 | } | |
172 | ||
173 | SWIG_STATIC_INLINE PyObject * | |
174 | SPyObj_FromCharPtr(const char* cptr) { | |
175 | return cptr ? PyString_FromString(cptr) : Py_BuildValue((char*)""); | |
176 | } | |
177 | ||
178 | SWIG_STATIC_INLINE int | |
179 | SPyObj_AsBool(PyObject *obj) { | |
8b79f983 | 180 | return SPyObj_AsLong/*Long*/(obj) ? 1 : 0; |
1de47c7c RD |
181 | } |
182 | ||
183 | ||
184 | ||
d14a1e28 RD |
185 | #ifdef __cplusplus |
186 | extern "C" { | |
187 | #endif | |
188 | ||
189 | #define SWIG_PY_INT 1 | |
190 | #define SWIG_PY_FLOAT 2 | |
191 | #define SWIG_PY_STRING 3 | |
192 | #define SWIG_PY_POINTER 4 | |
193 | #define SWIG_PY_BINARY 5 | |
194 | ||
195 | /* Flags for pointer conversion */ | |
196 | ||
197 | #define SWIG_POINTER_EXCEPTION 0x1 | |
198 | #define SWIG_POINTER_DISOWN 0x2 | |
199 | ||
200 | /* Exception handling in wrappers */ | |
201 | #define SWIG_fail goto fail | |
202 | ||
203 | /* Constant information structure */ | |
204 | typedef struct swig_const_info { | |
205 | int type; | |
206 | char *name; | |
207 | long lvalue; | |
208 | double dvalue; | |
209 | void *pvalue; | |
210 | swig_type_info **ptype; | |
211 | } swig_const_info; | |
212 | ||
d14a1e28 RD |
213 | /* Common SWIG API */ |
214 | #define SWIG_ConvertPtr(obj, pp, type, flags) \ | |
215 | SWIG_Python_ConvertPtr(obj, pp, type, flags) | |
216 | #define SWIG_NewPointerObj(p, type, flags) \ | |
217 | SWIG_Python_NewPointerObj(p, type, flags) | |
218 | #define SWIG_MustGetPtr(p, type, argnum, flags) \ | |
219 | SWIG_Python_MustGetPtr(p, type, argnum, flags) | |
1de47c7c | 220 | |
d14a1e28 RD |
221 | /* Python-specific SWIG API */ |
222 | #define SWIG_newvarlink() \ | |
223 | SWIG_Python_newvarlink() | |
224 | #define SWIG_addvarlink(p, name, get_attr, set_attr) \ | |
225 | SWIG_Python_addvarlink(p, name, get_attr, set_attr) | |
226 | #define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \ | |
227 | SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags) | |
d14a1e28 RD |
228 | #define SWIG_NewPackedObj(ptr, sz, type) \ |
229 | SWIG_Python_NewPackedObj(ptr, sz, type) | |
230 | #define SWIG_InstallConstants(d, constants) \ | |
231 | SWIG_Python_InstallConstants(d, constants) | |
232 | ||
233 | ||
98fb9b71 RD |
234 | SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int); |
235 | SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own); | |
236 | SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int); | |
237 | SWIGIMPORT(PyObject *) SWIG_Python_newvarlink(void); | |
238 | SWIGIMPORT(void) SWIG_Python_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *)); | |
239 | SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, int sz, swig_type_info *, int); | |
240 | SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, int sz, swig_type_info *); | |
241 | SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]); | |
d14a1e28 | 242 | |
d14a1e28 RD |
243 | |
244 | ||
245 | /* Contract support */ | |
246 | ||
11188b02 | 247 | #define SWIG_contract_assert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg ); goto fail; } else |
d14a1e28 | 248 | |
d14a1e28 RD |
249 | #ifdef __cplusplus |
250 | } | |
251 | #endif | |
252 |