Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across Interpreters#119331
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f0f080bc288a7135abdade179765e6f78fbdbf113b9b73c3d6b9c4369157ad5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Non-builtin modules built with argument clinic were crashing if used in a | ||
| subinterpreter before the main interpreter. The objects that were causing | ||
| the problem by leaking between interpreters carelessly have been fixed. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ | ||
| #include "pycore_dict.h" // _PyDict_HasOnlyStringKeys() | ||
| #include "pycore_modsupport.h" // export _PyArg_NoKeywords() | ||
| #include "pycore_pylifecycle.h" // _PyArg_Fini | ||
| #include "pycore_pystate.h" // _Py_IsMainInterpreter() | ||
| #include "pycore_tuple.h" // _PyTuple_ITEMS() | ||
| #include "pycore_pyerrors.h" // _Py_CalculateSuggestions() | ||
| @@ -1947,7 +1948,23 @@ _parser_init(void *arg) | ||
| int owned; | ||
| PyObject *kwtuple = parser->kwtuple; | ||
| if (kwtuple == NULL){ | ||
| /* We may temporarily switch to the main interpreter to avoid | ||
| * creating a tuple that could outlive its owning interpreter. */ | ||
| PyThreadState *save_tstate = NULL; | ||
| PyThreadState *temp_tstate = NULL; | ||
| if (!_Py_IsMainInterpreter(PyInterpreterState_Get())){ | ||
| temp_tstate = PyThreadState_New(_PyInterpreterState_Main()); | ||
| if (temp_tstate == NULL){ | ||
| return -1; | ||
| } | ||
| save_tstate = PyThreadState_Swap(temp_tstate); | ||
| } | ||
| kwtuple = new_kwtuple(keywords, len, pos); | ||
| if (temp_tstate != NULL){ | ||
| PyThreadState_Clear(temp_tstate); | ||
| (void)PyThreadState_Swap(save_tstate); | ||
| PyThreadState_Delete(temp_tstate); | ||
| } | ||
| if (kwtuple == NULL){ | ||
| return -1; | ||
| } | ||
| @@ -1969,8 +1986,8 @@ _parser_init(void *arg) | ||
| parser->next = _Py_atomic_load_ptr(&_PyRuntime.getargs.static_parsers); | ||
| do{ | ||
| // compare-exchange updates parser->next on failure | ||
| } while (_Py_atomic_compare_exchange_ptr(&_PyRuntime.getargs.static_parsers, | ||
| &parser->next, parser)); | ||
| } while (!_Py_atomic_compare_exchange_ptr(&_PyRuntime.getargs.static_parsers, | ||
1st1 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| &parser->next, parser)); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is doing this before checking
if (kwtuple == NULL)the right way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we want to clean up the temporary tstate regardless of the outcome of
new_kwtuple().