Skip to content

Commit cdd01d2

Browse files
committed
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. ........
1 parent 22b2018 commit cdd01d2

1 file changed

Lines changed: 39 additions & 33 deletions

File tree

Objects/longobject.c

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ maybe_small_long(PyLongObject *v)
9595
#define MAX(x, y) ((x) < (y) ? (y) : (x))
9696
#define MIN(x, y) ((x) > (y) ? (y) : (x))
9797

98-
#define SIGCHECK(PyTryBlock) \
99-
if (PyErr_CheckSignals()) PyTryBlock \
98+
#define SIGCHECK(PyTryBlock) \
99+
do { \
100+
if (PyErr_CheckSignals()) PyTryBlock \
101+
} while(0)
100102

101103
/* Normalize (remove leading zeros from) a long int object.
102104
Doesn't attempt to free the storage--in most cases, due to the nature
@@ -1379,11 +1381,13 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
13791381

13801382
#endif /* HAVE_LONG_LONG */
13811383

1382-
#define CHECK_BINOP(v,w) \
1383-
if (!PyLong_Check(v) || !PyLong_Check(w)) { \
1384-
Py_INCREF(Py_NotImplemented); \
1385-
return Py_NotImplemented; \
1386-
}
1384+
#define CHECK_BINOP(v,w) \
1385+
do { \
1386+
if (!PyLong_Check(v) || !PyLong_Check(w)) { \
1387+
Py_INCREF(Py_NotImplemented); \
1388+
return Py_NotImplemented; \
1389+
} \
1390+
} while(0)
13871391

13881392
/* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d <
13891393
2**k if d is nonzero, else 0. */
@@ -1599,7 +1603,7 @@ long_to_decimal_string(PyObject *aa)
15991603
SIGCHECK({
16001604
Py_DECREF(scratch);
16011605
return NULL;
1602-
})
1606+
});
16031607
}
16041608
/* pout should have at least one digit, so that the case when a = 0
16051609
works correctly */
@@ -2274,7 +2278,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
22742278
Py_DECREF(v);
22752279
*prem = NULL;
22762280
return NULL;
2277-
})
2281+
});
22782282

22792283
/* estimate quotient digit q; may overestimate by 1 (rare) */
22802284
vtop = vk[size_w];
@@ -2768,7 +2772,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
27682772
SIGCHECK({
27692773
Py_DECREF(z);
27702774
return NULL;
2771-
})
2775+
});
27722776

27732777
carry = *pz + f * f;
27742778
*pz++ = (digit)(carry & PyLong_MASK);
@@ -2806,7 +2810,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
28062810
SIGCHECK({
28072811
Py_DECREF(z);
28082812
return NULL;
2809-
})
2813+
});
28102814

28112815
while (pb < pbend) {
28122816
carry += *pz + *pb++ * f;
@@ -3645,26 +3649,28 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
36453649
* is NULL.
36463650
*/
36473651
#define REDUCE(X) \
3648-
if (c != NULL) { \
3649-
if (l_divmod(X, c, NULL, &temp) < 0) \
3650-
goto Error; \
3651-
Py_XDECREF(X); \
3652-
X = temp; \
3653-
temp = NULL; \
3654-
}
3652+
do { \
3653+
if (c != NULL) { \
3654+
if (l_divmod(X, c, NULL, &temp) < 0) \
3655+
goto Error; \
3656+
Py_XDECREF(X); \
3657+
X = temp; \
3658+
temp = NULL; \
3659+
} \
3660+
} while(0)
36553661

36563662
/* Multiply two values, then reduce the result:
36573663
result = X*Y % c. If c is NULL, skip the mod. */
3658-
#define MULT(X, Y, result) \
3659-
{ \
3660-
temp = (PyLongObject *)long_mul(X, Y); \
3661-
if (temp == NULL) \
3662-
goto Error; \
3663-
Py_XDECREF(result); \
3664-
result = temp; \
3665-
temp = NULL; \
3666-
REDUCE(result) \
3667-
}
3664+
#define MULT(X, Y, result) \
3665+
do { \
3666+
temp = (PyLongObject *)long_mul(X, Y); \
3667+
if (temp == NULL) \
3668+
goto Error; \
3669+
Py_XDECREF(result); \
3670+
result = temp; \
3671+
temp = NULL; \
3672+
REDUCE(result); \
3673+
} while(0)
36683674

36693675
if (Py_SIZE(b) <= FIVEARY_CUTOFF) {
36703676
/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
@@ -3673,9 +3679,9 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
36733679
digit bi = b->ob_digit[i];
36743680

36753681
for (j = (digit)1 << (PyLong_SHIFT-1); j != 0; j >>= 1) {
3676-
MULT(z, z, z)
3682+
MULT(z, z, z);
36773683
if (bi & j)
3678-
MULT(z, a, z)
3684+
MULT(z, a, z);
36793685
}
36803686
}
36813687
}
@@ -3684,17 +3690,17 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
36843690
Py_INCREF(z); /* still holds 1L */
36853691
table[0] = z;
36863692
for (i = 1; i < 32; ++i)
3687-
MULT(table[i-1], a, table[i])
3693+
MULT(table[i-1], a, table[i]);
36883694

36893695
for (i = Py_SIZE(b) - 1; i >= 0; --i) {
36903696
const digit bi = b->ob_digit[i];
36913697

36923698
for (j = PyLong_SHIFT - 5; j >= 0; j -= 5) {
36933699
const int index = (bi >> j) & 0x1f;
36943700
for (k = 0; k < 5; ++k)
3695-
MULT(z, z, z)
3701+
MULT(z, z, z);
36963702
if (index)
3697-
MULT(z, table[index], z)
3703+
MULT(z, table[index], z);
36983704
}
36993705
}
37003706
}

0 commit comments

Comments
 (0)