Add _PyCoreConfig and _Py_InitializeCore(). · python/cpython@6438bf5 · GitHub
Skip to content

Commit 6438bf5

Browse files
ncoghlanericsnowcurrently
authored andcommitted
Add _PyCoreConfig and _Py_InitializeCore().
1 parent bb1c034 commit 6438bf5

5 files changed

Lines changed: 240 additions & 58 deletions

File tree

Include/pylifecycle.h

Lines changed: 9 additions & 1 deletion

Include/pystate.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ typedef struct _is PyInterpreterState;
2323
#else
2424
typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
2525

26+
27+
typedef struct {
28+
int ignore_environment;
29+
int use_hash_seed;
30+
unsigned long hash_seed;
31+
int _disable_importlib; /* Needed by freeze_importlib */
32+
} _PyCoreConfig;
33+
34+
#define _PyCoreConfig_INIT {0, -1, 0, 0}
35+
2636
typedef struct _is {
2737

2838
struct _is *next;
@@ -42,6 +52,7 @@ typedef struct _is {
4252
int codecs_initialized;
4353
int fscodec_initialized;
4454

55+
_PyCoreConfig core_config;
4556
#ifdef HAVE_DLOPEN
4657
int dlopenflags;
4758
#endif

Modules/main.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,6 @@ read_command_line(int argc, wchar_t **argv, _Py_CommandLineDetails *cmdline)
389389
exit(1);
390390
}
391391

392-
// TODO: Move these to core runtime init.
393-
Py_HashRandomizationFlag = 1;
394-
_Py_HashRandomization_Init();
395-
PySys_ResetWarnOptions();
396-
397392
_PyOS_ResetGetOpt();
398393

399394
while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
@@ -584,6 +579,7 @@ Py_Main(int argc, wchar_t **argv)
584579
#endif
585580
int stdin_is_interactive = 0;
586581
_Py_CommandLineDetails cmdline = _Py_CommandLineDetails_INIT;
582+
_PyCoreConfig core_config = _PyCoreConfig_INIT;
587583
PyCompilerFlags cf;
588584
PyObject *main_importer_path = NULL;
589585

@@ -602,11 +598,16 @@ Py_Main(int argc, wchar_t **argv)
602598
break;
603599
}
604600
if (c == 'E' || c == 'I') {
605-
Py_IgnoreEnvironmentFlag++;
601+
core_config.ignore_environment++;
606602
break;
607603
}
608604
}
609605

606+
/* Initialize the core language runtime */
607+
Py_IgnoreEnvironmentFlag = core_config.ignore_environment;
608+
core_config._disable_importlib = 0;
609+
_Py_InitializeCore(&core_config);
610+
610611
/* Reprocess the command line with the language runtime available */
611612
if (read_command_line(argc, argv, &cmdline)) {
612613
return usage(2, argv[0]);
@@ -680,6 +681,7 @@ Py_Main(int argc, wchar_t **argv)
680681
for (i = 0; i < PyList_GET_SIZE(cmdline.warning_options); i++) {
681682
PySys_AddWarnOptionUnicode(PyList_GET_ITEM(cmdline.warning_options, i));
682683
}
684+
Py_DECREF(cmdline.warning_options);
683685
}
684686

685687
stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
@@ -767,9 +769,10 @@ Py_Main(int argc, wchar_t **argv)
767769
#else
768770
Py_SetProgramName(argv[0]);
769771
#endif
770-
Py_Initialize();
771-
Py_XDECREF(cmdline.warning_options);
772+
if (_Py_InitializeMainInterpreter(1))
773+
Py_FatalError("Py_Main: Py_InitializeMainInterpreter failed");
772774

775+
/* TODO: Move this to _PyRun_PrepareMain */
773776
if (!Py_QuietFlag && (Py_VerboseFlag ||
774777
(cmdline.command == NULL && cmdline.filename == NULL &&
775778
cmdline.module == NULL && stdin_is_interactive))) {
@@ -779,6 +782,7 @@ Py_Main(int argc, wchar_t **argv)
779782
fprintf(stderr, "%s\n", COPYRIGHT);
780783
}
781784

785+
/* TODO: Move this to _Py_InitializeMainInterpreter */
782786
if (cmdline.command != NULL) {
783787
/* Backup _PyOS_optind and force sys.argv[0] = '-c' */
784788
_PyOS_optind--;

Python/bootstrap_hash.c

Lines changed: 5 additions & 3 deletions

0 commit comments

Comments
 (0)