diff options
author | Walter Dörwald <walter@livinglogic.de> | 2002-11-19 20:49:15 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2002-11-19 20:49:15 (GMT) |
commit | f171540ab8d816a996c34db3f6aa4bf9cf147fba (patch) | |
tree | 001d1ff0bdea449058218d2debf6d6f8dbbcb220 /Objects/intobject.c | |
parent | 7a3bae410df3dd0032509b97077d0c4d98276fdd (diff) | |
download | cpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.zip cpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.tar.gz cpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.tar.bz2 |
Change int() so that passing a string, unicode, float or long argument
that is outside the integer range no longer raises OverflowError, but
returns a long object instead.
This fixes SF bug http://www.python.org/sf/635115
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index e339085..7242dd0 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -166,9 +166,20 @@ PyInt_AsLong(register PyObject *op) if (io == NULL) return -1; if (!PyInt_Check(io)) { - PyErr_SetString(PyExc_TypeError, - "nb_int should return int object"); - return -1; + if (PyLong_Check(io)) { + /* got a long? => retry int conversion */ + val = PyLong_AsLong((PyObject *)io); + if (PyErr_Occurred()) { + Py_DECREF(io); + return -1; + } + } + else + { + PyErr_SetString(PyExc_TypeError, + "nb_int should return int object"); + return -1; + } } val = PyInt_AS_LONG(io); @@ -892,7 +903,8 @@ Convert a string or number to an integer, if possible. A floating point\n\ argument will be truncated towards zero (this does not include a string\n\ representation of a floating point number!) When converting a string, use\n\ the optional base. It is an error to supply a base when converting a\n\ -non-string."); +non-string. If the argument is outside the integer range a long object\n\ +will be returned instead."); static PyNumberMethods int_as_number = { (binaryfunc)int_add, /*nb_add*/ |