summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2024-05-22 15:57:52 (GMT)
committerGitHub <noreply@github.com>2024-05-22 15:57:52 (GMT)
commit81865002aee8eaaeb3c7e402f86183afa6de77bf (patch)
treedde6add190311bdabf33093dd2ee3fd24ddf1ae5 /Tools/clinic
parentd472b4f9fa4fb6061588d421f33a0388a2005bc6 (diff)
downloadcpython-81865002aee8eaaeb3c7e402f86183afa6de77bf.zip
cpython-81865002aee8eaaeb3c7e402f86183afa6de77bf.tar.gz
cpython-81865002aee8eaaeb3c7e402f86183afa6de77bf.tar.bz2
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.
Diffstat (limited to 'Tools/clinic')
-rw-r--r--Tools/clinic/libclinic/parse_args.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py
index 905f2a0..7ac88bd 100644
--- a/Tools/clinic/libclinic/parse_args.py
+++ b/Tools/clinic/libclinic/parse_args.py
@@ -51,6 +51,8 @@ def declare_parser(
#endif
"""
else:
+ # XXX Why do we not statically allocate the tuple
+ # for non-builtin modules?
declarations = """
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)