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

gh-116664: Ensure thread-safe dict access in _warnings #116768

Merged

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Mar 13, 2024

Replace _PyDict_GetItemWithError() with PyDict_GetItemRef().

*module = PyUnicode_FromString("<string>");
if (*module == NULL)
goto handle_error;
}
else {
assert(Py_IsNone(*module) || PyUnicode_Check(*module));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to handle the case where *module (i.e., __name__) is not None and not a unicode object because Python code can set __name__ arbitrarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4f3cd02 should fix that case:

If None or a unicode object, return successfully; else decref and fall through to the no-key case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note, there is no test case for this in the test suite.

@erlend-aasland erlend-aasland enabled auto-merge (squash) March 18, 2024 09:10
@erlend-aasland
Copy link
Contributor Author

Thanks for the review!

@erlend-aasland erlend-aasland merged commit 762f489 into python:main Mar 18, 2024
33 of 34 checks passed
@erlend-aasland erlend-aasland deleted the nogil/warnings-dict-getitem branch March 18, 2024 09:37
vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 20, 2024
…116768)

Replace _PyDict_GetItemWithError() with PyDict_GetItemRef().
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…116768)

Replace _PyDict_GetItemWithError() with PyDict_GetItemRef().
@erlend-aasland erlend-aasland linked an issue Mar 28, 2024 that may be closed by this pull request
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…116768)

Replace _PyDict_GetItemWithError() with PyDict_GetItemRef().
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.

Make _warnings.c thread-safe in free-threaded build
2 participants