@@ -1963,6 +1963,62 @@ static int test_initconfig_exit(void)
1963
1963
}
1964
1964
1965
1965
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
+
1966
2022
static void configure_init_main (PyConfig * config )
1967
2023
{
1968
2024
wchar_t * argv [] = {
@@ -2384,6 +2440,7 @@ static struct TestCase TestCases[] = {
2384
2440
{"test_initconfig_api" , test_initconfig_api },
2385
2441
{"test_initconfig_get_api" , test_initconfig_get_api },
2386
2442
{"test_initconfig_exit" , test_initconfig_exit },
2443
+ {"test_initconfig_module" , test_initconfig_module },
2387
2444
{"test_run_main" , test_run_main },
2388
2445
{"test_run_main_loop" , test_run_main_loop },
2389
2446
{"test_get_argc_argv" , test_get_argc_argv },
0 commit comments