@@ -46,52 +46,51 @@ typedef struct _positional_argstack {
46
46
struct _positional_argstack * prev ;
47
47
} positional_argstack ;
48
48
49
- MUST_INLINE
50
49
PyObject * PyTruffle_GetArg (positional_argstack * p , PyObject * kwds , char * * kwdnames , unsigned char keywords_only ) {
50
+ void * out = NULL ;
51
51
if (!keywords_only ) {
52
52
int l = truffle_invoke_i (PY_TRUFFLE_CEXT , "PyObject_LEN" , to_java (p -> argv ));
53
53
if (p -> argnum < l ) {
54
- return PyTuple_GetItem (p -> argv , p -> argnum );
54
+ out = PyTuple_GetItem (p -> argv , p -> argnum );
55
55
}
56
- }
57
- if (p -> prev == NULL && kwdnames != NULL ) { // only the bottom argstack can have keyword names
56
+ } else if (out == NULL && p -> prev == NULL && kwdnames != NULL ) { // only the bottom argstack can have keyword names
58
57
const char * kwdname = kwdnames [p -> argnum ];
59
58
if (kwdname != NULL ) {
60
- void * kwarg = PyDict_GetItem (kwds , to_sulong (truffle_read_string (kwdname )));
61
- return kwarg ;
59
+ out = PyDict_GetItem (kwds , to_sulong (truffle_read_string (kwdname )));
62
60
}
63
61
}
64
- return NULL ;
62
+ v -> argnum ++ ;
63
+ return out ;
65
64
}
66
65
67
- #define PyTruffle_WriteOut (n , T , arg ) { \
68
- T __oai = arg; \
69
- if (PyErr_Occurred()) { \
70
- return 0; \
71
- } \
72
- switch(n) { \
73
- case 0: *((T*)v0) = __oai; break; \
74
- case 1: *((T*)v1) = __oai; break; \
75
- case 2: *((T*)v2) = __oai; break; \
76
- case 3: *((T*)v3) = __oai; break; \
77
- case 4: *((T*)v4) = __oai; break; \
78
- case 5: *((T*)v5) = __oai; break; \
79
- case 6: *((T*)v6) = __oai; break; \
80
- case 7: *((T*)v7) = __oai; break; \
81
- case 8: *((T*)v8) = __oai; break; \
82
- case 9: *((T*)v9) = __oai; break; \
83
- case 10: *((T*)v10) = __oai; break; \
84
- case 11: *((T*)v11) = __oai; break; \
85
- case 12: *((T*)v12) = __oai; break; \
86
- case 13: *((T*)v13) = __oai; break; \
87
- case 14: *((T*)v14) = __oai; break; \
88
- case 15: *((T*)v15) = __oai; break; \
89
- case 16: *((T*)v16) = __oai; break; \
90
- case 17: *((T*)v17) = __oai; break; \
91
- case 18: *((T*)v18) = __oai; break; \
92
- case 19: *((T*)v19) = __oai; break; \
93
- } \
94
- n++; \
66
+ #define PyTruffle_WriteOut (n , T , arg ) { \
67
+ T __oai = arg; \
68
+ if (PyErr_Occurred()) { \
69
+ return 0; \
70
+ } \
71
+ switch(n) { \
72
+ case 0: *((T*)v0) = __oai; break; \
73
+ case 1: *((T*)v1) = __oai; break; \
74
+ case 2: *((T*)v2) = __oai; break; \
75
+ case 3: *((T*)v3) = __oai; break; \
76
+ case 4: *((T*)v4) = __oai; break; \
77
+ case 5: *((T*)v5) = __oai; break; \
78
+ case 6: *((T*)v6) = __oai; break; \
79
+ case 7: *((T*)v7) = __oai; break; \
80
+ case 8: *((T*)v8) = __oai; break; \
81
+ case 9: *((T*)v9) = __oai; break; \
82
+ case 10: *((T*)v10) = __oai; break; \
83
+ case 11: *((T*)v11) = __oai; break; \
84
+ case 12: *((T*)v12) = __oai; break; \
85
+ case 13: *((T*)v13) = __oai; break; \
86
+ case 14: *((T*)v14) = __oai; break; \
87
+ case 15: *((T*)v15) = __oai; break; \
88
+ case 16: *((T*)v16) = __oai; break; \
89
+ case 17: *((T*)v17) = __oai; break; \
90
+ case 18: *((T*)v18) = __oai; break; \
91
+ case 19: *((T*)v19) = __oai; break; \
92
+ } \
93
+ n++; \
95
94
} while(0);
96
95
97
96
#define PyTruffle_ArgN (n ) (((n) == 0) ? v0 : (((n) == 1) ? v1 : (((n) == 2) ? v2 : (((n) == 3) ? v3 : (((n) == 4) ? v4 : (((n) == 5) ? v5 : (((n) == 6) ? v6 : (((n) == 7) ? v7 : (((n) == 8) ? v8 : (((n) == 9) ? v9 : (((n) == 10) ? v10 : (((n) == 11) ? v11 : (((n) == 12) ? v12 : (((n) == 13) ? v13 : (((n) == 14) ? v14 : (((n) == 15) ? v15 : (((n) == 16) ? v16 : (((n) == 17) ? v17 : (((n) == 18) ? v18 : (((n) == 19) ? v19 : NULL))))))))))))))))))))
@@ -122,7 +121,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
122
121
case 'z' :
123
122
case 'y' :
124
123
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
125
- v -> argnum ++ ;
126
124
if (format [format_idx + 1 ] == '*' ) {
127
125
format_idx ++ ; // skip over '*'
128
126
PyErr_Format (PyExc_TypeError , "%c* not supported" , c );
@@ -149,7 +147,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
149
147
break ;
150
148
case 'S' :
151
149
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
152
- v -> argnum ++ ;
153
150
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
154
151
if (!PyBytes_Check (arg )) {
155
152
PyErr_Format (PyExc_TypeError , "expected bytes, got %R" , Py_TYPE (arg ));
@@ -159,7 +156,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
159
156
break ;
160
157
case 'Y' :
161
158
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
162
- v -> argnum ++ ;
163
159
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
164
160
if (!PyByteArray_Check (arg )) {
165
161
PyErr_Format (PyExc_TypeError , "expected bytearray, got %R" , Py_TYPE (arg ));
@@ -173,7 +169,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
173
169
return 0 ;
174
170
case 'U' :
175
171
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
176
- v -> argnum ++ ;
177
172
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
178
173
if (!PyUnicode_Check (arg )) {
179
174
PyErr_Format (PyExc_TypeError , "expected str, got %R" , Py_TYPE (arg ));
@@ -197,7 +192,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
197
192
return 0 ;
198
193
case 'b' :
199
194
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
200
- v -> argnum ++ ;
201
195
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
202
196
if (_PyLong_Sign (arg ) < 0 ) {
203
197
PyErr_Format (PyExc_TypeError , "expected non-negative integer" );
@@ -207,13 +201,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
207
201
break ;
208
202
case 'B' :
209
203
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
210
- v -> argnum ++ ;
211
204
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
212
205
PyTruffle_WriteOut (output_idx , unsigned char , as_uchar (arg ));
213
206
break ;
214
207
case 'h' :
215
208
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
216
- v -> argnum ++ ;
217
209
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
218
210
if (_PyLong_Sign (arg ) < 0 ) {
219
211
PyErr_Format (PyExc_TypeError , "expected non-negative integer" );
@@ -223,31 +215,26 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
223
215
break ;
224
216
case 'H' :
225
217
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
226
- v -> argnum ++ ;
227
218
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
228
219
PyTruffle_WriteOut (output_idx , short int , as_short (arg ));
229
220
break ;
230
221
case 'i' :
231
222
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
232
- v -> argnum ++ ;
233
223
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
234
224
PyTruffle_WriteOut (output_idx , int , as_int (arg ));
235
225
break ;
236
226
case 'I' :
237
227
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
238
- v -> argnum ++ ;
239
228
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
240
229
PyTruffle_WriteOut (output_idx , unsigned int , as_int (arg ));
241
230
break ;
242
231
case 'l' :
243
232
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
244
- v -> argnum ++ ;
245
233
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
246
234
PyTruffle_WriteOut (output_idx , long , as_long (arg ));
247
235
break ;
248
236
case 'k' :
249
237
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
250
- v -> argnum ++ ;
251
238
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
252
239
PyTruffle_WriteOut (output_idx , unsigned long , as_long (arg ));
253
240
break ;
@@ -259,13 +246,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
259
246
return 0 ;
260
247
case 'n' :
261
248
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
262
- v -> argnum ++ ;
263
249
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
264
250
PyTruffle_WriteOut (output_idx , Py_ssize_t , as_long (arg ));
265
251
break ;
266
252
case 'c' :
267
253
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
268
- v -> argnum ++ ;
269
254
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
270
255
if (!(PyBytes_Check (arg ) || PyByteArray_Check (arg ))) {
271
256
PyErr_Format (PyExc_TypeError , "expted bytes or bytearray, got %R" , Py_TYPE (arg ));
@@ -279,7 +264,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
279
264
break ;
280
265
case 'C' :
281
266
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
282
- v -> argnum ++ ;
283
267
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
284
268
if (!PyUnicode_Check (arg )) {
285
269
PyErr_Format (PyExc_TypeError , "expted bytes or bytearray, got %R" , Py_TYPE (arg ));
@@ -293,13 +277,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
293
277
break ;
294
278
case 'f' :
295
279
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
296
- v -> argnum ++ ;
297
280
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
298
281
PyTruffle_WriteOut (output_idx , float , as_float (arg ));
299
282
break ;
300
283
case 'd' :
301
284
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
302
- v -> argnum ++ ;
303
285
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
304
286
PyTruffle_WriteOut (output_idx , double , as_double (arg ));
305
287
break ;
@@ -308,7 +290,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
308
290
return 0 ;
309
291
case 'O' :
310
292
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
311
- v -> argnum ++ ;
312
293
if (format [format_idx + 1 ] == '!' ) {
313
294
format_idx ++ ;
314
295
PyTypeObject * typeobject = (PyTypeObject * )PyTruffle_ArgN (output_idx );
@@ -340,13 +321,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
340
321
break ;
341
322
case 'p' :
342
323
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
343
- v -> argnum ++ ;
344
324
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
345
325
PyTruffle_WriteOut (output_idx , int , as_int (truffle_invoke (to_java (arg ), "__bool__" )));
346
326
break ;
347
327
case '(' :
348
328
arg = PyTruffle_GetArg (v , kwds , kwdnames , rest_keywords_only );
349
- v -> argnum ++ ;
350
329
PyTruffle_SkipOptionalArg (output_idx , arg , rest_optional );
351
330
if (!PyTuple_Check (arg )) {
352
331
PyErr_Format (PyExc_TypeError , "expected tuple, got %R" , Py_TYPE (arg ));
0 commit comments