bpo-36142: Add _PyPreConfig structure by vstinner · Pull Request #12172 · python/cpython
#define CLEAR(ATTR) \ do { \ PyMem_RawFree(ATTR); \
if (_PyPreConfig_Copy(&config->preconfig, &config2->preconfig) < 0) { return -1; }
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR #define COPY_STR_ATTR(ATTR) \ do { \
COPY_ATTR(install_signal_handlers); COPY_ATTR(use_environment); COPY_ATTR(use_hash_seed); COPY_ATTR(hash_seed); COPY_ATTR(_install_importlib);
COPY_ATTR(isolated); COPY_ATTR(site_import); COPY_ATTR(bytes_warning); COPY_ATTR(inspect);
if (!config->use_environment) { if (!config->preconfig.use_environment) { return NULL; }
if (!config->use_environment) { if (!config->preconfig.use_environment) { *dest = NULL; return 0; }
#define COPY_FLAG(ATTR, VALUE) \ if (config->ATTR == -1) { \ config->ATTR = VALUE; \
COPY_FLAG(utf8_mode, Py_UTF8Mode); COPY_FLAG(isolated, Py_IsolatedFlag); COPY_FLAG(bytes_warning, Py_BytesWarningFlag); COPY_FLAG(inspect, Py_InspectFlag); COPY_FLAG(interactive, Py_InteractiveFlag);
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); COPY_NOT_FLAG(buffered_stdio, Py_UnbufferedStdioFlag); COPY_NOT_FLAG(site_import, Py_NoSiteFlag); COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
#define COPY_FLAG(ATTR, VAR) \ if (config->ATTR != -1) { \ VAR = config->ATTR; \
COPY_FLAG(utf8_mode, Py_UTF8Mode); COPY_FLAG(isolated, Py_IsolatedFlag); COPY_FLAG(bytes_warning, Py_BytesWarningFlag); COPY_FLAG(inspect, Py_InspectFlag); COPY_FLAG(interactive, Py_InteractiveFlag);
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); COPY_NOT_FLAG(buffered_stdio, Py_UnbufferedStdioFlag); COPY_NOT_FLAG(site_import, Py_NoSiteFlag); COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
_PyCoreConfig_GetGlobalConfig(config); assert(config->use_environment >= 0);
if (config->isolated > 0) { config->use_environment = 0; err = _PyPreConfig_Read(&config->preconfig); if (_Py_INIT_FAILED(err)) { return err; }
assert(config->preconfig.use_environment >= 0);
if (config->preconfig.isolated > 0) { config->user_site_directory = 0; }
if (config->use_environment) { if (config->preconfig.use_environment) { err = config_read_env_vars(config); if (_Py_INIT_FAILED(err)) { return err;
assert(config->coerce_c_locale >= 0); assert(config->use_environment >= 0); assert(config->preconfig.use_environment >= 0); assert(config->filesystem_encoding != NULL); assert(config->filesystem_errors != NULL); assert(config->stdio_encoding != NULL);
dict = PyDict_New(); if (dict == NULL) { return NULL; }
if (_PyPreConfig_AsDict(&config->preconfig, dict) < 0) { Py_DECREF(dict); return NULL; }
#define SET_ITEM(KEY, EXPR) \ do { \ obj = (EXPR); \ PyObject *obj = (EXPR); \ if (obj == NULL) { \ return NULL; \ goto fail; \ } \ int res = PyDict_SetItemString(dict, (KEY), obj); \ Py_DECREF(obj); \
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);
static _PyInitError cmdline_decode_argv(_PyCmdline *cmdline) { assert(cmdline->argv == NULL); return _PyArgv_Decode(cmdline->args, &cmdline->argv); }
/* --- _PyCoreConfig command line parser -------------------------- */
/* Parse the command line arguments */
case 'I': config->isolated++; config->preconfig.isolated++; break;
/* case 'J': reserved for Jython */
case 'E': config->use_environment = 0; config->preconfig.use_environment = 0; break;
case 't':
if (config->use_environment) { if (config->preconfig.use_environment) { err = cmdline_init_env_warnoptions(cmdline, config); if (_Py_INIT_FAILED(err)) { return err;