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:
Nadeem Vawda 2011-09-07 21:40:26 +02:00
parent 425fcd3045
commit 3d5881ec2b
3 changed files with 100 additions and 2 deletions

View file

@ -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,