19 Jun
2019
19 Jun
'19
5:59 a.m.
Le mer. 19 juin 2019 à 00:11, Hugh Fisher <hugo.fisher@gmail.com> a écrit :
_PyObject_CallVaArgs(..., NULL) with variable number of positional arguments, null terminated?
Such function already exists: PyObject_CallFunctionObjArgs().
PyObject_CallNoArgs() was justified by a lower usage of the C stack memory. PyObject_CallFunctionObjArgs() uses more stack than PyObject_CallNoArgs(), since the number of arguments is unknown: you have to scan "vargs" for NULL terminator.
PyObject_CallNoArgs() doesn't have this issue: it always have zero argument. _PyObject_FastCall() neither: the number of arguments is passed... as an argument ;-)
Example:
PyObject* args[] = {arg1, arg2};
res = _PyObject_FastCall(func, args, Py_ARRAY_LENGTH(args));
They are many ways to write the same code:
PyObject* args[2] = {arg1, arg2};
res = _PyObject_FastCall(func, args, 2);
Victor