summaryrefslogtreecommitdiff
path: root/Programs
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-20 01:47:58 -0700
committerGitHub <noreply@github.com>2021-09-20 01:47:58 -0700
commit3d16fc90ce36acaa846ee88bdd124f84d49395b3 (patch)
tree0b1e3a20f89cf2941712f08c1859cc829953dd01 /Programs
parent697b6650ed29cdd4c347e9d35c43e084eff22c5f (diff)
downloadcpython-git-3d16fc90ce36acaa846ee88bdd124f84d49395b3.tar.gz
bpo-40413: test_embed tests calling Py_RunMain() multiple times (GH-28466)
Calling Py_InitializeFromConfig()+Py_RunMain() multiple times must not crash. Cleanup also test_get_argc_argv(). (cherry picked from commit 5e2c32e08ed77081cabd9d51f0589f81c1572732) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Programs')
-rw-r--r--Programs/_testembed.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index f8de6bc079..b7d4675a95 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1662,15 +1662,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");
@@ -1844,6 +1855,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