diff options
author | Walter Dörwald <walter@livinglogic.de> | 2002-11-19 20:49:15 +0000 |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2002-11-19 20:49:15 +0000 |
commit | f171540ab8d816a996c34db3f6aa4bf9cf147fba (patch) | |
tree | 001d1ff0bdea449058218d2debf6d6f8dbbcb220 /Objects/longobject.c | |
parent | 7a3bae410df3dd0032509b97077d0c4d98276fdd (diff) | |
download | cpython-git-f171540ab8d816a996c34db3f6aa4bf9cf147fba.tar.gz |
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/longobject.c')
-rw-r--r-- | Objects/longobject.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 7374fce9dd..5038823334 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2517,20 +2517,31 @@ long_coerce(PyObject **pv, PyObject **pw) } static PyObject * -long_int(PyObject *v) +long_long(PyObject *v) { - long x; - x = PyLong_AsLong(v); - if (PyErr_Occurred()) - return NULL; - return PyInt_FromLong(x); + Py_INCREF(v); + return v; } static PyObject * -long_long(PyObject *v) +long_int(PyObject *v) { - Py_INCREF(v); - return v; + long x; + x = PyLong_AsLong(v); + if (PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { + PyErr_Clear(); + if (PyLong_CheckExact(v)) { + Py_INCREF(v); + return v; + } + else + return _PyLong_Copy((PyLongObject *)v); + } + else + return NULL; + } + return PyInt_FromLong(x); } static PyObject * |