Skip to content
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

[3.13] gh-122334: Fix crash when importing ssl after re-initialization (GH-122481) #122614

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when importing :mod:`ssl` after the main interpreter restarts.
13 changes: 13 additions & 0 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
Loading