@@ -1941,6 +1941,62 @@ static int test_initconfig_exit(void)
1941
1941
}
1942
1942
1943
1943
1944
+ static PyModuleDef_Slot extension_slots [] = {
1945
+ {Py_mod_gil , Py_MOD_GIL_NOT_USED },
1946
+ {0 , NULL }
1947
+ };
1948
+
1949
+ static struct PyModuleDef extension_module = {
1950
+ PyModuleDef_HEAD_INIT ,
1951
+ .m_name = "my_test_extension" ,
1952
+ .m_size = 0 ,
1953
+ .m_slots = extension_slots ,
1954
+ };
1955
+
1956
+ static PyObject * init_my_test_extension (void )
1957
+ {
1958
+ return PyModuleDef_Init (& extension_module );
1959
+ }
1960
+
1961
+
1962
+ static int test_initconfig_module (void )
1963
+ {
1964
+ PyInitConfig * config = PyInitConfig_Create ();
1965
+ if (config == NULL ) {
1966
+ printf ("Init allocation error\n" );
1967
+ return 1 ;
1968
+ }
1969
+
1970
+ if (PyInitConfig_SetStr (config , "program_name" , PROGRAM_NAME_UTF8 ) < 0 ) {
1971
+ goto error ;
1972
+ }
1973
+
1974
+ if (PyInitConfig_AddModule (config , "my_test_extension" ,
1975
+ init_my_test_extension ) < 0 ) {
1976
+ goto error ;
1977
+ }
1978
+
1979
+ if (Py_InitializeFromInitConfig (config ) < 0 ) {
1980
+ goto error ;
1981
+ }
1982
+ PyInitConfig_Free (config );
1983
+
1984
+ if (PyRun_SimpleString ("import my_test_extension" ) < 0 ) {
1985
+ fprintf (stderr , "unable to import my_test_extension\n" );
1986
+ exit (1 );
1987
+ }
1988
+
1989
+ Py_Finalize ();
1990
+ return 0 ;
1991
+
1992
+ const char * err_msg ;
1993
+ error :
1994
+ (void )PyInitConfig_GetError (config , & err_msg );
1995
+ printf ("Python init failed: %s\n" , err_msg );
1996
+ exit (1 );
1997
+ }
1998
+
1999
+
1944
2000
static void configure_init_main (PyConfig * config )
1945
2001
{
1946
2002
wchar_t * argv [] = {
@@ -2362,6 +2418,7 @@ static struct TestCase TestCases[] = {
2362
2418
{"test_initconfig_api" , test_initconfig_api },
2363
2419
{"test_initconfig_get_api" , test_initconfig_get_api },
2364
2420
{"test_initconfig_exit" , test_initconfig_exit },
2421
+ {"test_initconfig_module" , test_initconfig_module },
2365
2422
{"test_run_main" , test_run_main },
2366
2423
{"test_run_main_loop" , test_run_main_loop },
2367
2424
{"test_get_argc_argv" , test_get_argc_argv },
0 commit comments