[issue8259] left shift operator doesn't accepts long as second argument

Mark Dickinson report at bugs.python.org
Fri Apr 2 13:29:46 CEST 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

The original error, for a 32-bit machine, looks like expected behaviour to me;  at worst, it's a doc bug.  If the right-hand argument doesn't fit into a Py_ssize_t, then I think it's reasonable to refuse to do the shift.

But Antoine's 'outrageous left shift count' comes from the following code, in long_lshift in Objects/longobject.c.

	if ((long)(int)shiftby != shiftby) {
		PyErr_SetString(PyExc_ValueError,
				"outrageous left shift count");
		goto lshift_error;
	}

I think this code dates from the days when the number of 'digits' of a PyLong was held in an int rather than a Py_ssize_t, and I think it's a (minor) bug.  A 64-bit machine with sufficient RAM shouldn't mind shifting something by >= 2**31 places.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8259>
_______________________________________


More information about the Python-bugs-list mailing list