diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-07-02 22:47:57 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-07-02 22:59:47 +0300 |
commit | 96b239778766d32d5158aca805e08199b3c0a743 (patch) | |
tree | a9c8679261a62138ec4735d878a11f6478cd196a /contrib/tools/python3/Python/getargs.c | |
parent | 292e7317266c2136a1e1bd027e16e6eefb639028 (diff) | |
download | ydb-96b239778766d32d5158aca805e08199b3c0a743.tar.gz |
Update contrib/tools/python3 to 3.12.4
6e8edffbef193b35b45ddccdc3beda6bb2627186
Diffstat (limited to 'contrib/tools/python3/Python/getargs.c')
-rw-r--r-- | contrib/tools/python3/Python/getargs.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/contrib/tools/python3/Python/getargs.c b/contrib/tools/python3/Python/getargs.c index 5e731cdc23..02bddf0618 100644 --- a/contrib/tools/python3/Python/getargs.c +++ b/contrib/tools/python3/Python/getargs.c @@ -4,6 +4,7 @@ #include "Python.h" #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "pycore_pylifecycle.h" // _PyArg_Fini +#include "pycore_pystate.h" // _Py_IsMainInterpreter() #include <ctype.h> #include <float.h> @@ -2002,7 +2003,23 @@ _parser_init(struct _PyArg_Parser *parser) 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 0; } |