mirror of
https://github.com/python/cpython.git
synced 2025-08-29 13:15:11 +00:00
When an inlined operation on two small ints causes overflow, don't
raise the exception here -- call the generic function (which may convert the arguments to long and try again).
This commit is contained in:
parent
ae347b33be
commit
87780dfa97
1 changed files with 24 additions and 32 deletions
|
@ -915,16 +915,14 @@ eval_frame(PyFrameObject *f)
|
||||||
a = PyInt_AS_LONG(v);
|
a = PyInt_AS_LONG(v);
|
||||||
b = PyInt_AS_LONG(w);
|
b = PyInt_AS_LONG(w);
|
||||||
i = a + b;
|
i = a + b;
|
||||||
if ((i^a) < 0 && (i^b) < 0) {
|
if ((i^a) < 0 && (i^b) < 0)
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
goto slow_add;
|
||||||
"integer addition");
|
x = PyInt_FromLong(i);
|
||||||
x = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
x = PyInt_FromLong(i);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
slow_add:
|
||||||
x = PyNumber_Add(v, w);
|
x = PyNumber_Add(v, w);
|
||||||
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
@ -940,16 +938,14 @@ eval_frame(PyFrameObject *f)
|
||||||
a = PyInt_AS_LONG(v);
|
a = PyInt_AS_LONG(v);
|
||||||
b = PyInt_AS_LONG(w);
|
b = PyInt_AS_LONG(w);
|
||||||
i = a - b;
|
i = a - b;
|
||||||
if ((i^a) < 0 && (i^~b) < 0) {
|
if ((i^a) < 0 && (i^~b) < 0)
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
goto slow_sub;
|
||||||
"integer subtraction");
|
x = PyInt_FromLong(i);
|
||||||
x = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
x = PyInt_FromLong(i);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
slow_sub:
|
||||||
x = PyNumber_Subtract(v, w);
|
x = PyNumber_Subtract(v, w);
|
||||||
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
@ -1102,16 +1098,14 @@ eval_frame(PyFrameObject *f)
|
||||||
a = PyInt_AS_LONG(v);
|
a = PyInt_AS_LONG(v);
|
||||||
b = PyInt_AS_LONG(w);
|
b = PyInt_AS_LONG(w);
|
||||||
i = a + b;
|
i = a + b;
|
||||||
if ((i^a) < 0 && (i^b) < 0) {
|
if ((i^a) < 0 && (i^b) < 0)
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
goto slow_iadd;
|
||||||
"integer addition");
|
x = PyInt_FromLong(i);
|
||||||
x = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
x = PyInt_FromLong(i);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
slow_iadd:
|
||||||
x = PyNumber_InPlaceAdd(v, w);
|
x = PyNumber_InPlaceAdd(v, w);
|
||||||
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
@ -1127,16 +1121,14 @@ eval_frame(PyFrameObject *f)
|
||||||
a = PyInt_AS_LONG(v);
|
a = PyInt_AS_LONG(v);
|
||||||
b = PyInt_AS_LONG(w);
|
b = PyInt_AS_LONG(w);
|
||||||
i = a - b;
|
i = a - b;
|
||||||
if ((i^a) < 0 && (i^~b) < 0) {
|
if ((i^a) < 0 && (i^~b) < 0)
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
goto slow_isub;
|
||||||
"integer subtraction");
|
x = PyInt_FromLong(i);
|
||||||
x = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
x = PyInt_FromLong(i);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
slow_isub:
|
||||||
x = PyNumber_InPlaceSubtract(v, w);
|
x = PyNumber_InPlaceSubtract(v, w);
|
||||||
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue