bpo-34170: Add _PyCoreConfig.isolated by vstinner · Pull Request #8417 · python/cpython (original) (raw)
@ncoghlan, @ericsnowcurrently, @emilyemorehouse: OK, this PR should be big enhancement for the PEP 432 :-)
Previously, _PyCoreConfig "tried" to be isolated from Py_xxx global configuration variables like Py_IsolatedFlag. In practice, it already contained ignore_environment and utf8_mode which duplicated Py_IgnoreEnvironment and Py_UTF8Mode global configuration which can lead to inconsistency.
With this change, the priority becomes more explicit: _PyCoreConfig has now the priority over Py_xxx. To get a smooth transition, _PyCoreConfig are initialized to -1 which means "unset": in that case, the fields are initialized from Py_xxx.
Core config has the priority:
_PyCoreConfig config = _PyCoreConfig_INIT;
Py_UTF8Mode = 0; /* just for the example */
config.utf8_mode = 1; /* override Py_UTF8Mode */
Py_Initialize(&config);
# UTF-8 Mode enabled from config.utf8_mode
Backward compatibility:
_PyCoreConfig config = _PyCoreConfig_INIT;
Py_UTF8Mode = 1;
Py_Initialize(config);
# UTF-8 Mode enabled from Py_UTF8Mode
This change simplify and clarify main.c:
- Py_xxx variables are no longer modified when reading the configuration. Reading the configuration must no longer modify Python global variables: only local variables like pymain, config and cmdline
- Unset fields (set to -1) of config are now always initialized from Py_xxx
- Python initialization now always override Py_xxx from the config <= this part is now better defined