Commit 33c377ed authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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
parent ae342cf7
...@@ -54,23 +54,8 @@ typedef struct { ...@@ -54,23 +54,8 @@ typedef struct {
wchar_t *home; wchar_t *home;
} _PyPathConfig; } _PyPathConfig;
#ifdef MS_WINDOWS #define _PyPathConfig_INIT {.module_search_path = NULL}
#define _PyPathConfig_INIT \ /* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
{.program_full_path = NULL, \
.prefix = NULL, \
.dll_path = NULL, \
.module_search_path = NULL, \
.program_name = NULL, \
.home = NULL}
#else
#define _PyPathConfig_INIT \
{.program_full_path = NULL, \
.prefix = NULL, \
.exec_prefix = NULL, \
.module_search_path = NULL, \
.program_name = NULL, \
.home = NULL}
#endif
PyAPI_DATA(_PyPathConfig) _Py_path_config; PyAPI_DATA(_PyPathConfig) _Py_path_config;
...@@ -116,6 +101,7 @@ typedef struct pyruntimestate { ...@@ -116,6 +101,7 @@ typedef struct pyruntimestate {
} _PyRuntimeState; } _PyRuntimeState;
#define _PyRuntimeState_INIT {.initialized = 0, .core_initialized = 0} #define _PyRuntimeState_INIT {.initialized = 0, .core_initialized = 0}
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
PyAPI_DATA(_PyRuntimeState) _PyRuntime; PyAPI_DATA(_PyRuntimeState) _PyRuntime;
PyAPI_FUNC(_PyInitError) _PyRuntimeState_Init(_PyRuntimeState *); PyAPI_FUNC(_PyInitError) _PyRuntimeState_Init(_PyRuntimeState *);
......
...@@ -38,19 +38,8 @@ typedef struct { ...@@ -38,19 +38,8 @@ typedef struct {
int show_alloc_count; /* -X showalloccount */ int show_alloc_count; /* -X showalloccount */
} _PyCoreConfig; } _PyCoreConfig;
#define _PyCoreConfig_INIT \ #define _PyCoreConfig_INIT (_PyCoreConfig){.use_hash_seed = -1}
(_PyCoreConfig){\ /* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
.ignore_environment = 0, \
.use_hash_seed = -1, \
.hash_seed = 0, \
._disable_importlib = 0, \
.allocator = NULL, \
.dev_mode = 0, \
.faulthandler = 0, \
.tracemalloc = 0, \
.import_time = 0, \
.show_ref_count = 0, \
.show_alloc_count = 0}
/* Placeholders while working on the new configuration API /* Placeholders while working on the new configuration API
* *
...@@ -69,11 +58,8 @@ typedef struct { ...@@ -69,11 +58,8 @@ typedef struct {
} _PyMainInterpreterConfig; } _PyMainInterpreterConfig;
#define _PyMainInterpreterConfig_INIT \ #define _PyMainInterpreterConfig_INIT \
(_PyMainInterpreterConfig){\ (_PyMainInterpreterConfig){.install_signal_handlers = -1}
.install_signal_handlers = -1, \ /* Note: _PyMainInterpreterConfig_INIT sets other fields to 0/NULL */
.module_search_path_env = NULL, \
.home = NULL, \
.program_name = NULL}
typedef struct _is { typedef struct _is {
......
...@@ -160,7 +160,7 @@ pymain_get_env_var(const char *name) ...@@ -160,7 +160,7 @@ pymain_get_env_var(const char *name)
static void static void
pymain_run_statup(PyCompilerFlags *cf) pymain_run_startup(PyCompilerFlags *cf)
{ {
char *startup = Py_GETENV("PYTHONSTARTUP"); char *startup = Py_GETENV("PYTHONSTARTUP");
if (startup == NULL || startup[0] == '\0') { if (startup == NULL || startup[0] == '\0') {
...@@ -367,8 +367,6 @@ pymain_run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf) ...@@ -367,8 +367,6 @@ pymain_run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf)
/* Main program */ /* Main program */
/*TODO: Add arg processing to PEP 432 as a new configuration setup API
*/
typedef struct { typedef struct {
size_t len; size_t len;
wchar_t **options; wchar_t **options;
...@@ -949,8 +947,6 @@ pymain_get_program_name(_PyMain *pymain) ...@@ -949,8 +947,6 @@ pymain_get_program_name(_PyMain *pymain)
* *
* Replaces previous call to Py_Initialize() * Replaces previous call to Py_Initialize()
* *
* TODO: Move environment queries (etc) into Py_ReadConfig
*
* Return 0 on success. * Return 0 on success.
* Set pymain->err and return -1 on error. * Set pymain->err and return -1 on error.
*/ */
...@@ -1121,10 +1117,9 @@ pymain_run_filename(_PyMain *pymain) ...@@ -1121,10 +1117,9 @@ pymain_run_filename(_PyMain *pymain)
if (cmdline->filename == NULL && pymain->stdin_is_interactive) { if (cmdline->filename == NULL && pymain->stdin_is_interactive) {
Py_InspectFlag = 0; /* do exit on SystemExit */ Py_InspectFlag = 0; /* do exit on SystemExit */
pymain_run_statup(&pymain->cf); pymain_run_startup(&pymain->cf);
pymain_run_interactive_hook(); pymain_run_interactive_hook();
} }
/* XXX */
if (pymain->main_importer_path != NULL) { if (pymain->main_importer_path != NULL) {
pymain->status = pymain_run_main_from_importer(pymain); pymain->status = pymain_run_main_from_importer(pymain);
...@@ -1162,7 +1157,7 @@ pymain_repl(_PyMain *pymain) ...@@ -1162,7 +1157,7 @@ pymain_repl(_PyMain *pymain)
Py_InspectFlag = 0; Py_InspectFlag = 0;
pymain_run_interactive_hook(); pymain_run_interactive_hook();
/* XXX */
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &pymain->cf); int res = PyRun_AnyFileFlags(stdin, "<stdin>", &pymain->cf);
pymain->status = (res != 0); pymain->status = (res != 0);
} }
...@@ -1630,7 +1625,6 @@ pymain_init(_PyMain *pymain) ...@@ -1630,7 +1625,6 @@ pymain_init(_PyMain *pymain)
} }
pymain->core_config._disable_importlib = 0; pymain->core_config._disable_importlib = 0;
/* TODO: Moar config options! */
pymain->config.install_signal_handlers = 1; pymain->config.install_signal_handlers = 1;
orig_argc = pymain->argc; /* For Py_GetArgcArgv() */ orig_argc = pymain->argc; /* For Py_GetArgcArgv() */
......
...@@ -606,10 +606,6 @@ _Py_SetLocaleFromEnv(int category) ...@@ -606,10 +606,6 @@ _Py_SetLocaleFromEnv(int category)
* safe to call without calling Py_Initialize first) * safe to call without calling Py_Initialize first)
*/ */
/* TODO: Progressively move functionality from Py_BeginInitialization to
* Py_ReadConfig and Py_EndInitialization
*/
_PyInitError _PyInitError
_Py_InitializeCore(const _PyCoreConfig *config) _Py_InitializeCore(const _PyCoreConfig *config)
{ {
...@@ -881,10 +877,9 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) ...@@ -881,10 +877,9 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
return _Py_INIT_OK(); return _Py_INIT_OK();
} }
/* TODO: Report exceptions rather than fatal errors below here */ if (_PyTime_Init() < 0) {
if (_PyTime_Init() < 0)
return _Py_INIT_ERR("can't initialize time"); return _Py_INIT_ERR("can't initialize time");
}
/* GetPath may initialize state that _PySys_EndInit locks /* GetPath may initialize state that _PySys_EndInit locks
in, and so has to be called first. */ in, and so has to be called first. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment