8000 gh-116664: In _warnings.c, make filters_version access thread-safe (#… · python/cpython@05e0b67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 05e0b67

Browse files
gh-116664: In _warnings.c, make filters_version access thread-safe (#117374)
- assert that the lock is held in already_warned() - protect 'filters_version' increment in warnings_filters_mutated_impl()
1 parent 019143f commit 05e0b67

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Python/_warnings.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key,
398398
return -1;
399399

400400
WarningsState *st = warnings_get_state(interp);
401-
if (st == NULL) {
402-
return -1;
403-
}
401+
assert(st != NULL);
402+
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&st->mutex);
403+
404404
PyObject *version_obj;
405405
if (PyDict_GetItemRef(registry, &_Py_ID(version), &version_obj) < 0) {
406406
return -1;
@@ -1177,11 +1177,14 @@ warnings_filters_mutated_impl(PyObject *module)
11771177
if (interp == NULL) {
11781178
return NULL;
11791179
}
1180+
11801181
WarningsState *st = warnings_get_state(interp);
1181-
if (st == NULL) {
1182-
return NULL;
1183-
}
1182+
assert(st != NULL);
1183+
1184+
Py_BEGIN_CRITICAL_SECTION_MUT(&st->mutex);
11841185
st->filters_version++;
1186+
Py_END_CRITICAL_SECTION();
1187+
11851188
Py_RETURN_NONE;
11861189
}
11871190

0 commit comments

Comments
 (0)
0