mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #23571: _Py_CheckFunctionResult() now gives the name of the function
which returned an invalid result (result+error or no result without error) in the exception message. Add also unit test to check that the exception contains the name of the function. Special case: the final _PyEval_EvalFrameEx() check doesn't mention the function since it didn't execute a single function but a whole frame.
This commit is contained in:
parent
6921c13bbb
commit
efde146b0c
6 changed files with 93 additions and 12 deletions
|
@ -3360,6 +3360,24 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args)
|
|||
return Py_BuildValue("Nl", obj, pos);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
return_null_without_error(PyObject *self, PyObject *args)
|
||||
{
|
||||
/* invalid call: return NULL without setting an error,
|
||||
* _Py_CheckFunctionResult() must detect such bug at runtime. */
|
||||
PyErr_Clear();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
return_result_with_error(PyObject *self, PyObject *args)
|
||||
{
|
||||
/* invalid call: return a result with an error set,
|
||||
* _Py_CheckFunctionResult() must detect such bug at runtime. */
|
||||
PyErr_SetNone(PyExc_ValueError);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef TestMethods[] = {
|
||||
{"raise_exception", raise_exception, METH_VARARGS},
|
||||
|
@ -3519,6 +3537,10 @@ static PyMethodDef TestMethods[] = {
|
|||
pymarshal_read_last_object_from_file, METH_VARARGS},
|
||||
{"pymarshal_read_object_from_file",
|
||||
pymarshal_read_object_from_file, METH_VARARGS},
|
||||
{"return_null_without_error",
|
||||
return_null_without_error, METH_NOARGS},
|
||||
{"return_result_with_error",
|
||||
return_result_with_error, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue