Cython has moved to github.

pyrex

view Tests/5/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 12072e0e4fd5
children 94d46b3c5354
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; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
34 static PyObject *__pyx_m;
35 static PyObject *__pyx_b;
36 static int __pyx_lineno;
37 static char *__pyx_filename;
38 static char **__pyx_f;
40 static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], Py_ssize_t nargs, PyObject **args2, PyObject **kwds2, char rqd_kwds[]); /*proto*/
42 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
44 static void __Pyx_AddTraceback(char *funcname); /*proto*/
46 /* Declarations from starargs */
49 /* Declarations from implementation of starargs */
55 static __Pyx_StringTabEntry __pyx_string_tab[] = {
56 {0, 0, 0, 0}
57 };
61 /* Implementation of starargs */
63 static PyObject *__pyx_f_8starargs_spam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
64 static PyObject *__pyx_f_8starargs_spam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
65 PyObject *__pyx_v_x = 0;
66 PyObject *__pyx_v_y = 0;
67 PyObject *__pyx_v_z = 0;
68 PyObject *__pyx_r;
69 static char *__pyx_argnames[] = {"x","y","z",0};
70 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) return 0;
71 Py_INCREF(__pyx_v_x);
72 Py_INCREF(__pyx_v_y);
73 Py_INCREF(__pyx_v_z);
75 __pyx_r = Py_None; Py_INCREF(Py_None);
76 Py_DECREF(__pyx_v_x);
77 Py_DECREF(__pyx_v_y);
78 Py_DECREF(__pyx_v_z);
79 return __pyx_r;
80 }
82 static PyObject *__pyx_f_8starargs_grail(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
83 static PyObject *__pyx_f_8starargs_grail(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
84 PyObject *__pyx_v_x = 0;
85 PyObject *__pyx_v_y = 0;
86 PyObject *__pyx_v_z = 0;
87 PyObject *__pyx_v_a = 0;
88 PyObject *__pyx_r;
89 static char *__pyx_argnames[] = {"x","y","z",0};
90 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, &__pyx_v_a, 0, 0) < 0) return 0;
91 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
92 Py_XDECREF(__pyx_args);
93 Py_XDECREF(__pyx_kwds);
94 Py_XDECREF(__pyx_v_a);
95 return 0;
96 }
97 Py_INCREF(__pyx_v_x);
98 Py_INCREF(__pyx_v_y);
99 Py_INCREF(__pyx_v_z);
101 __pyx_r = Py_None; Py_INCREF(Py_None);
102 Py_XDECREF(__pyx_v_a);
103 Py_DECREF(__pyx_v_x);
104 Py_DECREF(__pyx_v_y);
105 Py_DECREF(__pyx_v_z);
106 Py_XDECREF(__pyx_args);
107 Py_XDECREF(__pyx_kwds);
108 return __pyx_r;
109 }
111 static PyObject *__pyx_f_8starargs_swallow(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
112 static PyObject *__pyx_f_8starargs_swallow(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
113 PyObject *__pyx_v_x = 0;
114 PyObject *__pyx_v_y = 0;
115 PyObject *__pyx_v_z = 0;
116 PyObject *__pyx_v_k = 0;
117 PyObject *__pyx_r;
118 static char *__pyx_argnames[] = {"x","y","z",0};
119 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, 0, &__pyx_v_k, 0) < 0) return 0;
120 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
121 Py_XDECREF(__pyx_args);
122 Py_XDECREF(__pyx_kwds);
123 Py_XDECREF(__pyx_v_k);
124 return 0;
125 }
126 Py_INCREF(__pyx_v_x);
127 Py_INCREF(__pyx_v_y);
128 Py_INCREF(__pyx_v_z);
130 __pyx_r = Py_None; Py_INCREF(Py_None);
131 Py_XDECREF(__pyx_v_k);
132 Py_DECREF(__pyx_v_x);
133 Py_DECREF(__pyx_v_y);
134 Py_DECREF(__pyx_v_z);
135 Py_XDECREF(__pyx_args);
136 Py_XDECREF(__pyx_kwds);
137 return __pyx_r;
138 }
140 static PyObject *__pyx_f_8starargs_creosote(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
141 static PyObject *__pyx_f_8starargs_creosote(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
142 PyObject *__pyx_v_x = 0;
143 PyObject *__pyx_v_y = 0;
144 PyObject *__pyx_v_z = 0;
145 PyObject *__pyx_v_a = 0;
146 PyObject *__pyx_v_k = 0;
147 PyObject *__pyx_r;
148 static char *__pyx_argnames[] = {"x","y","z",0};
149 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, &__pyx_v_a, &__pyx_v_k, 0) < 0) return 0;
150 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_z)) {
151 Py_XDECREF(__pyx_args);
152 Py_XDECREF(__pyx_kwds);
153 Py_XDECREF(__pyx_v_a);
154 Py_XDECREF(__pyx_v_k);
155 return 0;
156 }
157 Py_INCREF(__pyx_v_x);
158 Py_INCREF(__pyx_v_y);
159 Py_INCREF(__pyx_v_z);
161 __pyx_r = Py_None; Py_INCREF(Py_None);
162 Py_XDECREF(__pyx_v_a);
163 Py_XDECREF(__pyx_v_k);
164 Py_DECREF(__pyx_v_x);
165 Py_DECREF(__pyx_v_y);
166 Py_DECREF(__pyx_v_z);
167 Py_XDECREF(__pyx_args);
168 Py_XDECREF(__pyx_kwds);
169 return __pyx_r;
170 }
172 static struct PyMethodDef __pyx_methods[] = {
173 {"spam", (PyCFunction)__pyx_f_8starargs_spam, METH_VARARGS|METH_KEYWORDS, 0},
174 {"grail", (PyCFunction)__pyx_f_8starargs_grail, METH_VARARGS|METH_KEYWORDS, 0},
175 {"swallow", (PyCFunction)__pyx_f_8starargs_swallow, METH_VARARGS|METH_KEYWORDS, 0},
176 {"creosote", (PyCFunction)__pyx_f_8starargs_creosote, METH_VARARGS|METH_KEYWORDS, 0},
177 {0, 0, 0, 0}
178 };
180 static void __pyx_init_filenames(void); /*proto*/
182 PyMODINIT_FUNC initstarargs(void); /*proto*/
183 PyMODINIT_FUNC initstarargs(void) {
184 __pyx_init_filenames();
185 __pyx_m = Py_InitModule4("starargs", __pyx_methods, 0, 0, PYTHON_API_VERSION);
186 if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
187 Py_INCREF(__pyx_m);
188 __pyx_b = PyImport_AddModule("__builtin__");
189 if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
190 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
191 if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
193 /* "/Local/Projects/D/Pyrex/Source/Tests/5/starargs.pyx":10 */
194 return;
195 __pyx_L1:;
196 __Pyx_AddTraceback("starargs");
197 }
199 static char *__pyx_filenames[] = {
200 "starargs.pyx",
201 };
203 /* Runtime support code */
205 static void __pyx_init_filenames(void) {
206 __pyx_f = __pyx_filenames;
207 }
209 static int __Pyx_GetStarArgs(
210 PyObject **args,
211 PyObject **kwds,
212 char *kwd_list[],
213 Py_ssize_t nargs,
214 PyObject **args2,
215 PyObject **kwds2,
216 char rqd_kwds[])
217 {
218 PyObject *x = 0, *args1 = 0, *kwds1 = 0;
219 int i;
220 char **p;
222 if (args2)
223 *args2 = 0;
224 if (kwds2)
225 *kwds2 = 0;
227 if (args2) {
228 args1 = PyTuple_GetSlice(*args, 0, nargs);
229 if (!args1)
230 goto bad;
231 *args2 = PyTuple_GetSlice(*args, nargs, PyTuple_GET_SIZE(*args));
232 if (!*args2)
233 goto bad;
234 }
235 else if (PyTuple_GET_SIZE(*args) > nargs) {
236 int m = nargs;
237 int n = PyTuple_GET_SIZE(*args);
238 PyErr_Format(PyExc_TypeError,
239 "function takes at most %d positional arguments (%d given)",
240 m, n);
241 goto bad;
242 }
243 else {
244 args1 = *args;
245 Py_INCREF(args1);
246 }
248 if (rqd_kwds && !*kwds)
249 for (i = 0, p = kwd_list; *p; i++, p++)
250 if (rqd_kwds[i])
251 goto missing_kwarg;
253 if (kwds2) {
254 if (*kwds) {
255 kwds1 = PyDict_New();
256 if (!kwds1)
257 goto bad;
258 *kwds2 = PyDict_Copy(*kwds);
259 if (!*kwds2)
260 goto bad;
261 for (i = 0, p = kwd_list; *p; i++, p++) {
262 x = PyDict_GetItemString(*kwds, *p);
263 if (x) {
264 if (PyDict_SetItemString(kwds1, *p, x) < 0)
265 goto bad;
266 if (PyDict_DelItemString(*kwds2, *p) < 0)
267 goto bad;
268 }
269 else if (rqd_kwds && rqd_kwds[i])
270 goto missing_kwarg;
271 }
272 }
273 else {
274 *kwds2 = PyDict_New();
275 if (!*kwds2)
276 goto bad;
277 }
278 }
279 else {
280 kwds1 = *kwds;
281 Py_XINCREF(kwds1);
282 if (rqd_kwds && *kwds)
283 for (i = 0, p = kwd_list; *p; i++, p++)
284 if (rqd_kwds[i] && !PyDict_GetItemString(*kwds, *p))
285 goto missing_kwarg;
286 }
288 *args = args1;
289 *kwds = kwds1;
290 return 0;
291 missing_kwarg:
292 PyErr_Format(PyExc_TypeError,
293 "required keyword argument '%s' is missing", *p);
294 bad:
295 Py_XDECREF(args1);
296 Py_XDECREF(kwds1);
297 if (args2) {
298 Py_XDECREF(*args2);
299 }
300 if (kwds2) {
301 Py_XDECREF(*kwds2);
302 }
303 return -1;
304 }
306 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
307 while (t->p) {
308 *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
309 if (!*t->p)
310 return -1;
311 if (t->i)
312 PyString_InternInPlace(t->p);
313 ++t;
314 }
315 return 0;
316 }
318 #include "compile.h"
319 #include "frameobject.h"
320 #include "traceback.h"
322 static void __Pyx_AddTraceback(char *funcname) {
323 PyObject *py_srcfile = 0;
324 PyObject *py_funcname = 0;
325 PyObject *py_globals = 0;
326 PyObject *empty_tuple = 0;
327 PyObject *empty_string = 0;
328 PyCodeObject *py_code = 0;
329 PyFrameObject *py_frame = 0;
331 py_srcfile = PyString_FromString(__pyx_filename);
332 if (!py_srcfile) goto bad;
333 py_funcname = PyString_FromString(funcname);
334 if (!py_funcname) goto bad;
335 py_globals = PyModule_GetDict(__pyx_m);
336 if (!py_globals) goto bad;
337 empty_tuple = PyTuple_New(0);
338 if (!empty_tuple) goto bad;
339 empty_string = PyString_FromString("");
340 if (!empty_string) goto bad;
341 py_code = PyCode_New(
342 0, /*int argcount,*/
343 0, /*int nlocals,*/
344 0, /*int stacksize,*/
345 0, /*int flags,*/
346 empty_string, /*PyObject *code,*/
347 empty_tuple, /*PyObject *consts,*/
348 empty_tuple, /*PyObject *names,*/
349 empty_tuple, /*PyObject *varnames,*/
350 empty_tuple, /*PyObject *freevars,*/
351 empty_tuple, /*PyObject *cellvars,*/
352 py_srcfile, /*PyObject *filename,*/
353 py_funcname, /*PyObject *name,*/
354 __pyx_lineno, /*int firstlineno,*/
355 empty_string /*PyObject *lnotab*/
356 );
357 if (!py_code) goto bad;
358 py_frame = PyFrame_New(
359 PyThreadState_Get(), /*PyThreadState *tstate,*/
360 py_code, /*PyCodeObject *code,*/
361 py_globals, /*PyObject *globals,*/
362 0 /*PyObject *locals*/
363 );
364 if (!py_frame) goto bad;
365 py_frame->f_lineno = __pyx_lineno;
366 PyTraceBack_Here(py_frame);
367 bad:
368 Py_XDECREF(py_srcfile);
369 Py_XDECREF(py_funcname);
370 Py_XDECREF(empty_tuple);
371 Py_XDECREF(empty_string);
372 Py_XDECREF(py_code);
373 Py_XDECREF(py_frame);
374 }