Skip to content

Commit 33c377e

Browse files
authored
bpo-32030: Simplify _PyCoreConfig_INIT macro (#4728)
* Simplify _PyCoreConfig_INIT, _PyMainInterpreterConfig_INIT, _PyPathConfig_INIT macros: no need to set fields to 0/NULL, it's redundant (the C language sets them to 0/NULL for us). * Fix typo: pymain_run_statup() => pymain_run_startup() * Remove a few XXX/TODO
1 parent ae342cf commit 33c377e

File tree

4 files changed

+12
-51
lines changed

4 files changed

+12
-51
lines changed

Include/internal/pystate.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,8 @@ typedef struct {
5454
wchar_t *home;
5555
} _PyPathConfig;
5656

57-
#ifdef MS_WINDOWS
58-
#define _PyPathConfig_INIT \
59-
{.program_full_path = NULL, \
60-
.prefix = NULL, \
61-
.dll_path = NULL, \
62-
.module_search_path = NULL, \
63-
.program_name = NULL, \
64-
.home = NULL}
65-
#else
66-
#define _PyPathConfig_INIT \
67-
{.program_full_path = NULL, \
68-
.prefix = NULL, \
69-
.exec_prefix = NULL, \
70-
.module_search_path = NULL, \
71-
.program_name = NULL, \
72-
.home = NULL}
73-
#endif
57+
#define _PyPathConfig_INIT {.module_search_path = NULL}
58+
/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
7459

7560
PyAPI_DATA(_PyPathConfig) _Py_path_config;
7661

@@ -116,6 +101,7 @@ typedef struct pyruntimestate {
116101
} _PyRuntimeState;
117102

118103
#define _PyRuntimeState_INIT {.initialized = 0, .core_initialized = 0}
104+
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
119105

120106
PyAPI_DATA(_PyRuntimeState) _PyRuntime;
121107
PyAPI_FUNC(_PyInitError) _PyRuntimeState_Init(_PyRuntimeState *);

Include/pystate.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,8 @@ typedef struct {
3838
int show_alloc_count; /* -X showalloccount */
3939
} _PyCoreConfig;
4040

41-
#define _PyCoreConfig_INIT \
42-
(_PyCoreConfig){\
43-
.ignore_environment = 0, \
44-
.use_hash_seed = -1, \
45-
.hash_seed = 0, \
46-
._disable_importlib = 0, \
47-
.allocator = NULL, \
48-
.dev_mode = 0, \
49-
.faulthandler = 0, \
50-
.tracemalloc = 0, \
51-
.import_time = 0, \
52-
.show_ref_count = 0, \
53-
.show_alloc_count = 0}
41+
#define _PyCoreConfig_INIT (_PyCoreConfig){.use_hash_seed = -1}
42+
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
5443

5544
/* Placeholders while working on the new configuration API
5645
*
@@ -69,11 +58,8 @@ typedef struct {
6958
} _PyMainInterpreterConfig;
7059

7160
#define _PyMainInterpreterConfig_INIT \
72-
(_PyMainInterpreterConfig){\
73-
.install_signal_handlers = -1, \
74-
.module_search_path_env = NULL, \
75-
.home = NULL, \
76-
.program_name = NULL}
61+
(_PyMainInterpreterConfig){.install_signal_handlers = -1}
62+
/* Note: _PyMainInterpreterConfig_INIT sets other fields to 0/NULL */
7763

7864
typedef struct _is {
7965

Modules/main.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pymain_get_env_var(const char *name)
160160

161161

162162
static void
163-
pymain_run_statup(PyCompilerFlags *cf)
163+
pymain_run_startup(PyCompilerFlags *cf)
164164
{
165165
char *startup = Py_GETENV("PYTHONSTARTUP");
166166
if (startup == NULL || startup[0] == '\0') {
@@ -367,8 +367,6 @@ pymain_run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf)
367367

368368
/* Main program */
369369

370-
/*TODO: Add arg processing to PEP 432 as a new configuration setup API
371-
*/
372370
typedef struct {
373371
size_t len;
374372
wchar_t **options;
@@ -949,8 +947,6 @@ pymain_get_program_name(_PyMain *pymain)
949947
*
950948
* Replaces previous call to Py_Initialize()
951949
*
952-
* TODO: Move environment queries (etc) into Py_ReadConfig
953-
*
954950
* Return 0 on success.
955951
* Set pymain->err and return -1 on error.
956952
*/
@@ -1121,10 +1117,9 @@ pymain_run_filename(_PyMain *pymain)
11211117

11221118
if (cmdline->filename == NULL && pymain->stdin_is_interactive) {
11231119
Py_InspectFlag = 0; /* do exit on SystemExit */
1124-
pymain_run_statup(&pymain->cf);
1120+
pymain_run_startup(&pymain->cf);
11251121
pymain_run_interactive_hook();
11261122
}
1127-
/* XXX */
11281123

11291124
if (pymain->main_importer_path != NULL) {
11301125
pymain->status = pymain_run_main_from_importer(pymain);
@@ -1162,7 +1157,7 @@ pymain_repl(_PyMain *pymain)
11621157

11631158
Py_InspectFlag = 0;
11641159
pymain_run_interactive_hook();
1165-
/* XXX */
1160+
11661161
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &pymain->cf);
11671162
pymain->status = (res != 0);
11681163
}
@@ -1630,7 +1625,6 @@ pymain_init(_PyMain *pymain)
16301625
}
16311626

16321627
pymain->core_config._disable_importlib = 0;
1633-
/* TODO: Moar config options! */
16341628
pymain->config.install_signal_handlers = 1;
16351629

16361630
orig_argc = pymain->argc; /* For Py_GetArgcArgv() */

Python/pylifecycle.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,6 @@ _Py_SetLocaleFromEnv(int category)
606606
* safe to call without calling Py_Initialize first)
607607
*/
608608

609-
/* TODO: Progressively move functionality from Py_BeginInitialization to
610-
* Py_ReadConfig and Py_EndInitialization
611-
*/
612-
613609
_PyInitError
614610
_Py_InitializeCore(const _PyCoreConfig *config)
615611
{
@@ -881,10 +877,9 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
881877
return _Py_INIT_OK();
882878
}
883879

884-
/* TODO: Report exceptions rather than fatal errors below here */
885-
886-
if (_PyTime_Init() < 0)
880+
if (_PyTime_Init() < 0) {
887881
return _Py_INIT_ERR("can't initialize time");
882+
}
888883

889884
/* GetPath may initialize state that _PySys_EndInit locks
890885
in, and so has to be called first. */

0 commit comments

Comments
 (0)