Skip to content

Commit 252bf1c

Browse files
timfelfangerer
authored andcommitted
replace CALL_WITH_VARARGS macro with CallWithPolyglotArgs
1 parent 7e19217 commit 252bf1c

File tree

1 file changed

+4
-31
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+4
-31
lines changed

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

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,6 @@ PyObject* PyObject_CallObject(PyObject* callable, PyObject* args) {
161161
return PyObject_Call(callable, args, PyDict_New());
162162
}
163163

164-
// (tfel): this is used a couple of times in this file only, for now
165-
#define CALL_WITH_VARARGS(retval, funcname, skipN, ...) \
166-
switch (polyglot_get_arg_count() - skipN) { \
167-
case 0: \
168-
retval = funcname(__VA_ARGS__); break; \
169-
case 1: \
170-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN)); break; \
171-
case 2: \
172-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1)); break; \
173-
case 3: \
174-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2)); break; \
175-
case 4: \
176-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3)); break; \
177-
case 5: \
178-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3), polyglot_get_arg(skipN + 4)); break; \
179-
case 6: \
180-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3), polyglot_get_arg(skipN + 4), polyglot_get_arg(skipN + 5)); break; \
181-
case 7: \
182-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3), polyglot_get_arg(skipN + 4), polyglot_get_arg(skipN + 5), polyglot_get_arg(skipN + 6)); break; \
183-
case 8: \
184-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3), polyglot_get_arg(skipN + 4), polyglot_get_arg(skipN + 5), polyglot_get_arg(skipN + 6), polyglot_get_arg(skipN + 7)); break; \
185-
case 9: \
186-
retval = funcname(__VA_ARGS__, polyglot_get_arg(skipN), polyglot_get_arg(skipN + 1), polyglot_get_arg(skipN + 2), polyglot_get_arg(skipN + 3), polyglot_get_arg(skipN + 4), polyglot_get_arg(skipN + 5), polyglot_get_arg(skipN + 6), polyglot_get_arg(skipN + 7), polyglot_get_arg(skipN + 8)); break; \
187-
default: \
188-
fprintf(stderr, "Too many arguments passed through varargs: %d", polyglot_get_arg_count() - skipN); \
189-
}
190-
191164
NO_INLINE
192165
PyObject* PyObject_CallFunction(PyObject* callable, const char* fmt, ...) {
193166
PyObject* args;
@@ -196,7 +169,7 @@ PyObject* PyObject_CallFunction(PyObject* callable, const char* fmt, ...) {
196169
return PyObject_CallObject(callable, NULL);
197170
}
198171

199-
CALL_WITH_VARARGS(args, Py_BuildValue, 2, fmt);
172+
CallWithPolyglotArgs(args, fmt, _PyTruffle_BuildValue, fmt);
200173
if (strlen(fmt) < 2) {
201174
PyObject* singleArg = args;
202175
args = PyTuple_New(strlen(fmt));
@@ -216,7 +189,7 @@ PyObject* _PyObject_CallFunction_SizeT(PyObject* callable, const char* fmt, ...)
216189
return PyObject_CallObject(callable, NULL);
217190
}
218191

219-
CALL_WITH_VARARGS(args, Py_BuildValue, 2, fmt);
192+
CallWithPolyglotArgs(args, fmt, _PyTruffle_BuildValue, fmt);
220193
if (strlen(fmt) < 2) {
221194
PyObject* singleArg = args;
222195
args = PyTuple_New(strlen(fmt));
@@ -247,7 +220,7 @@ PyObject* PyObject_CallMethod(PyObject* object, const char* method, const char*
247220
if (fmt == NULL || fmt[0] == '\0') {
248221
args = Py_None;
249222
} else {
250-
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
223+
CallWithPolyglotArgs(args, fmt, _PyTruffle_BuildValue, fmt);
251224
}
252225
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
253226
}
@@ -265,7 +238,7 @@ PyObject* _PyObject_CallMethod_SizeT(PyObject* object, const char* method, const
265238
if (fmt == NULL || fmt[0] == '\0') {
266239
args = Py_None;
267240
} else {
268-
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
241+
CallWithPolyglotArgs(args, fmt, _PyTruffle_BuildValue, fmt);
269242
}
270243
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
271244
}

0 commit comments

Comments
 (0)