#define _Py_CONFIG_VERSION 1
+typedef enum {
+ /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */
+ _PyConfig_INIT_COMPAT = 1,
+ _PyConfig_INIT_PYTHON = 2,
+ _PyConfig_INIT_ISOLATED = 3
+} _PyConfigInitEnum;
+
+
typedef struct {
int _config_version; /* Internal configuration version,
used for ABI compatibility */
+ int _config_init; /* _PyConfigInitEnum value */
/* Parse _Py_PreInitializeFromArgs() arguments?
See _PyCoreConfig.parse_argv */
Set to 0 by "-X utf8=0" and PYTHONUTF8=0.
If equals to -1, it is set to 1 if the LC_CTYPE locale is "C" or
- "POSIX", otherwise it is set to 0.
-
- If equals to -2, inherit Py_UTF8Mode value value (which is equal to 0
- by default). */
+ "POSIX", otherwise it is set to 0. Inherit Py_UTF8Mode value value. */
int utf8_mode;
int dev_mode; /* Development mode. PYTHONDEVMODE, -X dev */
/* --- _PyCoreConfig ---------------------------------------------- */
-typedef enum {
- _PyCoreConfig_INIT = 0,
- _PyCoreConfig_INIT_PYTHON = 1,
- _PyCoreConfig_INIT_ISOLATED = 2
-} _PyCoreConfigInitEnum;
-
typedef struct {
int _config_version; /* Internal configuration version,
used for ABI compatibility */
- int _config_init; /* _PyCoreConfigInitEnum value */
+ int _config_init; /* _PyConfigInitEnum value */
int isolated; /* Isolated mode? see _PyPreConfig.isolated */
int use_environment; /* Use environment variables? see _PyPreConfig.use_environment */
/* --- _PyPreConfig ----------------------------------------------- */
-PyAPI_FUNC(void) _PyPreConfig_Init(_PyPreConfig *config);
+PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(_PyPreConfig *config);
PyAPI_FUNC(void) _PyPreConfig_InitFromCoreConfig(
_PyPreConfig *config,
const _PyCoreConfig *coreconfig);
/* --- _PyCoreConfig ---------------------------------------------- */
-PyAPI_FUNC(void) _PyCoreConfig_Init(_PyCoreConfig *config);
+PyAPI_FUNC(void) _PyCoreConfig_InitCompatConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Copy(
_PyCoreConfig *config,
const _PyCoreConfig *config2);
MS_WINDOWS = (os.name == 'nt')
+
PYMEM_ALLOCATOR_NOT_SET = 0
PYMEM_ALLOCATOR_DEBUG = 2
PYMEM_ALLOCATOR_MALLOC = 3
-CONFIG_INIT = 0
-CONFIG_INIT_PYTHON = 1
-CONFIG_INIT_ISOLATED = 2
+# _PyCoreConfig_InitCompatConfig()
+API_COMPAT = 1
+# _PyCoreConfig_InitPythonConfig()
+API_PYTHON = 2
+# _PyCoreConfig_InitIsolatedConfig()
+API_ISOLATED = 3
class EmbeddingTestsMixin:
# Marker to ignore a configuration parameter
IGNORE_CONFIG = object()
- DEFAULT_PRE_CONFIG = {
+ PRE_CONFIG_COMPAT = {
'allocator': PYMEM_ALLOCATOR_NOT_SET,
'parse_argv': 0,
'configure_locale': 1,
'utf8_mode': 0,
}
if MS_WINDOWS:
- DEFAULT_PRE_CONFIG.update({
+ PRE_CONFIG_COMPAT.update({
'legacy_windows_fs_encoding': 0,
})
- PYTHON_PRE_CONFIG = dict(DEFAULT_PRE_CONFIG,
+ PRE_CONFIG_PYTHON = dict(PRE_CONFIG_COMPAT,
parse_argv=1,
coerce_c_locale=GET_DEFAULT_CONFIG,
utf8_mode=GET_DEFAULT_CONFIG,
)
- ISOLATED_PRE_CONFIG = dict(DEFAULT_PRE_CONFIG,
+ PRE_CONFIG_ISOLATED = dict(PRE_CONFIG_COMPAT,
configure_locale=0,
isolated=1,
use_environment=0,
'use_environment',
]
- DEFAULT_CORE_CONFIG = {
- '_config_init': CONFIG_INIT,
+ CORE_CONFIG_COMPAT = {
+ '_config_init': API_COMPAT,
'isolated': 0,
'use_environment': 1,
'dev_mode': 0,
'_init_main': 1,
}
if MS_WINDOWS:
- DEFAULT_CORE_CONFIG.update({
+ CORE_CONFIG_COMPAT.update({
'legacy_windows_stdio': 0,
})
- PYTHON_CORE_CONFIG = dict(DEFAULT_CORE_CONFIG,
+ CORE_CONFIG_PYTHON = dict(CORE_CONFIG_COMPAT,
configure_c_stdio=1,
parse_argv=1,
)
- ISOLATED_CORE_CONFIG = dict(DEFAULT_CORE_CONFIG,
+ CORE_CONFIG_ISOLATED = dict(CORE_CONFIG_COMPAT,
isolated=1,
use_environment=0,
user_site_directory=0,
pathconfig_warnings=0,
)
if MS_WINDOWS:
- ISOLATED_CORE_CONFIG['legacy_windows_stdio'] = 0
+ CORE_CONFIG_ISOLATED['legacy_windows_stdio'] = 0
# global config
DEFAULT_GLOBAL_CONFIG = {
if value is self.GET_DEFAULT_CONFIG:
expected_preconfig[key] = pre_config[key]
- if not expected_preconfig['configure_locale'] or api == CONFIG_INIT:
+ if not expected_preconfig['configure_locale'] or api == API_COMPAT:
# there is no easy way to get the locale encoding before
# setlocale(LC_CTYPE, "") is called: don't test encodings
for key in ('filesystem_encoding', 'filesystem_errors',
self.assertEqual(config['global_config'], expected)
- def check_config(self, testname, expected_config=None, expected_preconfig=None,
- add_path=None, stderr=None, api=CONFIG_INIT):
+ def check_config(self, testname, expected_config=None,
+ expected_preconfig=None, add_path=None, stderr=None,
+ *, api):
env = dict(os.environ)
# Remove PYTHON* environment variables to get deterministic environment
for key in list(env):
if key.startswith('PYTHON'):
del env[key]
- if api == CONFIG_INIT_ISOLATED:
- default_preconfig = self.ISOLATED_PRE_CONFIG
- elif api == CONFIG_INIT_PYTHON:
- default_preconfig = self.PYTHON_PRE_CONFIG
+ if api == API_ISOLATED:
+ default_preconfig = self.PRE_CONFIG_ISOLATED
+ elif api == API_PYTHON:
+ default_preconfig = self.PRE_CONFIG_PYTHON
else:
- default_preconfig = self.DEFAULT_PRE_CONFIG
+ default_preconfig = self.PRE_CONFIG_COMPAT
if expected_preconfig is None:
expected_preconfig = {}
expected_preconfig = dict(default_preconfig, **expected_preconfig)
if expected_config is None:
expected_config = {}
- if api == CONFIG_INIT_PYTHON:
- default_config = self.PYTHON_CORE_CONFIG
- elif api == CONFIG_INIT_ISOLATED:
- default_config = self.ISOLATED_CORE_CONFIG
+ if api == API_PYTHON:
+ default_config = self.CORE_CONFIG_PYTHON
+ elif api == API_ISOLATED:
+ default_config = self.CORE_CONFIG_ISOLATED
else:
- default_config = self.DEFAULT_CORE_CONFIG
+ default_config = self.CORE_CONFIG_COMPAT
expected_config = dict(default_config, **expected_config)
expected_config['_config_init'] = api
self.check_global_config(config)
def test_init_default_config(self):
- self.check_config("init_default_config", {}, {})
+ self.check_config("init_initialize_config", api=API_COMPAT)
+
+ def test_preinit_compat_config(self):
+ self.check_config("preinit_compat_config", api=API_COMPAT)
+
+ def test_init_compat_config(self):
+ self.check_config("init_compat_config", api=API_COMPAT)
def test_init_global_config(self):
preconfig = {
'user_site_directory': 0,
'pathconfig_warnings': 0,
}
- self.check_config("init_global_config", config, preconfig)
+ self.check_config("init_global_config", config, preconfig,
+ api=API_COMPAT)
def test_init_from_config(self):
preconfig = {
'check_hash_pycs_mode': 'always',
'pathconfig_warnings': 0,
}
- self.check_config("init_from_config", config, preconfig)
+ self.check_config("init_from_config", config, preconfig,
+ api=API_COMPAT)
def test_init_env(self):
preconfig = {
'allocator': PYMEM_ALLOCATOR_MALLOC,
+ 'utf8_mode': 1,
}
config = {
'use_hash_seed': 1,
'faulthandler': 1,
'warnoptions': ['EnvVar'],
}
- self.check_config("init_env", config, preconfig)
+ self.check_config("init_env", config, preconfig,
+ api=API_COMPAT)
def test_init_env_dev_mode(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_DEBUG)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
- self.check_config("init_env_dev_mode", config, preconfig)
+ self.check_config("init_env_dev_mode", config, preconfig,
+ api=API_COMPAT)
def test_init_env_dev_mode_alloc(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_MALLOC)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
- self.check_config("init_env_dev_mode_alloc", config, preconfig)
+ self.check_config("init_env_dev_mode_alloc", config, preconfig,
+ api=API_COMPAT)
def test_init_dev_mode(self):
preconfig = {
'warnoptions': ['default'],
}
self.check_config("init_dev_mode", config, preconfig,
- api=CONFIG_INIT_PYTHON)
+ api=API_PYTHON)
def test_preinit_parse_argv(self):
# Pre-initialize implicitly using argv: make sure that -X dev
'xoptions': ['dev'],
}
self.check_config("preinit_parse_argv", config, preconfig,
- api=CONFIG_INIT_PYTHON)
+ api=API_PYTHON)
def test_preinit_dont_parse_argv(self):
# -X dev must be ignored by isolated preconfiguration
'isolated': 0,
}
self.check_config("preinit_dont_parse_argv", config, preconfig,
- api=CONFIG_INIT_ISOLATED)
+ api=API_ISOLATED)
def test_init_isolated_flag(self):
config = {
'use_environment': 0,
'user_site_directory': 0,
}
- self.check_config("init_isolated_flag", config, api=CONFIG_INIT_PYTHON)
+ self.check_config("init_isolated_flag", config, api=API_PYTHON)
def test_preinit_isolated1(self):
# _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
'use_environment': 0,
'user_site_directory': 0,
}
- self.check_config("preinit_isolated1", config)
+ self.check_config("preinit_isolated1", config, api=API_COMPAT)
def test_preinit_isolated2(self):
# _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
'use_environment': 0,
'user_site_directory': 0,
}
- self.check_config("preinit_isolated2", config)
+ self.check_config("preinit_isolated2", config, api=API_COMPAT)
def test_preinit_isolated_config(self):
- self.check_config("preinit_isolated_config", api=CONFIG_INIT_ISOLATED)
+ self.check_config("preinit_isolated_config", api=API_ISOLATED)
def test_init_isolated_config(self):
- self.check_config("init_isolated_config", api=CONFIG_INIT_ISOLATED)
+ self.check_config("init_isolated_config", api=API_ISOLATED)
def test_init_python_config(self):
- self.check_config("init_python_config", api=CONFIG_INIT_PYTHON)
+ self.check_config("init_python_config", api=API_PYTHON)
def test_init_dont_configure_locale(self):
# _PyPreConfig.configure_locale=0
'coerce_c_locale': 0,
}
self.check_config("init_dont_configure_locale", {}, preconfig,
- api=CONFIG_INIT_PYTHON)
+ api=API_PYTHON)
def test_init_read_set(self):
core_config = {
'executable': 'my_executable',
}
self.check_config("init_read_set", core_config,
- api=CONFIG_INIT_PYTHON,
+ api=API_PYTHON,
add_path="init_read_set_path")
def test_init_run_main(self):
'run_command': code + '\n',
'parse_argv': 1,
}
- self.check_config("init_run_main", core_config,
- api=CONFIG_INIT_PYTHON)
+ self.check_config("init_run_main", core_config, api=API_PYTHON)
def test_init_main(self):
code = ('import _testinternalcapi, json; '
'_init_main': 0,
}
self.check_config("init_main", core_config,
- api=CONFIG_INIT_PYTHON,
+ api=API_PYTHON,
stderr="Run Python code before _Py_InitializeMain")
def test_init_parse_argv(self):
'run_command': 'pass\n',
'use_environment': 0,
}
- self.check_config("init_parse_argv", core_config,
- api=CONFIG_INIT_PYTHON)
+ self.check_config("init_parse_argv", core_config, api=API_PYTHON)
def test_init_dont_parse_argv(self):
pre_config = {
'program_name': './argv0',
}
self.check_config("init_dont_parse_argv", core_config, pre_config,
- api=CONFIG_INIT_PYTHON)
+ api=API_PYTHON)
if __name__ == "__main__":
}
text[text_size] = '\0';
+ _PyInitError err;
_PyCoreConfig config;
- _PyCoreConfig_InitIsolatedConfig(&config);
+
+ err = _PyCoreConfig_InitIsolatedConfig(&config);
+ if (_PyInitError_Failed(err)) {
+ _PyCoreConfig_Clear(&config);
+ _Py_ExitInitError(err);
+ }
config.site_import = 0;
- config.program_name = L"./_freeze_importlib";
+
+ err = _PyCoreConfig_SetString(&config, &config.program_name,
+ L"./_freeze_importlib");
+ if (_PyInitError_Failed(err)) {
+ _PyCoreConfig_Clear(&config);
+ _Py_ExitInitError(err);
+ }
+
/* Don't install importlib, since it could execute outdated bytecode. */
config._install_importlib = 0;
config._init_main = 0;
- _PyInitError err = _Py_InitializeFromConfig(&config);
- /* No need to call _PyCoreConfig_Clear() since we didn't allocate any
- memory: program_name is a constant string. */
+ err = _Py_InitializeFromConfig(&config);
+ _PyCoreConfig_Clear(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
}
}
-static int test_init_default_config(void)
+static int test_init_initialize_config(void)
{
_testembed_Py_Initialize();
dump_config();
}
+static int check_init_compat_config(int preinit)
+{
+ _PyInitError err;
+
+ if (preinit) {
+ _PyPreConfig preconfig;
+ _PyPreConfig_InitCompatConfig(&preconfig);
+
+ err = _Py_PreInitialize(&preconfig);
+ if (_PyInitError_Failed(err)) {
+ _Py_ExitInitError(err);
+ }
+ }
+
+ _PyCoreConfig config;
+ _PyCoreConfig_InitCompatConfig(&config);
+ config.program_name = L"./_testembed";
+
+ err = _Py_InitializeFromConfig(&config);
+ if (_PyInitError_Failed(err)) {
+ _Py_ExitInitError(err);
+ }
+
+ dump_config();
+ Py_Finalize();
+ return 0;
+}
+
+
+static int test_preinit_compat_config(void)
+{
+ return check_init_compat_config(1);
+}
+
+
+static int test_init_compat_config(void)
+{
+ return check_init_compat_config(0);
+}
+
+
static int test_init_global_config(void)
{
/* FIXME: test Py_IgnoreEnvironmentFlag */
_PyInitError err;
_PyPreConfig preconfig;
- _PyPreConfig_Init(&preconfig);
+ _PyPreConfig_InitCompatConfig(&preconfig);
putenv("PYTHONMALLOC=malloc_debug");
preconfig.allocator = PYMEM_ALLOCATOR_MALLOC;
/* Test _Py_InitializeFromConfig() */
_PyCoreConfig config;
- _PyCoreConfig_Init(&config);
+ _PyCoreConfig_InitCompatConfig(&config);
config.install_signal_handlers = 0;
/* FIXME: test use_environment */
_PyInitError err;
_PyPreConfig preconfig;
- _PyPreConfig_Init(&preconfig);
+ _PyPreConfig_InitCompatConfig(&preconfig);
preconfig.isolated = 1;
err = _Py_PreInitialize(&preconfig);
}
_PyCoreConfig config;
- _PyCoreConfig_Init(&config);
+ _PyCoreConfig_InitCompatConfig(&config);
config.program_name = L"./_testembed";
set_all_env_vars();
_PyInitError err;
_PyPreConfig preconfig;
- _PyPreConfig_Init(&preconfig);
+ _PyPreConfig_InitCompatConfig(&preconfig);
preconfig.isolated = 0;
err = _Py_PreInitialize(&preconfig);
/* Test _PyCoreConfig.isolated=1 */
_PyCoreConfig config;
- _PyCoreConfig_Init(&config);
+ _PyCoreConfig_InitCompatConfig(&config);
Py_IsolatedFlag = 0;
config.isolated = 1;
_PyCoreConfig config;
err = _PyCoreConfig_InitIsolatedConfig(&config);
if (_PyInitError_Failed(err)) {
+ _PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
}
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
+ _PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
}
{ "bpo20891", test_bpo20891 },
{ "initialize_twice", test_initialize_twice },
{ "initialize_pymain", test_initialize_pymain },
- { "init_default_config", test_init_default_config },
+ { "init_initialize_config", test_init_initialize_config },
+ { "preinit_compat_config", test_preinit_compat_config },
+ { "init_compat_config", test_init_compat_config },
{ "init_global_config", test_init_global_config },
{ "init_from_config", test_init_from_config },
{ "init_parse_argv", test_init_parse_argv },
/* UTF-8 mode (PEP 540): if equals to 1, use the UTF-8 encoding, and change
stdin and stdout error handler to "surrogateescape". It is equal to
-1 by default: unknown, will be set by Py_Main() */
-int Py_UTF8Mode = 0;
+int Py_UTF8Mode = -1;
int Py_DebugFlag = 0; /* Needed by parser.c */
int Py_VerboseFlag = 0; /* Needed by import.c */
int Py_QuietFlag = 0; /* Needed by sysmodule.c */
void
-_PyCoreConfig_Init(_PyCoreConfig *config)
+_PyCoreConfig_InitCompatConfig(_PyCoreConfig *config)
{
memset(config, 0, sizeof(*config));
config->_config_version = _Py_CONFIG_VERSION;
- config->_config_init = (int)_PyCoreConfig_INIT;
+ config->_config_init = (int)_PyConfig_INIT_COMPAT;
config->isolated = -1;
config->use_environment = -1;
config->dev_mode = -1;
static void
_PyCoreConfig_InitDefaults(_PyCoreConfig *config)
{
- _PyCoreConfig_Init(config);
+ _PyCoreConfig_InitCompatConfig(config);
config->isolated = 0;
config->use_environment = 1;
{
_PyCoreConfig_InitDefaults(config);
- config->_config_init = (int)_PyCoreConfig_INIT_PYTHON;
+ config->_config_init = (int)_PyConfig_INIT_PYTHON;
config->configure_c_stdio = 1;
config->parse_argv = 1;
{
_PyCoreConfig_InitDefaults(config);
- config->_config_init = (int)_PyCoreConfig_INIT_ISOLATED;
+ config->_config_init = (int)_PyConfig_INIT_ISOLATED;
config->isolated = 1;
config->use_environment = 0;
config->user_site_directory = 0;
static void
_PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
{
+ if (config->_config_init != _PyConfig_INIT_COMPAT) {
+ /* Python and Isolated configuration ignore global variables */
+ return;
+ }
+
#define COPY_FLAG(ATTR, VALUE) \
if (config->ATTR == -1) { \
config->ATTR = VALUE; \
}
_PyCoreConfig config;
- _PyCoreConfig_InitPythonConfig(&config);
+ err = _PyCoreConfig_InitPythonConfig(&config);
+ if (_PyInitError_Failed(err)) {
+ _PyCoreConfig_Clear(&config);
+ _Py_ExitInitError(err);
+ }
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
Py_SetProgramName(argv_copy[0]);
err = _Py_InitializeFromConfig(&config);
- /* No need to call _PyCoreConfig_Clear() since we didn't allocate any
- memory: program_name is a constant string. */
+ _PyCoreConfig_Clear(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
}
_PyInitError err;
_PyCoreConfig config;
- _PyCoreConfig_Init(&config);
+ _PyCoreConfig_InitCompatConfig(&config);
err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) {
void
-_PyPreConfig_Init(_PyPreConfig *config)
+_PyPreConfig_InitCompatConfig(_PyPreConfig *config)
{
memset(config, 0, sizeof(*config));
config->_config_version = _Py_CONFIG_VERSION;
+ config->_config_init = (int)_PyConfig_INIT_COMPAT;
config->parse_argv = 0;
config->isolated = -1;
config->use_environment = -1;
config->configure_locale = 1;
- config->utf8_mode = -2;
+ config->utf8_mode = -1;
config->dev_mode = -1;
config->allocator = PYMEM_ALLOCATOR_NOT_SET;
#ifdef MS_WINDOWS
void
_PyPreConfig_InitPythonConfig(_PyPreConfig *config)
{
- _PyPreConfig_Init(config);
+ _PyPreConfig_InitCompatConfig(config);
+ config->_config_init = (int)_PyConfig_INIT_PYTHON;
+ config->isolated = 0;
config->parse_argv = 1;
+ config->use_environment = 1;
/* Set to -1 to enable C locale coercion (PEP 538) and UTF-8 Mode (PEP 540)
depending on the LC_CTYPE locale, PYTHONUTF8 and PYTHONCOERCECLOCALE
environment variables. */
config->coerce_c_locale = -1;
config->coerce_c_locale_warn = -1;
config->utf8_mode = -1;
+#ifdef MS_WINDOWS
+ config->legacy_windows_fs_encoding = 0;
+#endif
}
void
_PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
{
- _PyPreConfig_Init(config);
+ _PyPreConfig_InitCompatConfig(config);
+ config->_config_init = (int)_PyConfig_INIT_ISOLATED;
config->configure_locale = 0;
config->isolated = 1;
config->use_environment = 0;
_PyPreConfig_InitFromPreConfig(_PyPreConfig *config,
const _PyPreConfig *config2)
{
- _PyPreConfig_Init(config);
+ _PyPreConfig_InitCompatConfig(config);
_PyPreConfig_Copy(config, config2);
}
_PyPreConfig_InitFromCoreConfig(_PyPreConfig *config,
const _PyCoreConfig *coreconfig)
{
- _PyCoreConfigInitEnum config_init = (_PyCoreConfigInitEnum)coreconfig->_config_init;
+ _PyConfigInitEnum config_init = (_PyConfigInitEnum)coreconfig->_config_init;
switch (config_init) {
- case _PyCoreConfig_INIT_PYTHON:
+ case _PyConfig_INIT_PYTHON:
_PyPreConfig_InitPythonConfig(config);
break;
- case _PyCoreConfig_INIT_ISOLATED:
+ case _PyConfig_INIT_ISOLATED:
_PyPreConfig_InitIsolatedConfig(config);
break;
- case _PyCoreConfig_INIT:
+ case _PyConfig_INIT_COMPAT:
default:
- _PyPreConfig_Init(config);
+ _PyPreConfig_InitCompatConfig(config);
}
_PyPreConfig_GetCoreConfig(config, coreconfig);
}
static void
_PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
{
+ if (config->_config_init != _PyConfig_INIT_COMPAT) {
+ /* Python and Isolated configuration ignore global variables */
+ return;
+ }
+
#define COPY_FLAG(ATTR, VALUE) \
if (config->ATTR < 0) { \
config->ATTR = VALUE; \
COPY_FLAG(isolated, Py_IsolatedFlag);
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
+ COPY_FLAG(utf8_mode, Py_UTF8Mode);
#ifdef MS_WINDOWS
COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag);
#endif
- if (config->utf8_mode == -2) {
- config->utf8_mode = Py_UTF8Mode;
- }
#undef COPY_FLAG
#undef COPY_NOT_FLAG
}
const wchar_t *xopt;
- if (cmdline) {
- xopt = _Py_get_xoption(&cmdline->xoptions, L"utf8");
- }
- else {
- xopt = NULL;
- }
+ xopt = _Py_get_xoption(&cmdline->xoptions, L"utf8");
if (xopt) {
wchar_t *sep = wcschr(xopt, L'=');
if (sep) {
}
_PyCoreConfig local_config;
- _PyCoreConfig_Init(&local_config);
+ _PyCoreConfig_InitCompatConfig(&local_config);
err = pyinit_coreconfig(runtime, &local_config, src_config, args, interp_p);
_PyCoreConfig_Clear(&local_config);
return err;
}
_PyCoreConfig config;
- _PyCoreConfig_Init(&config);
+ _PyCoreConfig_InitCompatConfig(&config);
config.install_signal_handlers = install_sigs;
err = _Py_InitializeFromConfig(&config);
_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
- _PyPreConfig_Init(&runtime->preconfig);
+ _PyPreConfig_InitPythonConfig(&runtime->preconfig);
runtime->gilstate.check_enabled = 1;
memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1;
interp->check_interval = 100;
- _PyCoreConfig_Init(&interp->core_config);
+
+ _PyInitError err = _PyCoreConfig_InitPythonConfig(&interp->core_config);
+ if (_Py_INIT_FAILED(err)) {
+ PyMem_RawFree(interp);
+ return NULL;
+ }
+
interp->eval_frame = _PyEval_EvalFrameDefault;
#ifdef HAVE_DLOPEN
#if HAVE_DECL_RTLD_NOW