FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-40413: test_embed tests calling Py_RunMain() multiple times by vstinner · Pull Request #28466 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions Lib/test/test_embed.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ def test_run_main(self):
self.assertEqual(out.rstrip(), "Py_RunMain(): sys.argv=['-c', 'arg2']")
self.assertEqual(err, '')

def test_run_main_loop(self):
# bpo-40413: Calling Py_InitializeFromConfig()+Py_RunMain() multiple
# times must not crash.
nloop = 5
out, err = self.run_embedded_interpreter("test_run_main_loop")
self.assertEqual(out, "Py_RunMain(): sys.argv=['-c', 'arg2']\n" * nloop)
self.assertEqual(err, '')


class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
maxDiff = 4096
Expand Down
20 changes: 16 additions & 4 deletions Programs/_testembed.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1676,15 +1676,26 @@ static int test_run_main(void)
}


static int test_run_main_loop(void)
{
// bpo-40413: Calling Py_InitializeFromConfig()+Py_RunMain() multiple
// times must not crash.
for (int i=0; i<5; i++) {
int exitcode = test_run_main();
if (exitcode != 0) {
return exitcode;
}
}
return 0;
}


static int test_get_argc_argv(void)
{
PyConfig config;
PyConfig_InitPythonConfig(&config);

wchar_t *argv[] = {L"python3", L"-c",
(L"import sys; "
L"print(f'Py_RunMain(): sys.argv={sys.argv}')"),
L"arg2"};
wchar_t *argv[] = {L"python3", L"-c", L"pass", L"arg2"};
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config_set_string(&config, &config.program_name, L"./python3");

Expand Down Expand Up @@ -1900,6 +1911,7 @@ static struct TestCase TestCases[] = {
{"test_init_warnoptions", test_init_warnoptions},
{"test_init_set_config", test_init_set_config},
{"test_run_main", test_run_main},
{"test_run_main_loop", test_run_main_loop},
{"test_get_argc_argv", test_get_argc_argv},

// Audit
Expand Down

Back | FazBrowse Home | New Git URL