Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

miss-islington
Copy link
Contributor

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

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 [email protected]

…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 <[email protected]>
zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
Copy link
Contributor

@rruuaanng rruuaanng Oct 14, 2024

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
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
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants