@@ -1963,6 +1963,62 @@ static int test_initconfig_exit(void)
19631963}
19641964
19651965
1966+ static PyModuleDef_Slot extension_slots [] = {
1967+ {Py_mod_gil , Py_MOD_GIL_NOT_USED },
1968+ {0 , NULL }
1969+ };
1970+
1971+ static struct PyModuleDef extension_module = {
1972+ PyModuleDef_HEAD_INIT ,
1973+ .m_name = "my_test_extension" ,
1974+ .m_size = 0 ,
1975+ .m_slots = extension_slots ,
1976+ };
1977+
1978+ static PyObject * init_my_test_extension (void )
1979+ {
1980+ return PyModuleDef_Init (& extension_module );
1981+ }
1982+
1983+
1984+ static int test_initconfig_module (void )
1985+ {
1986+ PyInitConfig * config = PyInitConfig_Create ();
1987+ if (config == NULL ) {
1988+ printf ("Init allocation error\n" );
1989+ return 1 ;
1990+ }
1991+
1992+ if (PyInitConfig_SetStr (config , "program_name" , PROGRAM_NAME_UTF8 ) < 0 ) {
1993+ goto error ;
1994+ }
1995+
1996+ if (PyInitConfig_AddModule (config , "my_test_extension" ,
1997+ init_my_test_extension ) < 0 ) {
1998+ goto error ;
1999+ }
2000+
2001+ if (Py_InitializeFromInitConfig (config ) < 0 ) {
2002+ goto error ;
2003+ }
2004+ PyInitConfig_Free (config );
2005+
2006+ if (PyRun_SimpleString ("import my_test_extension" ) < 0 ) {
2007+ fprintf (stderr , "unable to import my_test_extension\n" );
2008+ exit (1 );
2009+ }
2010+
2011+ Py_Finalize ();
2012+ return 0 ;
2013+
2014+ const char * err_msg ;
2015+ error :
2016+ (void )PyInitConfig_GetError (config , & err_msg );
2017+ printf ("Python init failed: %s\n" , err_msg );
2018+ exit (1 );
2019+ }
2020+
2021+
19662022static void configure_init_main (PyConfig * config )
19672023{
19682024 wchar_t * argv [] = {
@@ -2384,6 +2440,7 @@ static struct TestCase TestCases[] = {
23842440 {"test_initconfig_api" , test_initconfig_api },
23852441 {"test_initconfig_get_api" , test_initconfig_get_api },
23862442 {"test_initconfig_exit" , test_initconfig_exit },
2443+ {"test_initconfig_module" , test_initconfig_module },
23872444 {"test_run_main" , test_run_main },
23882445 {"test_run_main_loop" , test_run_main_loop },
23892446 {"test_get_argc_argv" , test_get_argc_argv },
0 commit comments