[Python-checkins] r81064 - in python/branches/py3k: Objects/longobject.c

mark.dickinson python-checkins at python.org
Mon May 10 23:37:34 CEST 2010


Author: mark.dickinson
Date: Mon May 10 23:37:34 2010
New Revision: 81064

Log:
Merged revisions 81037 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81037 | mark.dickinson | 2010-05-09 21:42:09 +0100 (Sun, 09 May 2010) | 1 line
  
  Wrap multiline macros in a 'do {} while(0)', for safety.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Objects/longobject.c

Modified: python/branches/py3k/Objects/longobject.c
==============================================================================
--- python/branches/py3k/Objects/longobject.c	(original)
+++ python/branches/py3k/Objects/longobject.c	Mon May 10 23:37:34 2010
@@ -95,8 +95,10 @@
 #define MAX(x, y) ((x) < (y) ? (y) : (x))
 #define MIN(x, y) ((x) > (y) ? (y) : (x))
 
-#define SIGCHECK(PyTryBlock) \
-    if (PyErr_CheckSignals()) PyTryBlock \
+#define SIGCHECK(PyTryBlock)                    \
+    do {                                        \
+        if (PyErr_CheckSignals()) PyTryBlock    \
+    } while(0)
 
 /* Normalize (remove leading zeros from) a long int object.
    Doesn't attempt to free the storage--in most cases, due to the nature
@@ -1379,11 +1381,13 @@
 
 #endif /* HAVE_LONG_LONG */
 
-#define CHECK_BINOP(v,w) \
-    if (!PyLong_Check(v) || !PyLong_Check(w)) { \
-        Py_INCREF(Py_NotImplemented); \
-        return Py_NotImplemented; \
-    }
+#define CHECK_BINOP(v,w)                                \
+    do {                                                \
+        if (!PyLong_Check(v) || !PyLong_Check(w)) {     \
+            Py_INCREF(Py_NotImplemented);               \
+            return Py_NotImplemented;                   \
+        }                                               \
+    } while(0)
 
 /* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d <
    2**k if d is nonzero, else 0. */
@@ -1599,7 +1603,7 @@
         SIGCHECK({
                 Py_DECREF(scratch);
                 return NULL;
-            })
+            });
     }
     /* pout should have at least one digit, so that the case when a = 0
        works correctly */
@@ -2274,7 +2278,7 @@
                 Py_DECREF(v);
                 *prem = NULL;
                 return NULL;
-            })
+            });
 
         /* estimate quotient digit q; may overestimate by 1 (rare) */
         vtop = vk[size_w];
@@ -2768,7 +2772,7 @@
             SIGCHECK({
                     Py_DECREF(z);
                     return NULL;
-                })
+                });
 
             carry = *pz + f * f;
             *pz++ = (digit)(carry & PyLong_MASK);
@@ -2806,7 +2810,7 @@
             SIGCHECK({
                     Py_DECREF(z);
                     return NULL;
-                })
+                });
 
             while (pb < pbend) {
                 carry += *pz + *pb++ * f;
@@ -3645,26 +3649,28 @@
      * is NULL.
      */
 #define REDUCE(X)                                       \
-    if (c != NULL) {                                    \
-        if (l_divmod(X, c, NULL, &temp) < 0)            \
-            goto Error;                                 \
-        Py_XDECREF(X);                                  \
-        X = temp;                                       \
-        temp = NULL;                                    \
-    }
+    do {                                                \
+        if (c != NULL) {                                \
+            if (l_divmod(X, c, NULL, &temp) < 0)        \
+                goto Error;                             \
+            Py_XDECREF(X);                              \
+            X = temp;                                   \
+            temp = NULL;                                \
+        }                                               \
+    } while(0)
 
     /* Multiply two values, then reduce the result:
        result = X*Y % c.  If c is NULL, skip the mod. */
-#define MULT(X, Y, result)                              \
-{                                                       \
-    temp = (PyLongObject *)long_mul(X, Y);              \
-    if (temp == NULL)                                   \
-        goto Error;                                     \
-    Py_XDECREF(result);                                 \
-    result = temp;                                      \
-    temp = NULL;                                        \
-    REDUCE(result)                                      \
-}
+#define MULT(X, Y, result)                      \
+    do {                                        \
+        temp = (PyLongObject *)long_mul(X, Y);  \
+        if (temp == NULL)                       \
+            goto Error;                         \
+        Py_XDECREF(result);                     \
+        result = temp;                          \
+        temp = NULL;                            \
+        REDUCE(result);                         \
+    } while(0)
 
     if (Py_SIZE(b) <= FIVEARY_CUTOFF) {
         /* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
@@ -3673,9 +3679,9 @@
             digit bi = b->ob_digit[i];
 
             for (j = (digit)1 << (PyLong_SHIFT-1); j != 0; j >>= 1) {
-                MULT(z, z, z)
+                MULT(z, z, z);
                 if (bi & j)
-                    MULT(z, a, z)
+                    MULT(z, a, z);
             }
         }
     }
@@ -3684,7 +3690,7 @@
         Py_INCREF(z);           /* still holds 1L */
         table[0] = z;
         for (i = 1; i < 32; ++i)
-            MULT(table[i-1], a, table[i])
+            MULT(table[i-1], a, table[i]);
 
         for (i = Py_SIZE(b) - 1; i >= 0; --i) {
             const digit bi = b->ob_digit[i];
@@ -3692,9 +3698,9 @@
             for (j = PyLong_SHIFT - 5; j >= 0; j -= 5) {
                 const int index = (bi >> j) & 0x1f;
                 for (k = 0; k < 5; ++k)
-                    MULT(z, z, z)
+                    MULT(z, z, z);
                 if (index)
-                    MULT(z, table[index], z)
+                    MULT(z, table[index], z);
             }
         }
     }


More information about the Python-checkins mailing list