@@ -1806,6 +1806,16 @@ static int test_init_set_config(void)
1806
1806
}
1807
1807
1808
1808
1809
+ static int initconfig_getint (PyInitConfig * config , const char * name )
1810
+ {
1811
+ int64_t value ;
1812
+ int res = PyInitConfig_GetInt (config , name , & value );
1813
+ assert (res == 0 );
1814
+ assert (INT_MIN <= value && value <= INT_MAX );
1815
+ return (int )value ;
1816
+ }
1817
+
1818
+
1809
1819
static int test_initconfig_api (void )
1810
1820
{
1811
1821
PyInitConfig * config = PyInitConfig_Create ();
@@ -1844,7 +1854,6 @@ static int test_initconfig_api(void)
1844
1854
goto error ;
1845
1855
}
1846
1856
1847
-
1848
1857
if (Py_InitializeFromInitConfig (config ) < 0 ) {
1849
1858
goto error ;
1850
1859
}
@@ -1876,38 +1885,51 @@ static int test_initconfig_get_api(void)
1876
1885
assert (PyInitConfig_HasOption (config , "non-existent" ) == 0 );
1877
1886
1878
1887
// test PyInitConfig_GetInt()
1879
- int64_t value ;
1880
- assert (PyInitConfig_GetInt (config , "dev_mode" , & value ) == 0 );
1881
- assert (value == 0 );
1888
+ assert (initconfig_getint (config , "dev_mode" ) == 0 );
1882
1889
assert (PyInitConfig_SetInt (config , "dev_mode" , 1 ) == 0 );
1883
- assert (PyInitConfig_GetInt (config , "dev_mode" , & value ) == 0 );
1884
- assert (value == 1 );
1890
+ assert (initconfig_getint (config , "dev_mode" ) == 1 );
1885
1891
1886
1892
// test PyInitConfig_GetInt() on a PyPreConfig option
1887
- assert (PyInitConfig_GetInt (config , "utf8_mode" , & value ) == 0 );
1888
- assert (value == 0 );
1893
+ assert (initconfig_getint (config , "utf8_mode" ) == 0 );
1889
1894
assert (PyInitConfig_SetInt (config , "utf8_mode" , 1 ) == 0 );
1890
- assert (PyInitConfig_GetInt (config , "utf8_mode" , & value ) == 0 );
1891
- assert (value == 1 );
1895
+ assert (initconfig_getint (config , "utf8_mode" ) == 1 );
1892
1896
1893
1897
// test PyInitConfig_GetStr()
1894
1898
char * str ;
1899
+ assert (PyInitConfig_GetStr (config , "program_name" , & str ) == 0 );
1900
+ assert (str == NULL );
1895
1901
assert (PyInitConfig_SetStr (config , "program_name" , PROGRAM_NAME_UTF8 ) == 0 );
1896
1902
assert (PyInitConfig_GetStr (config , "program_name" , & str ) == 0 );
1897
1903
assert (strcmp (str , PROGRAM_NAME_UTF8 ) == 0 );
1898
1904
free (str );
1899
1905
1900
1906
// test PyInitConfig_GetStrList() and PyInitConfig_FreeStrList()
1907
+ size_t length ;
1908
+ char * * items ;
1909
+ assert (PyInitConfig_GetStrList (config , "xoptions" , & length , & items ) == 0 );
1910
+ assert (length == 0 );
1911
+
1901
1912
char * xoptions [] = {"faulthandler" };
1902
1913
assert (PyInitConfig_SetStrList (config , "xoptions" ,
1903
1914
Py_ARRAY_LENGTH (xoptions ), xoptions ) == 0 );
1904
- size_t length ;
1905
- char * * items ;
1915
+
1906
1916
assert (PyInitConfig_GetStrList (config , "xoptions" , & length , & items ) == 0 );
1907
1917
assert (length == 1 );
1908
1918
assert (strcmp (items [0 ], "faulthandler" ) == 0 );
1909
1919
PyInitConfig_FreeStrList (length , items );
1910
1920
1921
+ // Setting hash_seed sets use_hash_seed
1922
+ assert (initconfig_getint (config , "use_hash_seed" ) == 0 );
1923
+ assert (PyInitConfig_SetInt (config , "hash_seed" , 123 ) == 0 );
1924
+ assert (initconfig_getint (config , "use_hash_seed" ) == 1 );
1925
+
1926
+ // Setting module_search_paths sets module_search_paths_set
1927
+ assert (initconfig_getint (config , "module_search_paths_set" ) == 0 );
1928
+ char * paths [] = {"search" , "path" };
1929
+ assert (PyInitConfig_SetStrList (config , "module_search_paths" ,
1930
+ Py_ARRAY_LENGTH (paths ), paths ) == 0 );
1931
+ assert (initconfig_getint (config , "module_search_paths_set" ) == 1 );
1932
+
1911
1933
return 0 ;
1912
1934
}
1913
1935
0 commit comments