| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8b9dbc0 commit 484f20d
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -365,6 +365,9 @@ typedef struct { | |||
| 365 | 365 | If set to -1 (default), inherit Py_FrozenFlag value. */ | |
| 366 | 366 | int _frozen; | |
| 367 | 367 | ||
| 368 | + /* If non-zero, use "main" Python initialization */ | ||
| 369 | + int _init_main; | ||
| 370 | + | ||
| 368 | 371 | } _PyCoreConfig; | |
| 369 | 372 | ||
| 370 | 373 | #ifdef MS_WINDOWS | |
@@ -398,7 +401,8 @@ typedef struct { | |||
| 398 | 401 | .buffered_stdio = -1, \ | |
| 399 | 402 | ._install_importlib = 1, \ | |
| 400 | 403 | ._check_hash_pycs_mode = "default", \ | |
| 401 | - ._frozen = -1} | ||
| 404 | + ._frozen = -1, \ | ||
| 405 | + ._init_main = 1} | ||
| 402 | 406 | /* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */ | |
| 403 | 407 | ||
| 404 | 408 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,9 +20,6 @@ PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromPreConfig( | |||
| 20 | 20 | PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromConfig( | |
| 21 | 21 | const _PyCoreConfig *coreconfig); | |
| 22 | 22 | ||
| 23 | - PyAPI_FUNC(_PyInitError) _Py_InitializeCore( | ||
| 24 | - const _PyCoreConfig *config, | ||
| 25 | - PyInterpreterState **interp); | ||
| 26 | 23 | PyAPI_FUNC(int) _Py_IsCoreInitialized(void); | |
| 27 | 24 | ||
| 28 | 25 | ||
@@ -32,7 +29,8 @@ PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter( | |||
| 32 | 29 | /* Initialization and finalization */ | |
| 33 | 30 | ||
| 34 | 31 | PyAPI_FUNC(_PyInitError) _Py_InitializeFromConfig( | |
| 35 | - const _PyCoreConfig *config); | ||
| 32 | + const _PyCoreConfig *config, | ||
| 33 | + PyInterpreterState **interp_p); | ||
| 36 | 34 | PyAPI_FUNC(void) _Py_NO_RETURN _Py_ExitInitError(_PyInitError err); | |
| 37 | 35 | ||
| 38 | 36 | /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -338,6 +338,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): | |||
| 338 | 338 | '_install_importlib': 1, | |
| 339 | 339 | '_check_hash_pycs_mode': 'default', | |
| 340 | 340 | '_frozen': 0, | |
| 341 | + '_init_main': 1, | ||
| 341 | 342 | } | |
| 342 | 343 | if MS_WINDOWS: | |
| 343 | 344 | DEFAULT_PRE_CONFIG.update({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,19 +53,6 @@ pymain_init_preconfig(const _PyArgv *args) | |||
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | - static _PyInitError | ||
| 57 | - pymain_init_coreconfig(_PyCoreConfig *config, const _PyArgv *args, | ||
| 58 | - PyInterpreterState **interp_p) | ||
| 59 | - { | ||
| 60 | - _PyInitError err = _PyCoreConfig_Read(config, args); | ||
| 61 | - if (_Py_INIT_FAILED(err)) { | ||
| 62 | - return err; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - return _Py_InitializeCore(config, interp_p); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - | ||
| 69 | 56 | static _PyInitError | |
| 70 | 57 | pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) | |
| 71 | 58 | { | |
@@ -91,18 +78,22 @@ pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) | |||
| 91 | 78 | } | |
| 92 | 79 | ||
| 93 | 80 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 94 | - err = pymain_init_coreconfig(&config, args, interp_p); | ||
| 95 | - _PyCoreConfig_Clear(&config); | ||
| 81 | + | ||
| 82 | + err = _PyCoreConfig_Read(&config, args); | ||
| 96 | 83 | if (_Py_INIT_FAILED(err)) { | |
| 97 | - return err; | ||
| 84 | + goto done; | ||
| 98 | 85 | } | |
| 99 | 86 | ||
| 100 | - err = _Py_InitializeMainInterpreter(*interp_p); | ||
| 87 | + err = _Py_InitializeFromConfig(&config, interp_p); | ||
| 101 | 88 | if (_Py_INIT_FAILED(err)) { | |
| 102 | - return err; | ||
| 89 | + goto done; | ||
| 103 | 90 | } | |
| 104 | 91 | ||
| 105 | - return _Py_INIT_OK(); | ||
| 92 | + err = _Py_INIT_OK(); | ||
| 93 | + | ||
| 94 | + done: | ||
| 95 | + _PyCoreConfig_Clear(&config); | ||
| 96 | + return err; | ||
| 106 | 97 | } | |
| 107 | 98 | ||
| 108 | 99 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,8 +84,9 @@ main(int argc, char *argv[]) | |||
| 84 | 84 | /* Don't install importlib, since it could execute outdated bytecode. */ | |
| 85 | 85 | config._install_importlib = 0; | |
| 86 | 86 | config._frozen = 1; | |
| 87 | + config._init_main = 0; | ||
| 87 | 88 | ||
| 88 | - _PyInitError err = _Py_InitializeFromConfig(&config); | ||
| 89 | + _PyInitError err = _Py_InitializeFromConfig(&config, NULL); | ||
| 89 | 90 | /* No need to call _PyCoreConfig_Clear() since we didn't allocate any | |
| 90 | 91 | memory: program_name is a constant string. */ | |
| 91 | 92 | if (_Py_INIT_FAILED(err)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -529,7 +529,7 @@ static int test_init_from_config(void) | |||
| 529 | 529 | Py_FrozenFlag = 0; | |
| 530 | 530 | config._frozen = 1; | |
| 531 | 531 | ||
| 532 | - err = _Py_InitializeFromConfig(&config); | ||
| 532 | + err = _Py_InitializeFromConfig(&config, NULL); | ||
| 533 | 533 | /* Don't call _PyCoreConfig_Clear() since all strings are static */ | |
| 534 | 534 | if (_Py_INIT_FAILED(err)) { | |
| 535 | 535 | _Py_ExitInitError(err); | |
@@ -638,7 +638,7 @@ static int test_init_isolated(void) | |||
| 638 | 638 | config.program_name = L"./_testembed"; | |
| 639 | 639 | ||
| 640 | 640 | test_init_env_dev_mode_putenvs(); | |
| 641 | - err = _Py_InitializeFromConfig(&config); | ||
| 641 | + err = _Py_InitializeFromConfig(&config, NULL); | ||
| 642 | 642 | if (_Py_INIT_FAILED(err)) { | |
| 643 | 643 | _Py_ExitInitError(err); | |
| 644 | 644 | } | |
@@ -669,7 +669,7 @@ static int test_preinit_isolated1(void) | |||
| 669 | 669 | config.program_name = L"./_testembed"; | |
| 670 | 670 | ||
| 671 | 671 | test_init_env_dev_mode_putenvs(); | |
| 672 | - err = _Py_InitializeFromConfig(&config); | ||
| 672 | + err = _Py_InitializeFromConfig(&config, NULL); | ||
| 673 | 673 | if (_Py_INIT_FAILED(err)) { | |
| 674 | 674 | _Py_ExitInitError(err); | |
| 675 | 675 | } | |
@@ -706,7 +706,7 @@ static int test_preinit_isolated2(void) | |||
| 706 | 706 | config.program_name = L"./_testembed"; | |
| 707 | 707 | ||
| 708 | 708 | test_init_env_dev_mode_putenvs(); | |
| 709 | - err = _Py_InitializeFromConfig(&config); | ||
| 709 | + err = _Py_InitializeFromConfig(&config, NULL); | ||
| 710 | 710 | if (_Py_INIT_FAILED(err)) { | |
| 711 | 711 | _Py_ExitInitError(err); | |
| 712 | 712 | } | |
@@ -723,7 +723,7 @@ static int test_init_dev_mode(void) | |||
| 723 | 723 | putenv("PYTHONMALLOC="); | |
| 724 | 724 | config.dev_mode = 1; | |
| 725 | 725 | config.program_name = L"./_testembed"; | |
| 726 | - _PyInitError err = _Py_InitializeFromConfig(&config); | ||
| 726 | + _PyInitError err = _Py_InitializeFromConfig(&config, NULL); | ||
| 727 | 727 | if (_Py_INIT_FAILED(err)) { | |
| 728 | 728 | _Py_ExitInitError(err); | |
| 729 | 729 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -610,6 +610,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2) | |||
| 610 | 610 | COPY_WSTR_ATTR(run_filename); | |
| 611 | 611 | COPY_ATTR(_check_hash_pycs_mode); | |
| 612 | 612 | COPY_ATTR(_frozen); | |
| 613 | + COPY_ATTR(_init_main); | ||
| 613 | 614 | ||
| 614 | 615 | #undef COPY_ATTR | |
| 615 | 616 | #undef COPY_STR_ATTR | |
@@ -715,6 +716,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config) | |||
| 715 | 716 | SET_ITEM_INT(_install_importlib); | |
| 716 | 717 | SET_ITEM_STR(_check_hash_pycs_mode); | |
| 717 | 718 | SET_ITEM_INT(_frozen); | |
| 719 | + SET_ITEM_INT(_init_main); | ||
| 718 | 720 | ||
| 719 | 721 | return dict; | |
| 720 | 722 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,7 @@ Py_FrozenMain(int argc, char **argv) | |||
| 82 | 82 | if (argc >= 1) | |
| 83 | 83 | Py_SetProgramName(argv_copy[0]); | |
| 84 | 84 | ||
| 85 | - err = _Py_InitializeFromConfig(&config); | ||
| 85 | + err = _Py_InitializeFromConfig(&config, NULL); | ||
| 86 | 86 | /* No need to call _PyCoreConfig_Clear() since we didn't allocate any | |
| 87 | 87 | memory: program_name is a constant string. */ | |
| 88 | 88 | if (_Py_INIT_FAILED(err)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -458,7 +458,7 @@ _Py_SetLocaleFromEnv(int category) | |||
| 458 | 458 | /* Global initializations. Can be undone by Py_Finalize(). Don't | |
| 459 | 459 | call this twice without an intervening Py_Finalize() call. | |
| 460 | 460 | ||
| 461 | - Every call to _Py_InitializeCore, Py_Initialize or Py_InitializeEx | ||
| 461 | + Every call to _Py_InitializeFromConfig, Py_Initialize or Py_InitializeEx | ||
| 462 | 462 | must have a corresponding call to Py_Finalize. | |
| 463 | 463 | ||
| 464 | 464 | Locking: you must hold the interpreter lock while calling these APIs. | |
@@ -832,7 +832,7 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, | |||
| 832 | 832 | * to the Python C API (unless the API is explicitly listed as being | |
| 833 | 833 | * safe to call without calling Py_Initialize first) | |
| 834 | 834 | */ | |
| 835 | - _PyInitError | ||
| 835 | + static _PyInitError | ||
| 836 | 836 | _Py_InitializeCore(const _PyCoreConfig *src_config, | |
| 837 | 837 | PyInterpreterState **interp_p) | |
| 838 | 838 | { | |
@@ -981,20 +981,27 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp) | |||
| 981 | 981 | #undef _INIT_DEBUG_PRINT | |
| 982 | 982 | ||
| 983 | 983 | _PyInitError | |
| 984 | - _Py_InitializeFromConfig(const _PyCoreConfig *config) | ||
| 984 | + _Py_InitializeFromConfig(const _PyCoreConfig *config, | ||
| 985 | + PyInterpreterState **interp_p) | ||
| 985 | 986 | { | |
| 986 | 987 | PyInterpreterState *interp = NULL; | |
| 987 | 988 | _PyInitError err; | |
| 988 | 989 | err = _Py_InitializeCore(config, &interp); | |
| 989 | 990 | if (_Py_INIT_FAILED(err)) { | |
| 990 | 991 | return err; | |
| 991 | 992 | } | |
| 993 | + if (interp_p) { | ||
| 994 | + *interp_p = interp; | ||
| 995 | + } | ||
| 992 | 996 | config = &interp->core_config; | |
| 993 | 997 | ||
| 994 | - err = _Py_InitializeMainInterpreter(interp); | ||
| 995 | - if (_Py_INIT_FAILED(err)) { | ||
| 996 | - return err; | ||
| 998 | + if (config->_init_main) { | ||
| 999 | + err = _Py_InitializeMainInterpreter(interp); | ||
| 1000 | + if (_Py_INIT_FAILED(err)) { | ||
| 1001 | + return err; | ||
| 1002 | + } | ||
| 997 | 1003 | } | |
| 1004 | + | ||
| 998 | 1005 | return _Py_INIT_OK(); | |
| 999 | 1006 | } | |
| 1000 | 1007 | ||
@@ -1007,13 +1014,10 @@ Py_InitializeEx(int install_sigs) | |||
| 1007 | 1014 | return; | |
| 1008 | 1015 | } | |
| 1009 | 1016 | ||
| 1010 | - _PyInitError err; | ||
| 1011 | 1017 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 1012 | 1018 | config.install_signal_handlers = install_sigs; | |
| 1013 | 1019 | ||
| 1014 | - err = _Py_InitializeFromConfig(&config); | ||
| 1015 | - _PyCoreConfig_Clear(&config); | ||
| 1016 | - | ||
| 1020 | + _PyInitError err = _Py_InitializeFromConfig(&config, NULL); | ||
| 1017 | 1021 | if (_Py_INIT_FAILED(err)) { | |
| 1018 | 1022 | _Py_ExitInitError(err); | |
| 1019 | 1023 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments