bpo-38644: Pass tstate to _Py_CheckFunctionResult() (GH-17050)

* Add tstate parameter to _Py_CheckFunctionResult()
* Add _PyErr_FormatFromCauseTstate()
* Replace PyErr_XXX(...) with _PyErr_XXX(state, ...)
This commit is contained in:
Victor Stinner 2019-11-05 01:22:12 +01:00 committed by GitHub
parent be434dc038
commit 1726909094
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 52 deletions

View file

@ -454,9 +454,11 @@ cfunction_vectorcall_O(
static PyObject *
cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs)
{
assert(!PyErr_Occurred());
assert(kwargs == NULL || PyDict_Check(kwargs));
PyThreadState *tstate = _PyThreadState_GET();
assert(!_PyErr_Occurred(tstate));
int flags = PyCFunction_GET_FLAGS(func);
if (!(flags & METH_VARARGS)) {
/* If this is not a METH_VARARGS function, delegate to vectorcall */
@ -474,11 +476,12 @@ cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs)
}
else {
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
((PyCFunctionObject*)func)->m_ml->ml_name);
_PyErr_Format(tstate, PyExc_TypeError,
"%.200s() takes no keyword arguments",
((PyCFunctionObject*)func)->m_ml->ml_name);
return NULL;
}
result = meth(self, args);
}
return _Py_CheckFunctionResult(func, result, NULL);
return _Py_CheckFunctionResult(tstate, func, result, NULL);
}