gh-107954, PEP 741: Adjust Python initialization config (#123663) · python/cpython@b423ae6 · GitHub
Skip to content

Commit b423ae6

Browse files
authored
gh-107954, PEP 741: Adjust Python initialization config (#123663)
Setting dev_mode to 1 in an isolated configuration now enables also faulthandler. Moreover, setting "module_search_paths" option with PyInitConfig_SetStrList() now sets "module_search_paths_set" to 1.
1 parent 7bd964d commit b423ae6

3 files changed

Lines changed: 43 additions & 16 deletions

File tree

Lib/test/test_embed.py

Lines changed: 0 additions & 1 deletion

Programs/_testembed.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,16 @@ static int test_init_set_config(void)
18061806
}
18071807

18081808

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+
18091819
static int test_initconfig_api(void)
18101820
{
18111821
PyInitConfig *config = PyInitConfig_Create();
@@ -1844,7 +1854,6 @@ static int test_initconfig_api(void)
18441854
goto error;
18451855
}
18461856

1847-
18481857
if (Py_InitializeFromInitConfig(config) < 0) {
18491858
goto error;
18501859
}
@@ -1876,38 +1885,51 @@ static int test_initconfig_get_api(void)
18761885
assert(PyInitConfig_HasOption(config, "non-existent") == 0);
18771886

18781887
// 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);
18821889
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);
18851891

18861892
// 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);
18891894
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);
18921896

18931897
// test PyInitConfig_GetStr()
18941898
char *str;
1899+
assert(PyInitConfig_GetStr(config, "program_name", &str) == 0);
1900+
assert(str == NULL);
18951901
assert(PyInitConfig_SetStr(config, "program_name", PROGRAM_NAME_UTF8) == 0);
18961902
assert(PyInitConfig_GetStr(config, "program_name", &str) == 0);
18971903
assert(strcmp(str, PROGRAM_NAME_UTF8) == 0);
18981904
free(str);
18991905

19001906
// 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+
19011912
char* xoptions[] = {"faulthandler"};
19021913
assert(PyInitConfig_SetStrList(config, "xoptions",
19031914
Py_ARRAY_LENGTH(xoptions), xoptions) == 0);
1904-
size_t length;
1905-
char **items;
1915+
19061916
assert(PyInitConfig_GetStrList(config, "xoptions", &length, &items) == 0);
19071917
assert(length == 1);
19081918
assert(strcmp(items[0], "faulthandler") == 0);
19091919
PyInitConfig_FreeStrList(length, items);
19101920

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+
19111933
return 0;
19121934
}
19131935

Python/initconfig.c

Lines changed: 9 additions & 3 deletions

0 commit comments

Comments
 (0)