Cython has moved to github.
pyrex
view Tests/5/Reference/starargs.c @ 86:da6e97bb7e6d
Multiple compilation fixed
| author | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| date | Sat May 24 15:50:12 2008 +1200 (4 years ago) |
| parents | 6c5f5271ebab |
| children | 3b20cb4923eb |
line source
1 /* Generated by Pyrex */
3 #define PY_SSIZE_T_CLEAN
4 #include "Python.h"
5 #include "structmember.h"
6 #ifndef PY_LONG_LONG
7 #define PY_LONG_LONG LONG_LONG
8 #endif
9 #if PY_VERSION_HEX < 0x02050000
10 typedef int Py_ssize_t;
11 #define PY_SSIZE_T_MAX INT_MAX
12 #define PY_SSIZE_T_MIN INT_MIN
13 #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
14 #define PyInt_AsSsize_t(o) PyInt_AsLong(o)
15 #endif
16 #ifndef WIN32
17 #ifndef __stdcall
18 #define __stdcall
19 #endif
20 #ifndef __cdecl
21 #define __cdecl
22 #endif
23 #endif
24 #ifdef __cplusplus
25 #define __PYX_EXTERN_C extern "C"
26 #else
27 #define __PYX_EXTERN_C extern
28 #endif
29 #include <math.h>
32 typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
33 typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
35 static PyObject *__pyx_m;
36 static PyObject *__pyx_b;
37 static int __pyx_lineno;
38 static char *__pyx_filename;
39 static char **__pyx_f;
41 static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], Py_ssize_t nargs, PyObject **args2, PyObject **kwds2, char rqd_kwds[]); /*proto*/
43 static void __Pyx_AddTraceback(char *funcname); /*proto*/
45 /* Declarations from starargs */
49 static __Pyx_StringTabEntry __pyx_string_tab[] = {
50 {0, 0, 0, 0}
51 };
53 /* Implementation of starargs */
55 static PyObject *__pyx_f_8starargs_spam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
56 static PyObject *__pyx_f_8starargs_spam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
57 PyObject *__pyx_v_x = 0;
58 PyObject *__pyx_v_y = 0;
59 PyObject *__pyx_v_z = 0;
60 PyObject *__pyx_r;
61 static char *__pyx_argnames[] = {"x","y","z",0};
62 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) return 0;
63 Py_INCREF(__pyx_v_x);
64 Py_INCREF(__pyx_v_y);
65 Py_INCREF(__pyx_v_z);
67 __pyx_r = Py_None; Py_INCREF(Py_None);
68 Py_DECREF(__pyx_v_x);
69 Py_DECREF(__pyx_v_y);
70 Py_DECREF(__pyx_v_z);
71 return __pyx_r;
72 }
74 static PyObject *__pyx_f_8starargs_grail(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
75 static PyObject *__pyx_f_8starargs_grail(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
76 PyObject *__pyx_v_x = 0;
77 PyObject *__pyx_v_y = 0;
78 PyObject *__pyx_v_z = 0;
79 PyObject *__pyx_v_a = 0;
80 PyObject *__pyx_r;
81 static char *__pyx_argnames[] = {"x","y","z",0};
82 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, &__pyx_v_a, 0, 0) < 0) return 0;
83 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
84 Py_XDECREF(__pyx_args);
85 Py_XDECREF(__pyx_kwds);
86 Py_XDECREF(__pyx_v_a);
87 return 0;
88 }
89 Py_INCREF(__pyx_v_x);
90 Py_INCREF(__pyx_v_y);
91 Py_INCREF(__pyx_v_z);
93 __pyx_r = Py_None; Py_INCREF(Py_None);
94 Py_XDECREF(__pyx_v_a);
95 Py_DECREF(__pyx_v_x);
96 Py_DECREF(__pyx_v_y);
97 Py_DECREF(__pyx_v_z);
98 Py_XDECREF(__pyx_args);
99 Py_XDECREF(__pyx_kwds);
100 return __pyx_r;
101 }
103 static PyObject *__pyx_f_8starargs_swallow(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
104 static PyObject *__pyx_f_8starargs_swallow(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
105 PyObject *__pyx_v_x = 0;
106 PyObject *__pyx_v_y = 0;
107 PyObject *__pyx_v_z = 0;
108 PyObject *__pyx_v_k = 0;
109 PyObject *__pyx_r;
110 static char *__pyx_argnames[] = {"x","y","z",0};
111 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, 0, &__pyx_v_k, 0) < 0) return 0;
112 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
113 Py_XDECREF(__pyx_args);
114 Py_XDECREF(__pyx_kwds);
115 Py_XDECREF(__pyx_v_k);
116 return 0;
117 }
118 Py_INCREF(__pyx_v_x);
119 Py_INCREF(__pyx_v_y);
120 Py_INCREF(__pyx_v_z);
122 __pyx_r = Py_None; Py_INCREF(Py_None);
123 Py_XDECREF(__pyx_v_k);
124 Py_DECREF(__pyx_v_x);
125 Py_DECREF(__pyx_v_y);
126 Py_DECREF(__pyx_v_z);
127 Py_XDECREF(__pyx_args);
128 Py_XDECREF(__pyx_kwds);
129 return __pyx_r;
130 }
132 static PyObject *__pyx_f_8starargs_creosote(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
133 static PyObject *__pyx_f_8starargs_creosote(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
134 PyObject *__pyx_v_x = 0;
135 PyObject *__pyx_v_y = 0;
136 PyObject *__pyx_v_z = 0;
137 PyObject *__pyx_v_a = 0;
138 PyObject *__pyx_v_k = 0;
139 PyObject *__pyx_r;
140 static char *__pyx_argnames[] = {"x","y","z",0};
141 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, &__pyx_v_a, &__pyx_v_k, 0) < 0) return 0;
142 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
143 Py_XDECREF(__pyx_args);
144 Py_XDECREF(__pyx_kwds);
145 Py_XDECREF(__pyx_v_a);
146 Py_XDECREF(__pyx_v_k);
147 return 0;
148 }
149 Py_INCREF(__pyx_v_x);
150 Py_INCREF(__pyx_v_y);
151 Py_INCREF(__pyx_v_z);
153 __pyx_r = Py_None; Py_INCREF(Py_None);
154 Py_XDECREF(__pyx_v_a);
155 Py_XDECREF(__pyx_v_k);
156 Py_DECREF(__pyx_v_x);
157 Py_DECREF(__pyx_v_y);
158 Py_DECREF(__pyx_v_z);
159 Py_XDECREF(__pyx_args);
160 Py_XDECREF(__pyx_kwds);
161 return __pyx_r;
162 }
164 static struct PyMethodDef __pyx_methods[] = {
165 {"spam", (PyCFunction)__pyx_f_8starargs_spam, METH_VARARGS|METH_KEYWORDS, 0},
166 {"grail", (PyCFunction)__pyx_f_8starargs_grail, METH_VARARGS|METH_KEYWORDS, 0},
167 {"swallow", (PyCFunction)__pyx_f_8starargs_swallow, METH_VARARGS|METH_KEYWORDS, 0},
168 {"creosote", (PyCFunction)__pyx_f_8starargs_creosote, METH_VARARGS|METH_KEYWORDS, 0},
169 {0, 0, 0, 0}
170 };
172 static void __pyx_init_filenames(void); /*proto*/
174 PyMODINIT_FUNC initstarargs(void); /*proto*/
175 PyMODINIT_FUNC initstarargs(void) {
176 __pyx_init_filenames();
177 __pyx_m = Py_InitModule4("starargs", __pyx_methods, 0, 0, PYTHON_API_VERSION);
178 if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
179 Py_INCREF(__pyx_m);
180 __pyx_b = PyImport_AddModule("__builtin__");
181 if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
182 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
183 if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
185 /* "/Local/Projects/D/Pyrex/Source/Tests/5/starargs.pyx":10 */
186 return;
187 __pyx_L1:;
188 __Pyx_AddTraceback("starargs");
189 }
191 static char *__pyx_filenames[] = {
192 "starargs.pyx",
193 };
195 /* Runtime support code */
197 static void __pyx_init_filenames(void) {
198 __pyx_f = __pyx_filenames;
199 }
201 static int __Pyx_GetStarArgs(
202 PyObject **args,
203 PyObject **kwds,
204 char *kwd_list[],
205 Py_ssize_t nargs,
206 PyObject **args2,
207 PyObject **kwds2,
208 char rqd_kwds[])
209 {
210 PyObject *x = 0, *args1 = 0, *kwds1 = 0;
211 int i;
212 char **p;
214 if (args2)
215 *args2 = 0;
216 if (kwds2)
217 *kwds2 = 0;
219 if (args2) {
220 args1 = PyTuple_GetSlice(*args, 0, nargs);
221 if (!args1)
222 goto bad;
223 *args2 = PyTuple_GetSlice(*args, nargs, PyTuple_GET_SIZE(*args));
224 if (!*args2)
225 goto bad;
226 }
227 else if (PyTuple_GET_SIZE(*args) > nargs) {
228 int m = nargs;
229 int n = PyTuple_GET_SIZE(*args);
230 PyErr_Format(PyExc_TypeError,
231 "function takes at most %d positional arguments (%d given)",
232 m, n);
233 goto bad;
234 }
235 else {
236 args1 = *args;
237 Py_INCREF(args1);
238 }
240 if (rqd_kwds && !*kwds)
241 for (i = 0, p = kwd_list; *p; i++, p++)
242 if (rqd_kwds[i])
243 goto missing_kwarg;
245 if (kwds2) {
246 if (*kwds) {
247 kwds1 = PyDict_New();
248 if (!kwds1)
249 goto bad;
250 *kwds2 = PyDict_Copy(*kwds);
251 if (!*kwds2)
252 goto bad;
253 for (i = 0, p = kwd_list; *p; i++, p++) {
254 x = PyDict_GetItemString(*kwds, *p);
255 if (x) {
256 if (PyDict_SetItemString(kwds1, *p, x) < 0)
257 goto bad;
258 if (PyDict_DelItemString(*kwds2, *p) < 0)
259 goto bad;
260 }
261 else if (rqd_kwds && rqd_kwds[i])
262 goto missing_kwarg;
263 }
264 }
265 else {
266 *kwds2 = PyDict_New();
267 if (!*kwds2)
268 goto bad;
269 }
270 }
271 else {
272 kwds1 = *kwds;
273 Py_XINCREF(kwds1);
274 if (rqd_kwds && *kwds)
275 for (i = 0, p = kwd_list; *p; i++, p++)
276 if (rqd_kwds[i] && !PyDict_GetItemString(*kwds, *p))
277 goto missing_kwarg;
278 }
280 *args = args1;
281 *kwds = kwds1;
282 return 0;
283 missing_kwarg:
284 PyErr_Format(PyExc_TypeError,
285 "required keyword argument '%s' is missing", *p);
286 bad:
287 Py_XDECREF(args1);
288 Py_XDECREF(kwds1);
289 if (args2) {
290 Py_XDECREF(*args2);
291 }
292 if (kwds2) {
293 Py_XDECREF(*kwds2);
294 }
295 return -1;
296 }
298 #include "compile.h"
299 #include "frameobject.h"
300 #include "traceback.h"
302 static void __Pyx_AddTraceback(char *funcname) {
303 PyObject *py_srcfile = 0;
304 PyObject *py_funcname = 0;
305 PyObject *py_globals = 0;
306 PyObject *empty_tuple = 0;
307 PyObject *empty_string = 0;
308 PyCodeObject *py_code = 0;
309 PyFrameObject *py_frame = 0;
311 py_srcfile = PyString_FromString(__pyx_filename);
312 if (!py_srcfile) goto bad;
313 py_funcname = PyString_FromString(funcname);
314 if (!py_funcname) goto bad;
315 py_globals = PyModule_GetDict(__pyx_m);
316 if (!py_globals) goto bad;
317 empty_tuple = PyTuple_New(0);
318 if (!empty_tuple) goto bad;
319 empty_string = PyString_FromString("");
320 if (!empty_string) goto bad;
321 py_code = PyCode_New(
322 0, /*int argcount,*/
323 0, /*int nlocals,*/
324 0, /*int stacksize,*/
325 0, /*int flags,*/
326 empty_string, /*PyObject *code,*/
327 empty_tuple, /*PyObject *consts,*/
328 empty_tuple, /*PyObject *names,*/
329 empty_tuple, /*PyObject *varnames,*/
330 empty_tuple, /*PyObject *freevars,*/
331 empty_tuple, /*PyObject *cellvars,*/
332 py_srcfile, /*PyObject *filename,*/
333 py_funcname, /*PyObject *name,*/
334 __pyx_lineno, /*int firstlineno,*/
335 empty_string /*PyObject *lnotab*/
336 );
337 if (!py_code) goto bad;
338 py_frame = PyFrame_New(
339 PyThreadState_Get(), /*PyThreadState *tstate,*/
340 py_code, /*PyCodeObject *code,*/
341 py_globals, /*PyObject *globals,*/
342 0 /*PyObject *locals*/
343 );
344 if (!py_frame) goto bad;
345 py_frame->f_lineno = __pyx_lineno;
346 PyTraceBack_Here(py_frame);
347 bad:
348 Py_XDECREF(py_srcfile);
349 Py_XDECREF(py_funcname);
350 Py_XDECREF(empty_tuple);
351 Py_XDECREF(empty_string);
352 Py_XDECREF(py_code);
353 Py_XDECREF(py_frame);
354 }
