Kaydet (Commit) 73a1dfe3 authored tarafından Tim Peters's avatar Tim Peters

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.
üst 95fefc7a
...@@ -1366,6 +1366,11 @@ def inherits(): ...@@ -1366,6 +1366,11 @@ def inherits():
a = hexint(12345) a = hexint(12345)
verify(int(a) == 12345) verify(int(a) == 12345)
verify(int(a).__class__ is int) verify(int(a).__class__ is int)
verify((+a).__class__ is int)
verify((a >> 0).__class__ is int)
verify((a << 0).__class__ is int)
verify((hexint(0) << 12).__class__ is int)
verify((hexint(0) >> 12).__class__ is int)
class octlong(long): class octlong(long):
__slots__ = [] __slots__ = []
......
...@@ -681,8 +681,12 @@ int_neg(PyIntObject *v) ...@@ -681,8 +681,12 @@ int_neg(PyIntObject *v)
static PyObject * static PyObject *
int_pos(PyIntObject *v) int_pos(PyIntObject *v)
{ {
if (PyInt_CheckExact(v)) {
Py_INCREF(v); Py_INCREF(v);
return (PyObject *)v; return (PyObject *)v;
}
else
return PyInt_FromLong(v->ob_ival);
} }
static PyObject * static PyObject *
...@@ -716,10 +720,8 @@ int_lshift(PyIntObject *v, PyIntObject *w) ...@@ -716,10 +720,8 @@ int_lshift(PyIntObject *v, PyIntObject *w)
PyErr_SetString(PyExc_ValueError, "negative shift count"); PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL; return NULL;
} }
if (a == 0 || b == 0) { if (a == 0 || b == 0)
Py_INCREF(v); return int_pos(v);
return (PyObject *) v;
}
if (b >= LONG_BIT) { if (b >= LONG_BIT) {
return PyInt_FromLong(0L); return PyInt_FromLong(0L);
} }
...@@ -737,10 +739,8 @@ int_rshift(PyIntObject *v, PyIntObject *w) ...@@ -737,10 +739,8 @@ int_rshift(PyIntObject *v, PyIntObject *w)
PyErr_SetString(PyExc_ValueError, "negative shift count"); PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL; return NULL;
} }
if (a == 0 || b == 0) { if (a == 0 || b == 0)
Py_INCREF(v); return int_pos(v);
return (PyObject *) v;
}
if (b >= LONG_BIT) { if (b >= LONG_BIT) {
if (a < 0) if (a < 0)
a = -1; a = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment