@@ -1676,15 +1676,26 @@ static int test_run_main(void)
16761676}
16771677
16781678
1679+ static int test_run_main_loop (void )
1680+ {
1681+ // bpo-40413: Calling Py_InitializeFromConfig()+Py_RunMain() multiple
1682+ // times must not crash.
1683+ for (int i = 0 ; i < 5 ; i ++ ) {
1684+ int exitcode = test_run_main ();
1685+ if (exitcode != 0 ) {
1686+ return exitcode ;
1687+ }
1688+ }
1689+ return 0 ;
1690+ }
1691+
1692+
16791693static int test_get_argc_argv (void )
16801694{
16811695 PyConfig config ;
16821696 PyConfig_InitPythonConfig (& config );
16831697
1684- wchar_t * argv [] = {L"python3" , L"-c" ,
1685- (L"import sys; "
1686- L"print(f'Py_RunMain(): sys.argv={sys.argv}')" ),
1687- L"arg2" };
1698+ wchar_t * argv [] = {L"python3" , L"-c" , L"pass" , L"arg2" };
16881699 config_set_argv (& config , Py_ARRAY_LENGTH (argv ), argv );
16891700 config_set_string (& config , & config .program_name , L"./python3" );
16901701
@@ -1900,6 +1911,7 @@ static struct TestCase TestCases[] = {
19001911 {"test_init_warnoptions" , test_init_warnoptions },
19011912 {"test_init_set_config" , test_init_set_config },
19021913 {"test_run_main" , test_run_main },
1914+ {"test_run_main_loop" , test_run_main_loop },
19031915 {"test_get_argc_argv" , test_get_argc_argv },
19041916
19051917 // Audit
0 commit comments