Skip to content

Commit 4631da1

Browse files
authored
bpo-36763: Remove _PyCoreConfig._init_main (GH-13066)
1 parent 70005ac commit 4631da1

6 files changed

Lines changed: 10 additions & 19 deletions

File tree

Include/cpython/coreconfig.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ typedef struct {
391391
If set to -1 (default), inherit Py_FrozenFlag value. */
392392
int _frozen;
393393

394-
/* If non-zero, use "main" Python initialization */
395-
int _init_main;
396-
397394
} _PyCoreConfig;
398395

399396
#ifdef MS_WINDOWS
@@ -428,8 +425,7 @@ typedef struct {
428425
.buffered_stdio = -1, \
429426
._install_importlib = 1, \
430427
.check_hash_pycs_mode = NULL, \
431-
._frozen = -1, \
432-
._init_main = 1}
428+
._frozen = -1}
433429
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
434430

435431
#ifdef __cplusplus

Lib/test/test_embed.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
348348
'_install_importlib': 1,
349349
'check_hash_pycs_mode': 'default',
350350
'_frozen': 0,
351-
'_init_main': 1,
352351
}
353352
if MS_WINDOWS:
354353
DEFAULT_PRE_CONFIG.update({
@@ -443,7 +442,10 @@ def get_expected_config(self, expected, env):
443442
raise Exception(f"failed to get the default config: "
444443
f"stdout={proc.stdout!r} stderr={proc.stderr!r}")
445444
stdout = proc.stdout.decode('utf-8')
446-
config = json.loads(stdout)
445+
try:
446+
config = json.loads(stdout)
447+
except json.JSONDecodeError:
448+
self.fail(f"fail to decode stdout: {stdout!r}")
447449

448450
for key, value in expected.items():
449451
if value is self.GET_DEFAULT_CONFIG:
@@ -496,7 +498,10 @@ def check_config(self, testname, expected_config, expected_preconfig):
496498

497499
out, err = self.run_embedded_interpreter(testname, env=env)
498500
# Ignore err
499-
config = json.loads(out)
501+
try:
502+
config = json.loads(out)
503+
except json.JSONDecodeError:
504+
self.fail(f"fail to decode stdout: {out!r}")
500505

501506
expected_preconfig = dict(self.DEFAULT_PRE_CONFIG, **expected_preconfig)
502507
expected_config = self.get_expected_config(expected_config, env)
@@ -533,7 +538,6 @@ def test_init_global_config(self):
533538
'filesystem_encoding': 'utf-8',
534539
'filesystem_errors': self.UTF8_MODE_ERRORS,
535540
'user_site_directory': 0,
536-
'_frozen': 1,
537541
}
538542
self.check_config("init_global_config", config, preconfig)
539543

@@ -578,7 +582,6 @@ def test_init_from_config(self):
578582
'faulthandler': 1,
579583

580584
'check_hash_pycs_mode': 'always',
581-
'_frozen': 1,
582585
}
583586
self.check_config("init_from_config", config, preconfig)
584587

Programs/_freeze_importlib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ main(int argc, char *argv[])
8484
/* Don't install importlib, since it could execute outdated bytecode. */
8585
config._install_importlib = 0;
8686
config._frozen = 1;
87-
config._init_main = 0;
8887

8988
_PyInitError err = _Py_InitializeFromConfig(&config);
9089
/* No need to call _PyCoreConfig_Clear() since we didn't allocate any

Programs/_testembed.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ static int test_init_global_config(void)
354354
putenv("PYTHONUNBUFFERED=");
355355
Py_UnbufferedStdioFlag = 1;
356356

357-
Py_FrozenFlag = 1;
358-
359357
/* FIXME: test Py_LegacyWindowsFSEncodingFlag */
360358
/* FIXME: test Py_LegacyWindowsStdioFlag */
361359

@@ -497,9 +495,6 @@ static int test_init_from_config(void)
497495

498496
config.check_hash_pycs_mode = L"always";
499497

500-
Py_FrozenFlag = 0;
501-
config._frozen = 1;
502-
503498
err = _Py_InitializeFromConfig(&config);
504499
if (_Py_INIT_FAILED(err)) {
505500
_Py_ExitInitError(err);

Python/coreconfig.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
667667
COPY_WSTR_ATTR(run_filename);
668668
COPY_WSTR_ATTR(check_hash_pycs_mode);
669669
COPY_ATTR(_frozen);
670-
COPY_ATTR(_init_main);
671670

672671
#undef COPY_ATTR
673672
#undef COPY_WSTR_ATTR
@@ -766,7 +765,6 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
766765
SET_ITEM_INT(_install_importlib);
767766
SET_ITEM_WSTR(check_hash_pycs_mode);
768767
SET_ITEM_INT(_frozen);
769-
SET_ITEM_INT(_init_main);
770768

771769
return dict;
772770

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ init_python(const _PyCoreConfig *config, const _PyArgv *args)
988988
}
989989
config = &interp->core_config;
990990

991-
if (config->_init_main) {
991+
if (!config->_frozen) {
992992
err = _Py_InitializeMainInterpreter(runtime, interp);
993993
if (_Py_INIT_FAILED(err)) {
994994
return err;

0 commit comments

Comments
 (0)