[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5

victor.stinner python-checkins at python.org
Sat Sep 19 13:41:09 CEST 2015


https://hg.python.org/cpython/rev/3704cea9fd8e
changeset:   98071:3704cea9fd8e
parent:      98069:399746fde4f8
parent:      98070:21076e24cd8a
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Sep 19 13:39:16 2015 +0200
summary:
  Merge 3.5

files:
  Objects/longobject.c |  10 ++++++----
  1 files changed, 6 insertions(+), 4 deletions(-)


diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -4495,11 +4495,13 @@
 simple:
     assert(Py_REFCNT(a) > 0);
     assert(Py_REFCNT(b) > 0);
-#if LONG_MAX >> 2*PyLong_SHIFT
+/* Issue #24999: use two shifts instead of ">> 2*PyLong_SHIFT" to avoid
+   undefined behaviour when LONG_MAX type is smaller than 60 bits */
+#if LONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
     /* a fits into a long, so b must too */
     x = PyLong_AsLong((PyObject *)a);
     y = PyLong_AsLong((PyObject *)b);
-#elif defined(PY_LONG_LONG) && PY_LLONG_MAX >> 2*PyLong_SHIFT
+#elif defined(PY_LONG_LONG) && PY_LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
     x = PyLong_AsLongLong((PyObject *)a);
     y = PyLong_AsLongLong((PyObject *)b);
 #else
@@ -4516,9 +4518,9 @@
         y = x % y;
         x = t;
     }
-#if LONG_MAX >> 2*PyLong_SHIFT
+#if LONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
     return PyLong_FromLong(x);
-#elif defined(PY_LONG_LONG) && PY_LLONG_MAX >> 2*PyLong_SHIFT
+#elif defined(PY_LONG_LONG) && PY_LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
     return PyLong_FromLongLong(x);
 #else
 # error "_PyLong_GCD"

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list