summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-23 02:58:07 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-23 02:58:07 (GMT)
commit87780dfa97ade2fbc5be60ea8f8b17ba30a03d29 (patch)
tree3bbaf1eaed9aa610dd569c4a314719d754961d65 /Python/ceval.c
parentae347b33befbbf9068473f373def1620f2bab805 (diff)
downloadcpython-87780dfa97ade2fbc5be60ea8f8b17ba30a03d29.zip
cpython-87780dfa97ade2fbc5be60ea8f8b17ba30a03d29.tar.gz
cpython-87780dfa97ade2fbc5be60ea8f8b17ba30a03d29.tar.bz2
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).
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index f052e97..c9c9bf1 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -915,16 +915,14 @@ eval_frame(PyFrameObject *f)
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
i = a + b;
- if ((i^a) < 0 && (i^b) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "integer addition");
- x = NULL;
- }
- else
- x = PyInt_FromLong(i);
+ if ((i^a) < 0 && (i^b) < 0)
+ goto slow_add;
+ x = PyInt_FromLong(i);
}
- else
+ else {
+ slow_add:
x = PyNumber_Add(v, w);
+ }
Py_DECREF(v);
Py_DECREF(w);
PUSH(x);
@@ -940,16 +938,14 @@ eval_frame(PyFrameObject *f)
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
i = a - b;
- if ((i^a) < 0 && (i^~b) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "integer subtraction");
- x = NULL;
- }
- else
- x = PyInt_FromLong(i);
+ if ((i^a) < 0 && (i^~b) < 0)
+ goto slow_sub;
+ x = PyInt_FromLong(i);
}
- else
+ else {
+ slow_sub:
x = PyNumber_Subtract(v, w);
+ }
Py_DECREF(v);
Py_DECREF(w);
PUSH(x);
@@ -1102,16 +1098,14 @@ eval_frame(PyFrameObject *f)
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
i = a + b;
- if ((i^a) < 0 && (i^b) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "integer addition");
- x = NULL;
- }
- else
- x = PyInt_FromLong(i);
+ if ((i^a) < 0 && (i^b) < 0)
+ goto slow_iadd;
+ x = PyInt_FromLong(i);
}
- else
+ else {
+ slow_iadd:
x = PyNumber_InPlaceAdd(v, w);
+ }
Py_DECREF(v);
Py_DECREF(w);
PUSH(x);
@@ -1127,16 +1121,14 @@ eval_frame(PyFrameObject *f)
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
i = a - b;
- if ((i^a) < 0 && (i^~b) < 0) {
- PyErr_SetString(PyExc_OverflowError,
- "integer subtraction");
- x = NULL;
- }
- else
- x = PyInt_FromLong(i);
+ if ((i^a) < 0 && (i^~b) < 0)
+ goto slow_isub;
+ x = PyInt_FromLong(i);
}
- else
+ else {
+ slow_isub:
x = PyNumber_InPlaceSubtract(v, w);
+ }
Py_DECREF(v);
Py_DECREF(w);
PUSH(x);