summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-09-07 19:40:26 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-09-07 19:40:26 (GMT)
commit3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf (patch)
tree56fe5975d6856ad3f89daa74988a5f66221eda4a /Objects
parent425fcd3045708a6e8ce1c15c6950101d2523dd59 (diff)
downloadcpython-3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf.zip
cpython-3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf.tar.gz
cpython-3d5881ec2b600d59c38ca757ecdbfaf6c7d976cf.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 5df519c..8f6f18f 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -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,