diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-11 21:44:14 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-11 21:44:14 (GMT) |
commit | 73a1dfe3674429f923e98b84ef01df1614baad2f (patch) | |
tree | 9af64d22a0bdc3b3b77d7c704cfcda6c098b58b7 /Objects | |
parent | 95fefc7a7a7d3c732b9b2a2102ced3bcc7859cda (diff) | |
download | cpython-73a1dfe3674429f923e98b84ef01df1614baad2f.zip cpython-73a1dfe3674429f923e98b84ef01df1614baad2f.tar.gz cpython-73a1dfe3674429f923e98b84ef01df1614baad2f.tar.bz2 |
More bug 460020. When I is a subclass of int, disable the +I(whatever),
I(0) << whatever, I(0) >> whatever, I(whatever) << 0 and I(whatever) >> 0
optimizations.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/intobject.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 261edb8..c93b384 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -681,8 +681,12 @@ int_neg(PyIntObject *v) static PyObject * int_pos(PyIntObject *v) { - Py_INCREF(v); - return (PyObject *)v; + if (PyInt_CheckExact(v)) { + Py_INCREF(v); + return (PyObject *)v; + } + else + return PyInt_FromLong(v->ob_ival); } static PyObject * @@ -716,10 +720,8 @@ int_lshift(PyIntObject *v, PyIntObject *w) PyErr_SetString(PyExc_ValueError, "negative shift count"); return NULL; } - if (a == 0 || b == 0) { - Py_INCREF(v); - return (PyObject *) v; - } + if (a == 0 || b == 0) + return int_pos(v); if (b >= LONG_BIT) { return PyInt_FromLong(0L); } @@ -737,10 +739,8 @@ int_rshift(PyIntObject *v, PyIntObject *w) PyErr_SetString(PyExc_ValueError, "negative shift count"); return NULL; } - if (a == 0 || b == 0) { - Py_INCREF(v); - return (PyObject *) v; - } + if (a == 0 || b == 0) + return int_pos(v); if (b >= LONG_BIT) { if (a < 0) a = -1; |