From 87780dfa97ade2fbc5be60ea8f8b17ba30a03d29 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 23 Aug 2001 02:58:07 +0000 Subject: [PATCH] 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). --- Python/ceval.c | 56 ++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index f052e9726af..c9c9bf146ec 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);