]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #27222: various cleanups in long_rshift. Thanks Oren Milman.
authorMark Dickinson <dickinsm@gmail.com>
Sat, 17 Sep 2016 16:50:50 +0000 (17:50 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 17 Sep 2016 16:50:50 +0000 (17:50 +0100)
Misc/NEWS
Objects/longobject.c

index 76de19f507844da6536831d1834532343c697a54..a4da86489c5a16b5d38354cbfaafe5b9bbcbff89 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #27222: Clean up redundant code in long_rshift function. Thanks
+  Oren Milman.
+
 - Upgrade internal unicode databases to Unicode version 9.0.0.
 
 - Issue #28131: Fix a regression in zipimport's compile_source().  zipimport
index a453241b3fa8e437e7a7d9100838f736833ec587..0822f9bcb30eabe2d96466a1846cfb7e9c75fdde 100644 (file)
@@ -4296,22 +4296,22 @@ long_rshift(PyLongObject *a, PyLongObject *b)
         PyLongObject *a1, *a2;
         a1 = (PyLongObject *) long_invert(a);
         if (a1 == NULL)
-            goto rshift_error;
+            return NULL;
         a2 = (PyLongObject *) long_rshift(a1, b);
         Py_DECREF(a1);
         if (a2 == NULL)
-            goto rshift_error;
+            return NULL;
         z = (PyLongObject *) long_invert(a2);
         Py_DECREF(a2);
     }
     else {
         shiftby = PyLong_AsSsize_t((PyObject *)b);
         if (shiftby == -1L && PyErr_Occurred())
-            goto rshift_error;
+            return NULL;
         if (shiftby < 0) {
             PyErr_SetString(PyExc_ValueError,
                             "negative shift count");
-            goto rshift_error;
+            return NULL;
         }
         wordshift = shiftby / PyLong_SHIFT;
         newsize = Py_ABS(Py_SIZE(a)) - wordshift;
@@ -4323,19 +4323,15 @@ long_rshift(PyLongObject *a, PyLongObject *b)
         himask = PyLong_MASK ^ lomask;
         z = _PyLong_New(newsize);
         if (z == NULL)
-            goto rshift_error;
-        if (Py_SIZE(a) < 0)
-            Py_SIZE(z) = -(Py_SIZE(z));
+            return NULL;
         for (i = 0, j = wordshift; i < newsize; i++, j++) {
             z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask;
             if (i+1 < newsize)
                 z->ob_digit[i] |= (a->ob_digit[j+1] << hishift) & himask;
         }
-        z = long_normalize(z);
+        z = maybe_small_long(long_normalize(z));
     }
-  rshift_error:
-    return (PyObject *) maybe_small_long(z);
-
+    return (PyObject *)z;
 }
 
 static PyObject *