diff options
author | Victor Stinner <vstinner@python.org> | 2024-09-04 10:58:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-04 10:58:32 (GMT) |
commit | b423ae6b0879ab1b53c6f517274c0d9e0f235d78 (patch) | |
tree | f43488fe34b2471309e36729343b80af55bf867e /Programs/_testembed.c | |
parent | 7bd964dbbe301059f3971b1be281bee0938bc70a (diff) | |
download | cpython-b423ae6b0879ab1b53c6f517274c0d9e0f235d78.zip cpython-b423ae6b0879ab1b53c6f517274c0d9e0f235d78.tar.gz cpython-b423ae6b0879ab1b53c6f517274c0d9e0f235d78.tar.bz2 |
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.
Diffstat (limited to 'Programs/_testembed.c')
-rw-r--r-- | Programs/_testembed.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 13f1db1..778da2f 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1806,6 +1806,16 @@ static int test_init_set_config(void) } +static int initconfig_getint(PyInitConfig *config, const char *name) +{ + int64_t value; + int res = PyInitConfig_GetInt(config, name, &value); + assert(res == 0); + assert(INT_MIN <= value && value <= INT_MAX); + return (int)value; +} + + static int test_initconfig_api(void) { PyInitConfig *config = PyInitConfig_Create(); @@ -1844,7 +1854,6 @@ static int test_initconfig_api(void) goto error; } - if (Py_InitializeFromInitConfig(config) < 0) { goto error; } @@ -1876,38 +1885,51 @@ static int test_initconfig_get_api(void) assert(PyInitConfig_HasOption(config, "non-existent") == 0); // test PyInitConfig_GetInt() - int64_t value; - assert(PyInitConfig_GetInt(config, "dev_mode", &value) == 0); - assert(value == 0); + assert(initconfig_getint(config, "dev_mode") == 0); assert(PyInitConfig_SetInt(config, "dev_mode", 1) == 0); - assert(PyInitConfig_GetInt(config, "dev_mode", &value) == 0); - assert(value == 1); + assert(initconfig_getint(config, "dev_mode") == 1); // test PyInitConfig_GetInt() on a PyPreConfig option - assert(PyInitConfig_GetInt(config, "utf8_mode", &value) == 0); - assert(value == 0); + assert(initconfig_getint(config, "utf8_mode") == 0); assert(PyInitConfig_SetInt(config, "utf8_mode", 1) == 0); - assert(PyInitConfig_GetInt(config, "utf8_mode", &value) == 0); - assert(value == 1); + assert(initconfig_getint(config, "utf8_mode") == 1); // test PyInitConfig_GetStr() char *str; + assert(PyInitConfig_GetStr(config, "program_name", &str) == 0); + assert(str == NULL); assert(PyInitConfig_SetStr(config, "program_name", PROGRAM_NAME_UTF8) == 0); assert(PyInitConfig_GetStr(config, "program_name", &str) == 0); assert(strcmp(str, PROGRAM_NAME_UTF8) == 0); free(str); // test PyInitConfig_GetStrList() and PyInitConfig_FreeStrList() + size_t length; + char **items; + assert(PyInitConfig_GetStrList(config, "xoptions", &length, &items) == 0); + assert(length == 0); + char* xoptions[] = {"faulthandler"}; assert(PyInitConfig_SetStrList(config, "xoptions", Py_ARRAY_LENGTH(xoptions), xoptions) == 0); - size_t length; - char **items; + assert(PyInitConfig_GetStrList(config, "xoptions", &length, &items) == 0); assert(length == 1); assert(strcmp(items[0], "faulthandler") == 0); PyInitConfig_FreeStrList(length, items); + // Setting hash_seed sets use_hash_seed + assert(initconfig_getint(config, "use_hash_seed") == 0); + assert(PyInitConfig_SetInt(config, "hash_seed", 123) == 0); + assert(initconfig_getint(config, "use_hash_seed") == 1); + + // Setting module_search_paths sets module_search_paths_set + assert(initconfig_getint(config, "module_search_paths_set") == 0); + char* paths[] = {"search", "path"}; + assert(PyInitConfig_SetStrList(config, "module_search_paths", + Py_ARRAY_LENGTH(paths), paths) == 0); + assert(initconfig_getint(config, "module_search_paths_set") == 1); + return 0; } |