Skip to content

Commit eed5b1f

Browse files
picnixznoahbkim
authored andcommitted
pythongh-119981: Use do while(0) in some symtable.c multi-line macros (python#119982)
1 parent 00dc8f7 commit eed5b1f

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

Python/symtable.c

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -601,16 +601,17 @@ error_at_directive(PySTEntryObject *ste, PyObject *name)
601601
global: set of all symbol names explicitly declared as global
602602
*/
603603

604-
#define SET_SCOPE(DICT, NAME, I) { \
605-
PyObject *o = PyLong_FromLong(I); \
606-
if (!o) \
607-
return 0; \
608-
if (PyDict_SetItem((DICT), (NAME), o) < 0) { \
604+
#define SET_SCOPE(DICT, NAME, I) \
605+
do { \
606+
PyObject *o = PyLong_FromLong(I); \
607+
if (!o) \
608+
return 0; \
609+
if (PyDict_SetItem((DICT), (NAME), o) < 0) { \
610+
Py_DECREF(o); \
611+
return 0; \
612+
} \
609613
Py_DECREF(o); \
610-
return 0; \
611-
} \
612-
Py_DECREF(o); \
613-
}
614+
} while(0)
614615

615616
/* Decide on scope of name, given flags.
616617
@@ -1562,39 +1563,45 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
15621563
return --(ST)->recursion_depth,(X)
15631564

15641565
#define VISIT(ST, TYPE, V) \
1565-
if (!symtable_visit_ ## TYPE((ST), (V))) \
1566-
VISIT_QUIT((ST), 0);
1567-
1568-
#define VISIT_SEQ(ST, TYPE, SEQ) { \
1569-
int i; \
1570-
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1571-
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1572-
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1573-
if (!symtable_visit_ ## TYPE((ST), elt)) \
1574-
VISIT_QUIT((ST), 0); \
1575-
} \
1576-
}
1577-
1578-
#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
1579-
int i; \
1580-
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1581-
for (i = (START); i < asdl_seq_LEN(seq); i++) { \
1582-
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1583-
if (!symtable_visit_ ## TYPE((ST), elt)) \
1584-
VISIT_QUIT((ST), 0); \
1585-
} \
1586-
}
1587-
1588-
#define VISIT_SEQ_WITH_NULL(ST, TYPE, SEQ) { \
1589-
int i = 0; \
1590-
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1591-
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1592-
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1593-
if (!elt) continue; /* can be NULL */ \
1594-
if (!symtable_visit_ ## TYPE((ST), elt)) \
1595-
VISIT_QUIT((ST), 0); \
1596-
} \
1597-
}
1566+
do { \
1567+
if (!symtable_visit_ ## TYPE((ST), (V))) { \
1568+
VISIT_QUIT((ST), 0); \
1569+
} \
1570+
} while(0)
1571+
1572+
#define VISIT_SEQ(ST, TYPE, SEQ) \
1573+
do { \
1574+
int i; \
1575+
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1576+
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1577+
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1578+
if (!symtable_visit_ ## TYPE((ST), elt)) \
1579+
VISIT_QUIT((ST), 0); \
1580+
} \
1581+
} while(0)
1582+
1583+
#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) \
1584+
do { \
1585+
int i; \
1586+
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1587+
for (i = (START); i < asdl_seq_LEN(seq); i++) { \
1588+
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1589+
if (!symtable_visit_ ## TYPE((ST), elt)) \
1590+
VISIT_QUIT((ST), 0); \
1591+
} \
1592+
} while(0)
1593+
1594+
#define VISIT_SEQ_WITH_NULL(ST, TYPE, SEQ) \
1595+
do { \
1596+
int i = 0; \
1597+
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
1598+
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1599+
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1600+
if (!elt) continue; /* can be NULL */ \
1601+
if (!symtable_visit_ ## TYPE((ST), elt)) \
1602+
VISIT_QUIT((ST), 0); \
1603+
} \
1604+
} while(0)
15981605

15991606
static int
16001607
symtable_record_directive(struct symtable *st, identifier name, int lineno,
@@ -2261,11 +2268,11 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
22612268
break;
22622269
case Slice_kind:
22632270
if (e->v.Slice.lower)
2264-
VISIT(st, expr, e->v.Slice.lower)
2271+
VISIT(st, expr, e->v.Slice.lower);
22652272
if (e->v.Slice.upper)
2266-
VISIT(st, expr, e->v.Slice.upper)
2273+
VISIT(st, expr, e->v.Slice.upper);
22672274
if (e->v.Slice.step)
2268-
VISIT(st, expr, e->v.Slice.step)
2275+
VISIT(st, expr, e->v.Slice.step);
22692276
break;
22702277
case Name_kind:
22712278
if (!symtable_add_def(st, e->v.Name.id,

0 commit comments

Comments
 (0)