| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f78a5e9 commit 2000495
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,7 +123,9 @@ typedef struct { | |||
| 123 | 123 | /* --- _PyCoreConfig ---------------------------------------------- */ | |
| 124 | 124 | ||
| 125 | 125 | typedef struct { | |
| 126 | - _PyPreConfig preconfig; | ||
| 126 | + int isolated; | ||
| 127 | + int use_environment; | ||
| 128 | + int dev_mode; | ||
| 127 | 129 | ||
| 128 | 130 | /* Install signal handlers? Yes by default. */ | |
| 129 | 131 | int install_signal_handlers; | |
@@ -375,7 +377,9 @@ typedef struct { | |||
| 375 | 377 | #define _PyCoreConfig_INIT \ | |
| 376 | 378 | (_PyCoreConfig){ \ | |
| 377 | 379 | _PyCoreConfig_WINDOWS_INIT \ | |
| 378 | - .preconfig = _PyPreConfig_INIT, \ | ||
| 380 | + .isolated = -1, \ | ||
| 381 | + .use_environment = -1, \ | ||
| 382 | + .dev_mode = -1, \ | ||
| 379 | 383 | .install_signal_handlers = 1, \ | |
| 380 | 384 | .use_hash_seed = -1, \ | |
| 381 | 385 | .faulthandler = -1, \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, | |||
| 16 | 16 | ||
| 17 | 17 | PyAPI_FUNC(_PyInitError) _Py_PreInitialize(void); | |
| 18 | 18 | PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromPreConfig( | |
| 19 | - _PyPreConfig *preconfig); | ||
| 19 | + const _PyPreConfig *preconfig); | ||
| 20 | 20 | PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromConfig( | |
| 21 | 21 | const _PyCoreConfig *coreconfig); | |
| 22 | 22 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,12 +16,14 @@ typedef struct { | |||
| 16 | 16 | _PyWstrList xoptions; /* "-X value" option */ | |
| 17 | 17 | int use_environment; /* -E option */ | |
| 18 | 18 | int isolated; /* -I option */ | |
| 19 | + int dev_mode; /* -X dev and PYTHONDEVMODE */ | ||
| 19 | 20 | } _PyPreCmdline; | |
| 20 | 21 | ||
| 21 | 22 | #define _PyPreCmdline_INIT \ | |
| 22 | 23 | (_PyPreCmdline){ \ | |
| 23 | 24 | .use_environment = -1, \ | |
| 24 | - .isolated = -1} | ||
| 25 | + .isolated = -1, \ | ||
| 26 | + .dev_mode = -1} | ||
| 25 | 27 | /* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */ | |
| 26 | 28 | ||
| 27 | 29 | PyAPI_FUNC(void) _PyPreCmdline_Clear(_PyPreCmdline *cmdline); | |
@@ -112,7 +114,7 @@ PyAPI_FUNC(void) _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config); | |||
| 112 | 114 | PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config); | |
| 113 | 115 | PyAPI_FUNC(_PyInitError) _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, | |
| 114 | 116 | const _PyArgv *args); | |
| 115 | - PyAPI_FUNC(_PyInitError) _PyCoreConfig_Write(const _PyCoreConfig *config); | ||
| 117 | + PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config); | ||
| 116 | 118 | ||
| 117 | 119 | /* --- _PyMainInterpreterConfig ----------------------------------- */ | |
| 118 | 120 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,9 @@ extern void _PyGILState_Fini(void); | |||
| 77 | 77 | ||
| 78 | 78 | PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); | |
| 79 | 79 | ||
| 80 | + PyAPI_FUNC(_PyInitError) _Py_PreInitializeInPlace( | ||
| 81 | + _PyPreConfig *config); | ||
| 82 | + | ||
| 80 | 83 | #ifdef __cplusplus | |
| 81 | 84 | } | |
| 82 | 85 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,12 +272,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): | |||
| 272 | 272 | 'allocator': None, | |
| 273 | 273 | 'coerce_c_locale': 0, | |
| 274 | 274 | 'coerce_c_locale_warn': 0, | |
| 275 | - 'dev_mode': 0, | ||
| 276 | - 'isolated': 0, | ||
| 277 | - 'use_environment': 1, | ||
| 278 | 275 | 'utf8_mode': 0, | |
| 279 | 276 | } | |
| 277 | + COPY_PRE_CONFIG = [ | ||
| 278 | + 'dev_mode', | ||
| 279 | + 'isolated', | ||
| 280 | + 'use_environment', | ||
| 281 | + ] | ||
| 282 | + | ||
| 280 | 283 | DEFAULT_CORE_CONFIG = { | |
| 284 | + 'isolated': 0, | ||
| 285 | + 'use_environment': 1, | ||
| 286 | + 'dev_mode': 0, | ||
| 287 | + | ||
| 281 | 288 | 'install_signal_handlers': 1, | |
| 282 | 289 | 'use_hash_seed': 0, | |
| 283 | 290 | 'hash_seed': 0, | |
@@ -363,8 +370,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): | |||
| 363 | 370 | '_Py_HasFileSystemDefaultEncodeErrors': 0, | |
| 364 | 371 | } | |
| 365 | 372 | COPY_GLOBAL_PRE_CONFIG = [ | |
| 366 | - ('Py_IgnoreEnvironmentFlag', 'use_environment', True), | ||
| 367 | - ('Py_IsolatedFlag', 'isolated'), | ||
| 368 | 373 | ('Py_UTF8Mode', 'utf8_mode'), | |
| 369 | 374 | ] | |
| 370 | 375 | COPY_GLOBAL_CONFIG = [ | |
@@ -376,8 +381,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): | |||
| 376 | 381 | ('Py_FileSystemDefaultEncodeErrors', 'filesystem_errors'), | |
| 377 | 382 | ('Py_FileSystemDefaultEncoding', 'filesystem_encoding'), | |
| 378 | 383 | ('Py_FrozenFlag', '_frozen'), | |
| 384 | + ('Py_IgnoreEnvironmentFlag', 'use_environment', True), | ||
| 379 | 385 | ('Py_InspectFlag', 'inspect'), | |
| 380 | 386 | ('Py_InteractiveFlag', 'interactive'), | |
| 387 | + ('Py_IsolatedFlag', 'isolated'), | ||
| 381 | 388 | ('Py_NoSiteFlag', 'site_import', True), | |
| 382 | 389 | ('Py_NoUserSiteDirectory', 'user_site_directory', True), | |
| 383 | 390 | ('Py_OptimizeFlag', 'optimization_level'), | |
@@ -415,7 +422,7 @@ def check_main_config(self, config): | |||
| 415 | 422 | expected['xoptions'] = self.main_xoptions(core_config['xoptions']) | |
| 416 | 423 | self.assertEqual(main_config, expected) | |
| 417 | 424 | ||
| 418 | - def get_expected_config(self, expected, expected_preconfig, env): | ||
| 425 | + def get_expected_config(self, expected, env): | ||
| 419 | 426 | expected = dict(self.DEFAULT_CORE_CONFIG, **expected) | |
| 420 | 427 | ||
| 421 | 428 | code = textwrap.dedent(''' | |
@@ -443,7 +450,7 @@ def get_expected_config(self, expected, expected_preconfig, env): | |||
| 443 | 450 | # when test_embed is run from a venv (bpo-35313) | |
| 444 | 451 | args = (sys.executable, '-S', '-c', code) | |
| 445 | 452 | env = dict(env) | |
| 446 | - if not expected_preconfig['isolated']: | ||
| 453 | + if not expected['isolated']: | ||
| 447 | 454 | env['PYTHONCOERCECLOCALE'] = '0' | |
| 448 | 455 | env['PYTHONUTF8'] = '0' | |
| 449 | 456 | proc = subprocess.run(args, env=env, | |
@@ -509,7 +516,10 @@ def check_config(self, testname, expected_config, expected_preconfig): | |||
| 509 | 516 | config = json.loads(out) | |
| 510 | 517 | ||
| 511 | 518 | expected_preconfig = dict(self.DEFAULT_PRE_CONFIG, **expected_preconfig) | |
| 512 | - expected_config = self.get_expected_config(expected_config, expected_preconfig, env) | ||
| 519 | + expected_config = self.get_expected_config(expected_config, env) | ||
| 520 | + for key in self.COPY_PRE_CONFIG: | ||
| 521 | + if key not in expected_preconfig: | ||
| 522 | + expected_preconfig[key] = expected_config[key] | ||
| 513 | 523 | ||
| 514 | 524 | self.check_core_config(config, expected_config) | |
| 515 | 525 | self.check_pre_config(config, expected_preconfig) | |
@@ -617,35 +627,36 @@ def test_init_env(self): | |||
| 617 | 627 | ||
| 618 | 628 | def test_init_env_dev_mode(self): | |
| 619 | 629 | preconfig = dict(self.INIT_ENV_PRECONFIG, | |
| 620 | - allocator='debug', | ||
| 621 | - dev_mode=1) | ||
| 630 | + allocator='debug') | ||
| 622 | 631 | config = dict(self.INIT_ENV_CONFIG, | |
| 623 | 632 | dev_mode=1) | |
| 624 | 633 | self.check_config("init_env_dev_mode", config, preconfig) | |
| 625 | 634 | ||
| 626 | - def test_init_env_dev_mode(self): | ||
| 635 | + def test_init_env_dev_mode_alloc(self): | ||
| 627 | 636 | preconfig = dict(self.INIT_ENV_PRECONFIG, | |
| 628 | - allocator='malloc', | ||
| 629 | - dev_mode=1) | ||
| 630 | - config = dict(self.INIT_ENV_CONFIG) | ||
| 637 | + allocator='malloc') | ||
| 638 | + config = dict(self.INIT_ENV_CONFIG, | ||
| 639 | + dev_mode=1) | ||
| 631 | 640 | self.check_config("init_env_dev_mode_alloc", config, preconfig) | |
| 632 | 641 | ||
| 633 | 642 | def test_init_dev_mode(self): | |
| 634 | 643 | preconfig = { | |
| 635 | 644 | 'allocator': 'debug', | |
| 636 | - 'dev_mode': 1, | ||
| 637 | 645 | } | |
| 638 | 646 | config = { | |
| 639 | 647 | 'faulthandler': 1, | |
| 648 | + 'dev_mode': 1, | ||
| 640 | 649 | } | |
| 641 | 650 | self.check_config("init_dev_mode", config, preconfig) | |
| 642 | 651 | ||
| 643 | 652 | def test_init_isolated(self): | |
| 644 | 653 | preconfig = { | |
| 645 | - 'isolated': 1, | ||
| 646 | - 'use_environment': 0, | ||
| 654 | + 'isolated': 0, | ||
| 655 | + 'use_environment': 1, | ||
| 647 | 656 | } | |
| 648 | 657 | config = { | |
| 658 | + 'isolated': 1, | ||
| 659 | + 'use_environment': 0, | ||
| 649 | 660 | 'user_site_directory': 0, | |
| 650 | 661 | } | |
| 651 | 662 | self.check_config("init_isolated", config, preconfig) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -294,7 +294,7 @@ pymain_init_preconfig(const _PyArgv *args) | |||
| 294 | 294 | goto done; | |
| 295 | 295 | } | |
| 296 | 296 | ||
| 297 | - err = _Py_PreInitializeFromPreConfig(&config); | ||
| 297 | + err = _Py_PreInitializeInPlace(&config); | ||
| 298 | 298 | ||
| 299 | 299 | done: | |
| 300 | 300 | _PyPreConfig_Clear(&config); | |
@@ -311,11 +311,6 @@ pymain_init_coreconfig(_PyCoreConfig *config, const _PyArgv *args, | |||
| 311 | 311 | return err; | |
| 312 | 312 | } | |
| 313 | 313 | ||
| 314 | - err = _PyCoreConfig_Write(config); | ||
| 315 | - if (_Py_INIT_FAILED(err)) { | ||
| 316 | - return err; | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | 314 | return _Py_InitializeCore(interp_p, config); | |
| 320 | 315 | } | |
| 321 | 316 | ||
@@ -483,7 +478,7 @@ pymain_header(const _PyCoreConfig *config) | |||
| 483 | 478 | static void | |
| 484 | 479 | pymain_import_readline(const _PyCoreConfig *config) | |
| 485 | 480 | { | |
| 486 | - if (config->preconfig.isolated) { | ||
| 481 | + if (config->isolated) { | ||
| 487 | 482 | return; | |
| 488 | 483 | } | |
| 489 | 484 | if (!config->inspect && RUN_CODE(config)) { | |
@@ -655,7 +650,7 @@ pymain_run_file(_PyCoreConfig *config, PyCompilerFlags *cf) | |||
| 655 | 650 | static void | |
| 656 | 651 | pymain_run_startup(_PyCoreConfig *config, PyCompilerFlags *cf) | |
| 657 | 652 | { | |
| 658 | - const char *startup = _Py_GetEnv(config->preconfig.use_environment, "PYTHONSTARTUP"); | ||
| 653 | + const char *startup = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP"); | ||
| 659 | 654 | if (startup == NULL) { | |
| 660 | 655 | return; | |
| 661 | 656 | } | |
@@ -735,7 +730,7 @@ pymain_repl(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode) | |||
| 735 | 730 | { | |
| 736 | 731 | /* Check this environment variable at the end, to give programs the | |
| 737 | 732 | opportunity to set it from Python. */ | |
| 738 | - if (!Py_InspectFlag && _Py_GetEnv(config->preconfig.use_environment, "PYTHONINSPECT")) { | ||
| 733 | + if (!Py_InspectFlag && _Py_GetEnv(config->use_environment, "PYTHONINSPECT")) { | ||
| 739 | 734 | Py_InspectFlag = 1; | |
| 740 | 735 | config->inspect = 1; | |
| 741 | 736 | } | |
@@ -775,7 +770,7 @@ pymain_run_python(PyInterpreterState *interp, int *exitcode) | |||
| 775 | 770 | goto done; | |
| 776 | 771 | } | |
| 777 | 772 | } | |
| 778 | - else if (!config->preconfig.isolated) { | ||
| 773 | + else if (!config->isolated) { | ||
| 779 | 774 | PyObject *path0 = NULL; | |
| 780 | 775 | if (_PyPathConfig_ComputeSysPath0(&config->argv, &path0)) { | |
| 781 | 776 | if (path0 == NULL) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,7 +77,7 @@ main(int argc, char *argv[]) | |||
| 77 | 77 | text[text_size] = '\0'; | |
| 78 | 78 | ||
| 79 | 79 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 80 | - config.preconfig.use_environment = 0; | ||
| 80 | + config.use_environment = 0; | ||
| 81 | 81 | config.user_site_directory = 0; | |
| 82 | 82 | config.site_import = 0; | |
| 83 | 83 | config.program_name = L"./_freeze_importlib"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -397,6 +397,22 @@ static int test_init_global_config(void) | |||
| 397 | 397 | ||
| 398 | 398 | static int test_init_from_config(void) | |
| 399 | 399 | { | |
| 400 | + _PyInitError err; | ||
| 401 | + | ||
| 402 | + _PyPreConfig preconfig = _PyPreConfig_INIT; | ||
| 403 | + | ||
| 404 | + putenv("PYTHONMALLOC=malloc_debug"); | ||
| 405 | + preconfig.allocator = "malloc"; | ||
| 406 | + | ||
| 407 | + putenv("PYTHONUTF8=0"); | ||
| 408 | + Py_UTF8Mode = 0; | ||
| 409 | + preconfig.utf8_mode = 1; | ||
| 410 | + | ||
| 411 | + err = _Py_PreInitializeFromPreConfig(&preconfig); | ||
| 412 | + if (_Py_INIT_FAILED(err)) { | ||
| 413 | + _Py_ExitInitError(err); | ||
| 414 | + } | ||
| 415 | + | ||
| 400 | 416 | /* Test _Py_InitializeFromConfig() */ | |
| 401 | 417 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 402 | 418 | config.install_signal_handlers = 0; | |
@@ -407,9 +423,6 @@ static int test_init_from_config(void) | |||
| 407 | 423 | config.use_hash_seed = 1; | |
| 408 | 424 | config.hash_seed = 123; | |
| 409 | 425 | ||
| 410 | - putenv("PYTHONMALLOC=malloc_debug"); | ||
| 411 | - config.preconfig.allocator = "malloc"; | ||
| 412 | - | ||
| 413 | 426 | /* dev_mode=1 is tested in test_init_dev_mode() */ | |
| 414 | 427 | ||
| 415 | 428 | putenv("PYTHONFAULTHANDLER="); | |
@@ -430,10 +443,6 @@ static int test_init_from_config(void) | |||
| 430 | 443 | ||
| 431 | 444 | /* FIXME: test coerce_c_locale and coerce_c_locale_warn */ | |
| 432 | 445 | ||
| 433 | - putenv("PYTHONUTF8=0"); | ||
| 434 | - Py_UTF8Mode = 0; | ||
| 435 | - config.preconfig.utf8_mode = 1; | ||
| 436 | - | ||
| 437 | 446 | putenv("PYTHONPYCACHEPREFIX=env_pycache_prefix"); | |
| 438 | 447 | config.pycache_prefix = L"conf_pycache_prefix"; | |
| 439 | 448 | ||
@@ -521,7 +530,7 @@ static int test_init_from_config(void) | |||
| 521 | 530 | Py_FrozenFlag = 0; | |
| 522 | 531 | config._frozen = 1; | |
| 523 | 532 | ||
| 524 | - _PyInitError err = _Py_InitializeFromConfig(&config); | ||
| 533 | + err = _Py_InitializeFromConfig(&config); | ||
| 525 | 534 | /* Don't call _PyCoreConfig_Clear() since all strings are static */ | |
| 526 | 535 | if (_Py_INIT_FAILED(err)) { | |
| 527 | 536 | _Py_ExitInitError(err); | |
@@ -607,20 +616,30 @@ static int test_init_env_dev_mode_alloc(void) | |||
| 607 | 616 | ||
| 608 | 617 | static int test_init_isolated(void) | |
| 609 | 618 | { | |
| 619 | + _PyInitError err; | ||
| 620 | + | ||
| 621 | + _PyPreConfig preconfig = _PyPreConfig_INIT; | ||
| 622 | + | ||
| 623 | + /* Set coerce_c_locale and utf8_mode to not depend on the locale */ | ||
| 624 | + preconfig.coerce_c_locale = 0; | ||
| 625 | + preconfig.utf8_mode = 0; | ||
| 626 | + | ||
| 627 | + err = _Py_PreInitializeFromPreConfig(&preconfig); | ||
| 628 | + if (_Py_INIT_FAILED(err)) { | ||
| 629 | + _Py_ExitInitError(err); | ||
| 630 | + } | ||
| 631 | + | ||
| 610 | 632 | /* Test _PyCoreConfig.isolated=1 */ | |
| 611 | 633 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 612 | 634 | ||
| 613 | 635 | Py_IsolatedFlag = 0; | |
| 614 | - config.preconfig.isolated = 1; | ||
| 636 | + config.isolated = 1; | ||
| 615 | 637 | ||
| 616 | - /* Set coerce_c_locale and utf8_mode to not depend on the locale */ | ||
| 617 | - config.preconfig.coerce_c_locale = 0; | ||
| 618 | - config.preconfig.utf8_mode = 0; | ||
| 619 | 638 | /* Use path starting with "./" avoids a search along the PATH */ | |
| 620 | 639 | config.program_name = L"./_testembed"; | |
| 621 | 640 | ||
| 622 | 641 | test_init_env_dev_mode_putenvs(); | |
| 623 | - _PyInitError err = _Py_InitializeFromConfig(&config); | ||
| 642 | + err = _Py_InitializeFromConfig(&config); | ||
| 624 | 643 | if (_Py_INIT_FAILED(err)) { | |
| 625 | 644 | _Py_ExitInitError(err); | |
| 626 | 645 | } | |
@@ -635,7 +654,7 @@ static int test_init_dev_mode(void) | |||
| 635 | 654 | _PyCoreConfig config = _PyCoreConfig_INIT; | |
| 636 | 655 | putenv("PYTHONFAULTHANDLER="); | |
| 637 | 656 | putenv("PYTHONMALLOC="); | |
| 638 | - config.preconfig.dev_mode = 1; | ||
| 657 | + config.dev_mode = 1; | ||
| 639 | 658 | config.program_name = L"./_testembed"; | |
| 640 | 659 | _PyInitError err = _Py_InitializeFromConfig(&config); | |
| 641 | 660 | if (_Py_INIT_FAILED(err)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments