Skip to content

Commit c49e8df

Browse files
timfelfangerer
authored andcommitted
implement PyObject_CallFunctionObjArgs using va_list api
1 parent 252bf1c commit c49e8df

File tree

1 file changed

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

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,26 @@ PyObject* _PyObject_CallFunction_SizeT(PyObject* callable, const char* fmt, ...)
204204
NO_INLINE
205205
PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ...) {
206206
// the arguments are given as a variable list followed by NULL
207-
PyObject* args = PyTuple_New(polyglot_get_arg_count() - 2);
208-
for (int i = 1; i < polyglot_get_arg_count() - 1; i++) {
209-
PyObject* arg = (PyObject*) polyglot_get_arg(i);
207+
va_list vargs;
208+
va_list countva;
209+
va_start(vargs, callable);
210+
va_copy(countva, vargs);
211+
int nargs = 0;
212+
for (;;) {
213+
if (va_arg(countva, PyObject *) != NULL) {
214+
nargs++;
215+
} else {
216+
break;
217+
}
218+
}
219+
va_end(countva);
220+
PyObject* args = PyTuple_New(nargs);
221+
for (int i = 0; i < nargs; i++) {
222+
PyObject* arg = (PyObject*) va_arg(vargs, PyObject *);
210223
Py_XINCREF(arg);
211-
PyTuple_SetItem(args, i - 1, arg);
224+
PyTuple_SetItem(args, i, arg);
212225
}
226+
va_end(vargs);
213227
return PyObject_CallObject(callable, args);
214228
}
215229

0 commit comments

Comments
 (0)