bpo-32030: Complete _PyCoreConfig_Read() (#4946)

* Add _PyCoreConfig.install_signal_handlers
* Remove _PyMain.config: _PyMainInterpreterConfig usage is now
  restricted to pymain_init_python_main().
* Rename _PyMain.core_config to _PyMain.config
* _PyMainInterpreterConfig_Read() now creates the xoptions dictionary
   from the core config
* Fix _PyMainInterpreterConfig_Read(): don't replace xoptions and
  argv if they are already set.
This commit is contained in:
Victor Stinner 2017-12-20 19:36:46 +01:00 committed by GitHub
parent 51eb1c6b9c
commit 9cfc00262c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 387 additions and 346 deletions

View File

@ -25,6 +25,7 @@ typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
typedef struct { typedef struct {
int install_signal_handlers; /* Install signal handlers? -1 means unset */
int ignore_environment; /* -E */ int ignore_environment; /* -E */
int use_hash_seed; /* PYTHONHASHSEED=x */ int use_hash_seed; /* PYTHONHASHSEED=x */
unsigned long hash_seed; unsigned long hash_seed;
@ -62,6 +63,7 @@ typedef struct {
#define _PyCoreConfig_INIT \ #define _PyCoreConfig_INIT \
(_PyCoreConfig){ \ (_PyCoreConfig){ \
.install_signal_handlers = -1, \
.use_hash_seed = -1, \ .use_hash_seed = -1, \
.coerce_c_locale = -1, \ .coerce_c_locale = -1, \
.utf8_mode = -1, \ .utf8_mode = -1, \
@ -73,7 +75,7 @@ typedef struct {
* See PEP 432 for final anticipated contents * See PEP 432 for final anticipated contents
*/ */
typedef struct { typedef struct {
int install_signal_handlers; int install_signal_handlers; /* Install signal handlers? -1 means unset */
PyObject *argv; /* sys.argv list, can be NULL */ PyObject *argv; /* sys.argv list, can be NULL */
PyObject *executable; /* sys.executable str */ PyObject *executable; /* sys.executable str */
PyObject *prefix; /* sys.prefix str */ PyObject *prefix; /* sys.prefix str */

File diff suppressed because it is too large Load Diff

View File

@ -874,30 +874,29 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
_PyInitError _PyInitError
_Py_InitializeEx_Private(int install_sigs, int install_importlib) _Py_InitializeEx_Private(int install_sigs, int install_importlib)
{ {
_PyCoreConfig core_config = _PyCoreConfig_INIT; _PyCoreConfig config = _PyCoreConfig_INIT;
_PyMainInterpreterConfig config = _PyMainInterpreterConfig_INIT;
_PyInitError err; _PyInitError err;
core_config.ignore_environment = Py_IgnoreEnvironmentFlag; config.ignore_environment = Py_IgnoreEnvironmentFlag;
core_config._disable_importlib = !install_importlib; config._disable_importlib = !install_importlib;
config.install_signal_handlers = install_sigs; config.install_signal_handlers = install_sigs;
err = _PyCoreConfig_Read(&core_config); err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
goto done; goto done;
} }
err = _Py_InitializeCore(&core_config); err = _Py_InitializeCore(&config);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
goto done; goto done;
} }
err = _PyMainInterpreterConfig_Read(&config, &core_config); _PyMainInterpreterConfig main_config = _PyMainInterpreterConfig_INIT;
if (_Py_INIT_FAILED(err)) { err = _PyMainInterpreterConfig_Read(&main_config, &config);
goto done; if (!_Py_INIT_FAILED(err)) {
err = _Py_InitializeMainInterpreter(&main_config);
} }
_PyMainInterpreterConfig_Clear(&main_config);
err = _Py_InitializeMainInterpreter(&config);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
goto done; goto done;
} }
@ -905,8 +904,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
err = _Py_INIT_OK(); err = _Py_INIT_OK();
done: done:
_PyCoreConfig_Clear(&core_config); _PyCoreConfig_Clear(&config);
_PyMainInterpreterConfig_Clear(&config);
return err; return err;
} }