Skip to content

[3.13] gh-125243: Fix ZoneInfo data race in free threading build (GH-125281) - #125414

Merged
colesbury merged 1 commit into
python:3.13from
miss-islington:backport-f1d33db-3.13
Oct 15, 2024
Merged

colesbury merged 1 commit into
python:3.13from
miss-islington:backport-f1d33db-3.13

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 13, 2024 •

Copy link
Copy Markdown
Contributor

Lock ZoneInfoType to protect accesses to ZONEINFO_STRONG_CACHE.
Refactor the tp_new handler to use Argument Clinic so that we can just
use @critical_section annotations on the relevant functions.

Also use PyDict_SetDefaultRef instead of PyDict_SetDefault when
inserting into the TIMEDELTA_CACHE.
(cherry picked from commit f1d33db)

Co-authored-by: Sam Gross colesbury@gmail.com

…onGH-125281)

Lock `ZoneInfoType` to protect accesses to `ZONEINFO_STRONG_CACHE`.
Refactor the `tp_new` handler to use Argument Clinic so that we can just
use `@critical_section` annotations on the relevant functions.

Also use `PyDict_SetDefaultRef` instead of `PyDict_SetDefault` when
inserting into the `TIMEDELTA_CACHE`.
(cherry picked from commit f1d33db)

Co-authored-by: Sam Gross <colesbury@gmail.com>
zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)

@rruuaanng rruuaanng Oct 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Preprocessing maybe placed in the first column. This allows you to keep your style consistent with the other extension modules.
for example:

#ifdef __APPLE__
// gh-98178: On macOS, libc syslog() is not thread-safe
syslog(priority, "%s", message);
#else
Py_BEGIN_ALLOW_THREADS;
syslog(priority, "%s", message);
Py_END_ALLOW_THREADS;
#endif
Py_XDECREF(ident);
Py_RETURN_NONE;
}

zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
    PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a generated file

@colesbury
colesbury merged commit 6474e29 into python:3.13 Oct 15, 2024
@miss-islington
miss-islington deleted the backport-f1d33db-3.13 branch January 2, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants