@@ -4487,7 +4487,7 @@ divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift)
4487
4487
}
4488
4488
4489
4489
/* Inner function for both long_rshift and _PyLong_Rshift, shifting an
4490
- integer right by a strictly positive shift. */
4490
+ integer right by a nonnegative shift. */
4491
4491
4492
4492
static PyObject *
4493
4493
long_rshift1 (PyLongObject * a , Py_ssize_t wordshift , digit remshift )
@@ -4497,8 +4497,6 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
4497
4497
twodigits accum ;
4498
4498
int a_negative ;
4499
4499
4500
- assert (wordshift > 0 || remshift > 0 );
4501
-
4502
4500
/* Fast path for small a. */
4503
4501
if (IS_MEDIUM_VALUE (a )) {
4504
4502
stwodigits m , x ;
@@ -4518,10 +4516,14 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
4518
4516
if (remshift == 0 ) {
4519
4517
remshift = PyLong_SHIFT ;
4520
4518
-- wordshift ;
4519
+ if (wordshift < 0 ) {
4520
+ /* Can only happen if the original shift was 0. */
4521
+ return long_long (a );
4522
+ }
4521
4523
}
4522
- assert (wordshift >= 0 );
4523
4524
}
4524
4525
4526
+ assert (wordshift >= 0 );
4525
4527
newsize = size_a - wordshift ;
4526
4528
if (newsize <= 0 ) {
4527
4529
return PyLong_FromLong (- a_negative );
@@ -4584,9 +4586,6 @@ long_rshift(PyObject *a, PyObject *b)
4584
4586
PyErr_SetString (PyExc_ValueError , "negative shift count" );
4585
4587
return NULL ;
4586
4588
}
4587
- if (Py_SIZE (b ) == 0 ) {
4588
- return long_long (a );
4589
- }
4590
4589
if (Py_SIZE (a ) == 0 ) {
4591
4590
return PyLong_FromLong (0 );
4592
4591
}
@@ -4603,10 +4602,6 @@ _PyLong_Rshift(PyObject *a, size_t shiftby)
4603
4602
digit remshift ;
4604
4603
4605
4604
assert (PyLong_Check (a ));
4606
-
4607
- if (shiftby == 0 ) {
4608
- return long_long (a );
4609
- }
4610
4605
if (Py_SIZE (a ) == 0 ) {
4611
4606
return PyLong_FromLong (0 );
4612
4607
}
0 commit comments