mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #12909: Make PyLong_As* functions consistent in their use of exceptions.
PyLong_AsDouble() and PyLong_AsUnsignedLongLong() now raise TypeError (rather than SystemError) when passed a non-integer argument, matching the behavior of all the other PyLong_As*() functions.
This commit is contained in:
parent
425fcd3045
commit
3d5881ec2b
3 changed files with 100 additions and 2 deletions
|
|
@ -177,6 +177,32 @@ TESTNAME(PyObject *error(const char*))
|
|||
Py_DECREF(one);
|
||||
}
|
||||
|
||||
/* Test F_PY_TO_{S,U} on non-pylong input. This should raise a TypeError. */
|
||||
{
|
||||
TYPENAME out;
|
||||
unsigned TYPENAME uout;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
|
||||
out = F_PY_TO_S(Py_None);
|
||||
if (out != (TYPENAME)-1 || !PyErr_Occurred())
|
||||
return error("PyLong_AsXXX(None) didn't complain");
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError))
|
||||
return error("PyLong_AsXXX(None) raised "
|
||||
"something other than TypeError");
|
||||
PyErr_Clear();
|
||||
|
||||
uout = F_PY_TO_U(Py_None);
|
||||
if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred())
|
||||
return error("PyLong_AsXXX(None) didn't complain");
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError))
|
||||
return error("PyLong_AsXXX(None) raised "
|
||||
"something other than TypeError");
|
||||
PyErr_Clear();
|
||||
|
||||
Py_DECREF(Py_None);
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue