Mercurial > cpython-lru_cache-weakref
diff Objects/intobject.c @ 19878:cc146ee52897 legacy-trunk
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.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 11 Sep 2001 21:44:14 +0000 |
| parents | f2a3009b528e |
| children | df409844b659 |
line wrap: on
line diff
--- a/Objects/intobject.c Tue Sep 11 21:25:10 2001 +0000 +++ b/Objects/intobject.c Tue Sep 11 21:44:14 2001 +0000 @@ -681,8 +681,12 @@ 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 @@ 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 @@ 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;
