mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -1193,10 +1193,14 @@ PyLong_AsUnsignedLongLong(PyObject *vv)
|
|||
int one = 1;
|
||||
int res;
|
||||
|
||||
if (vv == NULL || !PyLong_Check(vv)) {
|
||||
if (vv == NULL) {
|
||||
PyErr_BadInternalCall();
|
||||
return (unsigned PY_LONG_LONG)-1;
|
||||
}
|
||||
if (!PyLong_Check(vv)) {
|
||||
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
||||
return (unsigned PY_LONG_LONG)-1;
|
||||
}
|
||||
|
||||
v = (PyLongObject*)vv;
|
||||
switch(Py_SIZE(v)) {
|
||||
|
@ -2481,10 +2485,14 @@ PyLong_AsDouble(PyObject *v)
|
|||
Py_ssize_t exponent;
|
||||
double x;
|
||||
|
||||
if (v == NULL || !PyLong_Check(v)) {
|
||||
if (v == NULL) {
|
||||
PyErr_BadInternalCall();
|
||||
return -1.0;
|
||||
}
|
||||
if (!PyLong_Check(v)) {
|
||||
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
||||
return -1.0;
|
||||
}
|
||||
x = _PyLong_Frexp((PyLongObject *)v, &exponent);
|
||||
if ((x == -1.0 && PyErr_Occurred()) || exponent > DBL_MAX_EXP) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue