summaryrefslogtreecommitdiffstats
path: root/Python/coreconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-14 16:39:45 (GMT)
committerGitHub <noreply@github.com>2018-11-14 16:39:45 (GMT)
commit01de89cb59107d4f889aa503a1c0350dae4aebaf (patch)
tree1b0a002a18efdc053caed59e3c5805570f891449 /Python/coreconfig.c
parent64313478bcbd0a708c3ce5d4d14f977da56e4be9 (diff)
downloadcpython-01de89cb59107d4f889aa503a1c0350dae4aebaf.zip
cpython-01de89cb59107d4f889aa503a1c0350dae4aebaf.tar.gz
cpython-01de89cb59107d4f889aa503a1c0350dae4aebaf.tar.bz2
bpo-35233: InitConfigTests tests more config vars (GH-10541)
test_embed.InitConfigTests tests more configuration variables. Changes: * InitConfigTests tests more core configuration variables: * base_exec_prefix * base_prefix * exec_prefix * home * legacy_windows_fs_encoding * legacy_windows_stdio * module_search_path_env * prefix * "_testembed init_from_config" tests more variables: * argv * warnoptions * xoptions * InitConfigTests: add check_global_config(), check_core_config() and check_main_config() subfunctions to cleanup the code. Move also constants at the class level (ex: COPY_MAIN_CONFIG). * Fix _PyCoreConfig_AsDict(): don't set stdio_encoding twice * Use more macros in _PyCoreConfig_AsDict() and _PyMainInterpreterConfig_AsDict() to reduce code duplication. * Other minor cleanups.
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r--Python/coreconfig.c191
1 files changed, 76 insertions, 115 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index 3e547c5..a040a86 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1444,14 +1444,6 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
return NULL;
}
-#define FROM_STRING(STR) \
- ((STR != NULL) ? \
- PyUnicode_FromString(STR) \
- : (Py_INCREF(Py_None), Py_None))
-#define FROM_WSTRING(STR) \
- ((STR != NULL) ? \
- PyUnicode_FromWideChar(STR, -1) \
- : (Py_INCREF(Py_None), Py_None))
#define SET_ITEM(KEY, EXPR) \
do { \
obj = (EXPR); \
@@ -1464,117 +1456,81 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
goto fail; \
} \
} while (0)
-
- SET_ITEM("install_signal_handlers",
- PyLong_FromLong(config->install_signal_handlers));
- SET_ITEM("use_environment",
- PyLong_FromLong(config->use_environment));
- SET_ITEM("use_hash_seed",
- PyLong_FromLong(config->use_hash_seed));
- SET_ITEM("hash_seed",
- PyLong_FromUnsignedLong(config->hash_seed));
- SET_ITEM("allocator",
- FROM_STRING(config->allocator));
- SET_ITEM("dev_mode",
- PyLong_FromLong(config->dev_mode));
- SET_ITEM("faulthandler",
- PyLong_FromLong(config->faulthandler));
- SET_ITEM("tracemalloc",
- PyLong_FromLong(config->tracemalloc));
- SET_ITEM("import_time",
- PyLong_FromLong(config->import_time));
- SET_ITEM("show_ref_count",
- PyLong_FromLong(config->show_ref_count));
- SET_ITEM("show_alloc_count",
- PyLong_FromLong(config->show_alloc_count));
- SET_ITEM("dump_refs",
- PyLong_FromLong(config->dump_refs));
- SET_ITEM("malloc_stats",
- PyLong_FromLong(config->malloc_stats));
- SET_ITEM("coerce_c_locale",
- PyLong_FromLong(config->coerce_c_locale));
- SET_ITEM("coerce_c_locale_warn",
- PyLong_FromLong(config->coerce_c_locale_warn));
- SET_ITEM("filesystem_encoding",
- FROM_STRING(config->filesystem_encoding));
- SET_ITEM("filesystem_errors",
- FROM_STRING(config->filesystem_errors));
- SET_ITEM("stdio_encoding",
- FROM_STRING(config->stdio_encoding));
- SET_ITEM("utf8_mode",
- PyLong_FromLong(config->utf8_mode));
- SET_ITEM("pycache_prefix",
- FROM_WSTRING(config->pycache_prefix));
- SET_ITEM("program_name",
- FROM_WSTRING(config->program_name));
- SET_ITEM("argv",
- _Py_wstrlist_as_pylist(config->argc, config->argv));
- SET_ITEM("program",
- FROM_WSTRING(config->program));
- SET_ITEM("xoptions",
- _Py_wstrlist_as_pylist(config->nxoption, config->xoptions));
- SET_ITEM("warnoptions",
- _Py_wstrlist_as_pylist(config->nwarnoption, config->warnoptions));
- SET_ITEM("module_search_path_env",
- FROM_WSTRING(config->module_search_path_env));
- SET_ITEM("home",
- FROM_WSTRING(config->home));
- SET_ITEM("module_search_paths",
- _Py_wstrlist_as_pylist(config->nmodule_search_path, config->module_search_paths));
- SET_ITEM("executable",
- FROM_WSTRING(config->executable));
- SET_ITEM("prefix",
- FROM_WSTRING(config->prefix));
- SET_ITEM("base_prefix",
- FROM_WSTRING(config->base_prefix));
- SET_ITEM("exec_prefix",
- FROM_WSTRING(config->exec_prefix));
- SET_ITEM("base_exec_prefix",
- FROM_WSTRING(config->base_exec_prefix));
+#define FROM_STRING(STR) \
+ ((STR != NULL) ? \
+ PyUnicode_FromString(STR) \
+ : (Py_INCREF(Py_None), Py_None))
+#define SET_ITEM_INT(ATTR) \
+ SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR))
+#define SET_ITEM_UINT(ATTR) \
+ SET_ITEM(#ATTR, PyLong_FromUnsignedLong(config->ATTR))
+#define SET_ITEM_STR(ATTR) \
+ SET_ITEM(#ATTR, FROM_STRING(config->ATTR))
+#define FROM_WSTRING(STR) \
+ ((STR != NULL) ? \
+ PyUnicode_FromWideChar(STR, -1) \
+ : (Py_INCREF(Py_None), Py_None))
+#define SET_ITEM_WSTR(ATTR) \
+ SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR))
+#define SET_ITEM_WSTRLIST(NOPTION, OPTIONS) \
+ SET_ITEM(#OPTIONS, _Py_wstrlist_as_pylist(config->NOPTION, config->OPTIONS))
+
+ SET_ITEM_INT(install_signal_handlers);
+ SET_ITEM_INT(use_environment);
+ SET_ITEM_INT(use_hash_seed);
+ SET_ITEM_UINT(hash_seed);
+ SET_ITEM_STR(allocator);
+ SET_ITEM_INT(dev_mode);
+ SET_ITEM_INT(faulthandler);
+ SET_ITEM_INT(tracemalloc);
+ SET_ITEM_INT(import_time);
+ SET_ITEM_INT(show_ref_count);
+ SET_ITEM_INT(show_alloc_count);
+ SET_ITEM_INT(dump_refs);
+ SET_ITEM_INT(malloc_stats);
+ SET_ITEM_INT(coerce_c_locale);
+ SET_ITEM_INT(coerce_c_locale_warn);
+ SET_ITEM_STR(filesystem_encoding);
+ SET_ITEM_STR(filesystem_errors);
+ SET_ITEM_INT(utf8_mode);
+ SET_ITEM_WSTR(pycache_prefix);
+ SET_ITEM_WSTR(program_name);
+ SET_ITEM_WSTRLIST(argc, argv);
+ SET_ITEM_WSTR(program);
+ SET_ITEM_WSTRLIST(nxoption, xoptions);
+ SET_ITEM_WSTRLIST(nwarnoption, warnoptions);
+ SET_ITEM_WSTR(module_search_path_env);
+ SET_ITEM_WSTR(home);
+ SET_ITEM_WSTRLIST(nmodule_search_path, module_search_paths);
+ SET_ITEM_WSTR(executable);
+ SET_ITEM_WSTR(prefix);
+ SET_ITEM_WSTR(base_prefix);
+ SET_ITEM_WSTR(exec_prefix);
+ SET_ITEM_WSTR(base_exec_prefix);
#ifdef MS_WINDOWS
- SET_ITEM("dll_path",
- FROM_WSTRING(config->dll_path));
+ SET_ITEM_WSTR(dll_path);
#endif
- SET_ITEM("isolated",
- PyLong_FromLong(config->isolated));
- SET_ITEM("site_import",
- PyLong_FromLong(config->site_import));
- SET_ITEM("bytes_warning",
- PyLong_FromLong(config->bytes_warning));
- SET_ITEM("inspect",
- PyLong_FromLong(config->inspect));
- SET_ITEM("interactive",
- PyLong_FromLong(config->interactive));
- SET_ITEM("optimization_level",
- PyLong_FromLong(config->optimization_level));
- SET_ITEM("parser_debug",
- PyLong_FromLong(config->parser_debug));
- SET_ITEM("write_bytecode",
- PyLong_FromLong(config->write_bytecode));
- SET_ITEM("verbose",
- PyLong_FromLong(config->verbose));
- SET_ITEM("quiet",
- PyLong_FromLong(config->quiet));
- SET_ITEM("user_site_directory",
- PyLong_FromLong(config->user_site_directory));
- SET_ITEM("buffered_stdio",
- PyLong_FromLong(config->buffered_stdio));
- SET_ITEM("stdio_encoding",
- FROM_STRING(config->stdio_encoding));
- SET_ITEM("stdio_errors",
- FROM_STRING(config->stdio_errors));
+ SET_ITEM_INT(isolated);
+ SET_ITEM_INT(site_import);
+ SET_ITEM_INT(bytes_warning);
+ SET_ITEM_INT(inspect);
+ SET_ITEM_INT(interactive);
+ SET_ITEM_INT(optimization_level);
+ SET_ITEM_INT(parser_debug);
+ SET_ITEM_INT(write_bytecode);
+ SET_ITEM_INT(verbose);
+ SET_ITEM_INT(quiet);
+ SET_ITEM_INT(user_site_directory);
+ SET_ITEM_INT(buffered_stdio);
+ SET_ITEM_STR(stdio_encoding);
+ SET_ITEM_STR(stdio_errors);
#ifdef MS_WINDOWS
- SET_ITEM("legacy_windows_fs_encoding",
- PyLong_FromLong(config->legacy_windows_fs_encoding));
- SET_ITEM("legacy_windows_stdio",
- PyLong_FromLong(config->legacy_windows_stdio));
+ SET_ITEM_INT(legacy_windows_fs_encoding);
+ SET_ITEM_INT(legacy_windows_stdio);
#endif
- SET_ITEM("_install_importlib",
- PyLong_FromLong(config->_install_importlib));
- SET_ITEM("_check_hash_pycs_mode",
- FROM_STRING(config->_check_hash_pycs_mode));
- SET_ITEM("_frozen",
- PyLong_FromLong(config->_frozen));
+ SET_ITEM_INT(_install_importlib);
+ SET_ITEM_STR(_check_hash_pycs_mode);
+ SET_ITEM_INT(_frozen);
return dict;
@@ -1585,4 +1541,9 @@ fail:
#undef FROM_STRING
#undef FROM_WSTRING
#undef SET_ITEM
+#undef SET_ITEM_INT
+#undef SET_ITEM_UINT
+#undef SET_ITEM_STR
+#undef SET_ITEM_WSTR
+#undef SET_ITEM_WSTRLIST
}