https://github.com/python/cpython/commit/b20893b5c2dc999bbad5723c20f0ff2aea83a428 commit: b20893b5c2dc999bbad5723c20f0ff2aea83a428 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: kumaraditya303 <[email protected]> date: 2024-08-02T14:07:16Z summary:
[3.13] gh-122334: Fix crash when importing ssl after re-initialization (GH-122481) (#122614) gh-122334: Fix crash when importing ssl after re-initialization (GH-122481) * Fix crash when importing ssl after re-initialization (cherry picked from commit 9fc1c992d6fcea0b7558c581846eef6bdd811f6c) Co-authored-by: neonene <[email protected]> files: A Misc/NEWS.d/next/Library/2024-07-30-21-29-30.gh-issue-122334.LeoE1x.rst M Lib/test/test_embed.py M Python/getargs.c diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 9a63dbc3c6af37..19db79f8a161d5 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -460,6 +460,25 @@ def add(cls, slot, own): self.assertEqual(result, {}) self.assertEqual(out, '') + def test_getargs_reset_static_parser(self): + # Test _PyArg_Parser initializations via _PyArg_UnpackKeywords() + # https://github.com/python/cpython/issues/122334 + code = textwrap.dedent(""" + import _ssl + _ssl.txt2obj(txt='1.3') + print('1') + + import _queue + _queue.SimpleQueue().put_nowait(item=None) + print('2') + + import _zoneinfo + _zoneinfo.ZoneInfo.clear_cache(only_keys=['Foo/Bar']) + print('3') + """) + out, err = self.run_embedded_interpreter("test_repeated_init_exec", code) + self.assertEqual(out, '1\n2\n3\n' * INIT_LOOPS) + @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2024-07-30-21-29-30.gh-issue-122334.LeoE1x.rst b/Misc/NEWS.d/next/Library/2024-07-30-21-29-30.gh-issue-122334.LeoE1x.rst new file mode 100644 index 00000000000000..cef801c950faa6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-07-30-21-29-30.gh-issue-122334.LeoE1x.rst @@ -0,0 +1 @@ +Fix crash when importing :mod:`ssl` after the main interpreter restarts. diff --git a/Python/getargs.c b/Python/getargs.c index 0b272374e08b58..f40972f23e67af 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2004,6 +2004,19 @@ parser_clear(struct _PyArg_Parser *parser) if (parser->is_kwtuple_owned) { Py_CLEAR(parser->kwtuple); } + + if (parser->format) { + parser->fname = NULL; + } + else { + assert(parser->fname != NULL); + } + parser->custom_msg = NULL; + parser->pos = 0; + parser->min = 0; + parser->max = 0; + parser->is_kwtuple_owned = 0; + parser->once.v = 0; } static PyObject* _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
