Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3318d29

Browse files
committed
Merged revisions 79843-79844 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent f96b784 commit 3318d29

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #8259: 1L << (2**31) no longer produces an 'outrageous shift error'
16+
on 64-bit machines. The shift count for either left or right shift is
17+
permitted to be up to sys.maxsize.
18+
1519
- Ensure that tokenization of identifiers is not affected by locale.
1620

1721
- Issue #1222585: Added LDCXXSHARED for C++ support. Patch by Arfrever.

Objects/longobject.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,8 +3779,7 @@ static PyObject *
37793779
long_rshift(PyLongObject *a, PyLongObject *b)
37803780
{
37813781
PyLongObject *z = NULL;
3782-
long shiftby;
3783-
Py_ssize_t newsize, wordshift, loshift, hishift, i, j;
3782+
Py_ssize_t shiftby, newsize, wordshift, loshift, hishift, i, j;
37843783
digit lomask, himask;
37853784

37863785
CHECK_BINOP(a, b);
@@ -3799,8 +3798,7 @@ long_rshift(PyLongObject *a, PyLongObject *b)
37993798
Py_DECREF(a2);
38003799
}
38013800
else {
3802-
3803-
shiftby = PyLong_AsLong((PyObject *)b);
3801+
shiftby = PyLong_AsSsize_t((PyObject *)b);
38043802
if (shiftby == -1L && PyErr_Occurred())
38053803
goto rshift_error;
38063804
if (shiftby < 0) {
@@ -3841,27 +3839,21 @@ long_lshift(PyObject *v, PyObject *w)
38413839
PyLongObject *a = (PyLongObject*)v;
38423840
PyLongObject *b = (PyLongObject*)w;
38433841
PyLongObject *z = NULL;
3844-
long shiftby;
3845-
Py_ssize_t oldsize, newsize, wordshift, remshift, i, j;
3842+
Py_ssize_t shiftby, oldsize, newsize, wordshift, remshift, i, j;
38463843
twodigits accum;
38473844

38483845
CHECK_BINOP(a, b);
38493846

3850-
shiftby = PyLong_AsLong((PyObject *)b);
3847+
shiftby = PyLong_AsSsize_t((PyObject *)b);
38513848
if (shiftby == -1L && PyErr_Occurred())
38523849
goto lshift_error;
38533850
if (shiftby < 0) {
38543851
PyErr_SetString(PyExc_ValueError, "negative shift count");
38553852
goto lshift_error;
38563853
}
3857-
if ((long)(int)shiftby != shiftby) {
3858-
PyErr_SetString(PyExc_ValueError,
3859-
"outrageous left shift count");
3860-
goto lshift_error;
3861-
}
38623854
/* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */
3863-
wordshift = (int)shiftby / PyLong_SHIFT;
3864-
remshift = (int)shiftby - wordshift * PyLong_SHIFT;
3855+
wordshift = shiftby / PyLong_SHIFT;
3856+
remshift = shiftby - wordshift * PyLong_SHIFT;
38653857

38663858
oldsize = ABS(Py_SIZE(a));
38673859
newsize = oldsize + wordshift;

0 commit comments

Comments
 (0)