cpython/Tools/clinic
Eric Snow 81865002ae
gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across Interpreters (gh-119331)
_PyArg_Parser holds static global data generated for modules by Argument Clinic.  The _PyArg_Parser.kwtuple field is a tuple object, even though it's stored within a static global.  In some cases the tuple is statically allocated and thus it's okay that it gets shared by multiple interpreters.  However, in other cases the tuple is set lazily, allocated from the heap using the active interprepreter at the point the tuple is needed.

This is a problem once that interpreter is destroyed since _PyArg_Parser.kwtuple becomes at dangling pointer, leading to crashes.  It isn't a problem if the tuple is allocated under the main interpreter, since its lifetime is bound to the lifetime of the runtime.  The solution here is to temporarily switch to the main interpreter.  The alternative would be to always statically allocate the tuple.

This change also fixes a bug where only the most recent parser was added to the global linked list.
2024-05-22 09:57:52 -06:00
..
libclinic gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across Interpreters (gh-119331) 2024-05-22 09:57:52 -06:00
.ruff.toml Bump ruff to 0.2.0 (#114932) 2024-02-02 21:04:15 +00:00
clinic.py gh-113317: Finish splitting Argument Clinic into sub-files (#117513) 2024-04-04 11:09:40 +02:00
mypy.ini gh-104146: Argument clinic: Remove dead code flagged by mypy's `truthy-bool` check (#107627) 2023-08-04 13:28:13 +00:00