diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-21 14:04:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-21 14:04:43 (GMT) |
commit | efde146b0c42f2643f96d00896c99a90d501fb69 (patch) | |
tree | ccb5f7484b0c55bf005ec9b5eb80558d8adb7e46 /Modules/_testcapimodule.c | |
parent | 6921c13bbbb2c9695edd87331d98f7aa1e48f7f2 (diff) | |
download | cpython-efde146b0c42f2643f96d00896c99a90d501fb69.zip cpython-efde146b0c42f2643f96d00896c99a90d501fb69.tar.gz cpython-efde146b0c42f2643f96d00896c99a90d501fb69.tar.bz2 |
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.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index df35197..b8e1dbc 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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 */ }; |