Skip to content

Commit c5d97ae

Browse files
committed
Objects/dictobject.c: protect macros expansion via do { ... } while (0) constructions
1 parent 6a11d10 commit c5d97ae

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Objects/dictobject.c

+25-17
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,18 @@ ASSERT_DICT_LOCKED(PyObject *op)
154154
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
155155
}
156156
#define ASSERT_DICT_LOCKED(op) ASSERT_DICT_LOCKED(_Py_CAST(PyObject*, op))
157-
#define ASSERT_WORLD_STOPPED_OR_DICT_LOCKED(op) \
158-
if (!_PyInterpreterState_GET()->stoptheworld.world_stopped) { \
159-
ASSERT_DICT_LOCKED(op); \
160-
}
161-
#define ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(op) \
162-
if (!_PyInterpreterState_GET()->stoptheworld.world_stopped) { \
163-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op); \
164-
}
157+
#define ASSERT_WORLD_STOPPED_OR_DICT_LOCKED(OP) \
158+
do { \
159+
if (!_PyInterpreterState_GET()->stoptheworld.world_stopped) { \
160+
ASSERT_DICT_LOCKED(OP); \
161+
} \
162+
} while (0)
163+
#define ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(OP) \
164+
do { \
165+
if (!_PyInterpreterState_GET()->stoptheworld.world_stopped) { \
166+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(OP); \
167+
} \
168+
} while (0)
165169

166170
#define IS_DICT_SHARED(mp) _PyObject_GC_IS_SHARED(mp)
167171
#define SET_DICT_SHARED(mp) _PyObject_GC_SET_SHARED(mp)
@@ -170,15 +174,19 @@ ASSERT_DICT_LOCKED(PyObject *op)
170174
#define ASSERT_OWNED_OR_SHARED(mp) \
171175
assert(_Py_IsOwnedByCurrentThread((PyObject *)mp) || IS_DICT_SHARED(mp));
172176

173-
#define LOCK_KEYS_IF_SPLIT(keys, kind) \
174-
if (kind == DICT_KEYS_SPLIT) { \
175-
LOCK_KEYS(keys); \
176-
}
177-
178-
#define UNLOCK_KEYS_IF_SPLIT(keys, kind) \
179-
if (kind == DICT_KEYS_SPLIT) { \
180-
UNLOCK_KEYS(keys); \
181-
}
177+
#define LOCK_KEYS_IF_SPLIT(KEYS, KIND) \
178+
do { \
179+
if (KIND == DICT_KEYS_SPLIT) { \
180+
LOCK_KEYS(KEYS); \
181+
} \
182+
} while (0)
183+
184+
#define UNLOCK_KEYS_IF_SPLIT(KEYS, KIND) \
185+
do { \
186+
if (KIND == DICT_KEYS_SPLIT) { \
187+
UNLOCK_KEYS(KEYS); \
188+
} \
189+
} while (0)
182190

183191
static inline Py_ssize_t
184192
load_keys_nentries(PyDictObject *mp)

0 commit comments

Comments
 (0)