mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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
This commit is contained in:
parent
7a3bae410d
commit
f171540ab8
9 changed files with 82 additions and 49 deletions
|
@ -2516,16 +2516,6 @@ long_coerce(PyObject **pv, PyObject **pw)
|
|||
return 1; /* Can't do it */
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
long_int(PyObject *v)
|
||||
{
|
||||
long x;
|
||||
x = PyLong_AsLong(v);
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
return PyInt_FromLong(x);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
long_long(PyObject *v)
|
||||
{
|
||||
|
@ -2533,6 +2523,27 @@ long_long(PyObject *v)
|
|||
return v;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
long_int(PyObject *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 *
|
||||
long_float(PyObject *v)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue