diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-04-06 16:53:17 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-04-06 16:53:17 (GMT) |
commit | 3318d29d2202f58b4011ec050f5e68a14feb6722 (patch) | |
tree | fddb3be27d04080c7d1fa77be3620ae4d9e45881 /Objects/longobject.c | |
parent | f96b78437bdda6e14d6b9b7edb54b8987de42915 (diff) | |
download | cpython-3318d29d2202f58b4011ec050f5e68a14feb6722.zip cpython-3318d29d2202f58b4011ec050f5e68a14feb6722.tar.gz cpython-3318d29d2202f58b4011ec050f5e68a14feb6722.tar.bz2 |
Merged revisions 79843-79844 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79843 | mark.dickinson | 2010-04-06 17:46:09 +0100 (Tue, 06 Apr 2010) | 4 lines
Issue #8259: Get rid of 'outrageous left shift count' error when
left-shifting an integer by more than 2**31 on a 64-bit machine. Also
convert shift counts to a Py_ssize_t instead of a C long.
........
r79844 | mark.dickinson | 2010-04-06 17:47:55 +0100 (Tue, 06 Apr 2010) | 1 line
Misc/NEWS entry for r79843.
........
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 781e34f..93f5611 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3779,8 +3779,7 @@ static PyObject * long_rshift(PyLongObject *a, PyLongObject *b) { PyLongObject *z = NULL; - long shiftby; - Py_ssize_t newsize, wordshift, loshift, hishift, i, j; + Py_ssize_t shiftby, newsize, wordshift, loshift, hishift, i, j; digit lomask, himask; CHECK_BINOP(a, b); @@ -3799,8 +3798,7 @@ long_rshift(PyLongObject *a, PyLongObject *b) Py_DECREF(a2); } else { - - shiftby = PyLong_AsLong((PyObject *)b); + shiftby = PyLong_AsSsize_t((PyObject *)b); if (shiftby == -1L && PyErr_Occurred()) goto rshift_error; if (shiftby < 0) { @@ -3841,27 +3839,21 @@ long_lshift(PyObject *v, PyObject *w) PyLongObject *a = (PyLongObject*)v; PyLongObject *b = (PyLongObject*)w; PyLongObject *z = NULL; - long shiftby; - Py_ssize_t oldsize, newsize, wordshift, remshift, i, j; + Py_ssize_t shiftby, oldsize, newsize, wordshift, remshift, i, j; twodigits accum; CHECK_BINOP(a, b); - shiftby = PyLong_AsLong((PyObject *)b); + shiftby = PyLong_AsSsize_t((PyObject *)b); if (shiftby == -1L && PyErr_Occurred()) goto lshift_error; if (shiftby < 0) { PyErr_SetString(PyExc_ValueError, "negative shift count"); goto lshift_error; } - if ((long)(int)shiftby != shiftby) { - PyErr_SetString(PyExc_ValueError, - "outrageous left shift count"); - goto lshift_error; - } /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */ - wordshift = (int)shiftby / PyLong_SHIFT; - remshift = (int)shiftby - wordshift * PyLong_SHIFT; + wordshift = shiftby / PyLong_SHIFT; + remshift = shiftby - wordshift * PyLong_SHIFT; oldsize = ABS(Py_SIZE(a)); newsize = oldsize + wordshift; |