diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-03-29 20:23:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 20:23:28 (GMT) |
commit | 05e0b67a43c5c1778dc2643c8b7c12864e135999 (patch) | |
tree | cde3eb6d3c07a9251a8fb43f77f96a4e47e39851 /Python | |
parent | 019143fecbfc26e69800d28d2a9e3392a051780b (diff) | |
download | cpython-05e0b67a43c5c1778dc2643c8b7c12864e135999.zip cpython-05e0b67a43c5c1778dc2643c8b7c12864e135999.tar.gz cpython-05e0b67a43c5c1778dc2643c8b7c12864e135999.tar.bz2 |
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()
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index ac3d3cc..4c52025 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -398,9 +398,9 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, return -1; WarningsState *st = warnings_get_state(interp); - if (st == NULL) { - return -1; - } + assert(st != NULL); + _Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&st->mutex); + PyObject *version_obj; if (PyDict_GetItemRef(registry, &_Py_ID(version), &version_obj) < 0) { return -1; @@ -1177,11 +1177,14 @@ warnings_filters_mutated_impl(PyObject *module) if (interp == NULL) { return NULL; } + WarningsState *st = warnings_get_state(interp); - if (st == NULL) { - return NULL; - } + assert(st != NULL); + + Py_BEGIN_CRITICAL_SECTION_MUT(&st->mutex); st->filters_version++; + Py_END_CRITICAL_SECTION(); + Py_RETURN_NONE; } |