Skip to content

Commit c023fac

Browse files
timfelfangerer
authored andcommitted
simplify further
1 parent 6ce4ac4 commit c023fac

File tree

1 file changed

+34
-55
lines changed

1 file changed

+34
-55
lines changed

graalpython/com.oracle.graal.python.cext/src/modsupport.c

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -46,52 +46,51 @@ typedef struct _positional_argstack {
4646
struct _positional_argstack* prev;
4747
} positional_argstack;
4848

49-
MUST_INLINE
5049
PyObject* PyTruffle_GetArg(positional_argstack* p, PyObject* kwds, char** kwdnames, unsigned char keywords_only) {
50+
void* out = NULL;
5151
if (!keywords_only) {
5252
int l = truffle_invoke_i(PY_TRUFFLE_CEXT, "PyObject_LEN", to_java(p->argv));
5353
if (p->argnum < l) {
54-
return PyTuple_GetItem(p->argv, p->argnum);
54+
out = PyTuple_GetItem(p->argv, p->argnum);
5555
}
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
5857
const char* kwdname = kwdnames[p->argnum];
5958
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)));
6260
}
6361
}
64-
return NULL;
62+
v->argnum++;
63+
return out;
6564
}
6665

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++; \
9594
} while(0);
9695

9796
#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
122121
case 'z':
123122
case 'y':
124123
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
125-
v->argnum++;
126124
if (format[format_idx + 1] == '*') {
127125
format_idx++; // skip over '*'
128126
PyErr_Format(PyExc_TypeError, "%c* not supported", c);
@@ -149,7 +147,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
149147
break;
150148
case 'S':
151149
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
152-
v->argnum++;
153150
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
154151
if (!PyBytes_Check(arg)) {
155152
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
159156
break;
160157
case 'Y':
161158
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
162-
v->argnum++;
163159
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
164160
if (!PyByteArray_Check(arg)) {
165161
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
173169
return 0;
174170
case 'U':
175171
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
176-
v->argnum++;
177172
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
178173
if (!PyUnicode_Check(arg)) {
179174
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
197192
return 0;
198193
case 'b':
199194
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
200-
v->argnum++;
201195
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
202196
if (_PyLong_Sign(arg) < 0) {
203197
PyErr_Format(PyExc_TypeError, "expected non-negative integer");
@@ -207,13 +201,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
207201
break;
208202
case 'B':
209203
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
210-
v->argnum++;
211204
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
212205
PyTruffle_WriteOut(output_idx, unsigned char, as_uchar(arg));
213206
break;
214207
case 'h':
215208
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
216-
v->argnum++;
217209
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
218210
if (_PyLong_Sign(arg) < 0) {
219211
PyErr_Format(PyExc_TypeError, "expected non-negative integer");
@@ -223,31 +215,26 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
223215
break;
224216
case 'H':
225217
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
226-
v->argnum++;
227218
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
228219
PyTruffle_WriteOut(output_idx, short int, as_short(arg));
229220
break;
230221
case 'i':
231222
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
232-
v->argnum++;
233223
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
234224
PyTruffle_WriteOut(output_idx, int, as_int(arg));
235225
break;
236226
case 'I':
237227
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
238-
v->argnum++;
239228
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
240229
PyTruffle_WriteOut(output_idx, unsigned int, as_int(arg));
241230
break;
242231
case 'l':
243232
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
244-
v->argnum++;
245233
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
246234
PyTruffle_WriteOut(output_idx, long, as_long(arg));
247235
break;
248236
case 'k':
249237
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
250-
v->argnum++;
251238
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
252239
PyTruffle_WriteOut(output_idx, unsigned long, as_long(arg));
253240
break;
@@ -259,13 +246,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
259246
return 0;
260247
case 'n':
261248
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
262-
v->argnum++;
263249
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
264250
PyTruffle_WriteOut(output_idx, Py_ssize_t, as_long(arg));
265251
break;
266252
case 'c':
267253
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
268-
v->argnum++;
269254
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
270255
if (!(PyBytes_Check(arg) || PyByteArray_Check(arg))) {
271256
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
279264
break;
280265
case 'C':
281266
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
282-
v->argnum++;
283267
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
284268
if (!PyUnicode_Check(arg)) {
285269
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
293277
break;
294278
case 'f':
295279
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
296-
v->argnum++;
297280
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
298281
PyTruffle_WriteOut(output_idx, float, as_float(arg));
299282
break;
300283
case 'd':
301284
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
302-
v->argnum++;
303285
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
304286
PyTruffle_WriteOut(output_idx, double, as_double(arg));
305287
break;
@@ -308,7 +290,6 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
308290
return 0;
309291
case 'O':
310292
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
311-
v->argnum++;
312293
if (format[format_idx + 1] == '!') {
313294
format_idx++;
314295
PyTypeObject* typeobject = (PyTypeObject*)PyTruffle_ArgN(output_idx);
@@ -340,13 +321,11 @@ int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, const ch
340321
break;
341322
case 'p':
342323
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
343-
v->argnum++;
344324
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
345325
PyTruffle_WriteOut(output_idx, int, as_int(truffle_invoke(to_java(arg), "__bool__")));
346326
break;
347327
case '(':
348328
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only);
349-
v->argnum++;
350329
PyTruffle_SkipOptionalArg(output_idx, arg, rest_optional);
351330
if (!PyTuple_Check(arg)) {
352331
PyErr_Format(PyExc_TypeError, "expected tuple, got %R", Py_TYPE(arg));

0 commit comments

Comments
 (0)