From f171540ab8d816a996c34db3f6aa4bf9cf147fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Tue, 19 Nov 2002 20:49:15 +0000 Subject: 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 --- Objects/longobject.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'Objects/longobject.c') 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 * -- cgit v1.2.1