bpo-37337: Add _PyObject_VectorcallMethod() (GH-14228)

This commit is contained in:
Jeroen Demeyer 2019-06-28 11:49:00 +02:00 committed by Inada Naoki
parent b4bee03087
commit b1263d5a60
7 changed files with 105 additions and 33 deletions

View file

@ -1077,6 +1077,38 @@ object_vacall(PyObject *base, PyObject *callable, va_list vargs)
}
PyObject *
_PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
assert(name != NULL);
assert(args != NULL);
assert(PyVectorcall_NARGS(nargsf) >= 1);
PyObject *callable = NULL;
/* Use args[0] as "self" argument */
int unbound = _PyObject_GetMethod(args[0], name, &callable);
if (callable == NULL) {
return NULL;
}
if (unbound) {
/* We must remove PY_VECTORCALL_ARGUMENTS_OFFSET since
* that would be interpreted as allowing to change args[-1] */
nargsf &= ~PY_VECTORCALL_ARGUMENTS_OFFSET;
}
else {
/* Skip "self". We can keep PY_VECTORCALL_ARGUMENTS_OFFSET since
* args[-1] in the onward call is args[0] here. */
args++;
nargsf--;
}
PyObject *result = _PyObject_Vectorcall(callable, args, nargsf, kwnames);
Py_DECREF(callable);
return result;
}
PyObject *
PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
{