mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-32030: Fix compiler warnings (#4921)
Fix compiler warnings in Py_FinalizeEx(): only define variables if they are needed, add #ifdef. Other cleanup changes: * _PyWarnings_InitWithConfig() is no more needed: call _PyWarnings_Init() instead. * Inline pymain_init_main_interpreter() in its caller. This subfunction is no more justifed.
This commit is contained in:
parent
21be85f520
commit
5d8624647d
4 changed files with 17 additions and 40 deletions
|
@ -7,9 +7,6 @@ extern "C" {
|
||||||
#ifndef Py_LIMITED_API
|
#ifndef Py_LIMITED_API
|
||||||
PyAPI_FUNC(PyObject*) _PyWarnings_Init(void);
|
PyAPI_FUNC(PyObject*) _PyWarnings_Init(void);
|
||||||
#endif
|
#endif
|
||||||
#ifdef Py_BUILD_CORE
|
|
||||||
PyAPI_FUNC(PyObject*) _PyWarnings_InitWithConfig(const _PyCoreConfig *config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyErr_WarnEx(
|
PyAPI_FUNC(int) PyErr_WarnEx(
|
||||||
PyObject *category,
|
PyObject *category,
|
||||||
|
|
|
@ -1151,27 +1151,6 @@ pymain_get_program_name(_PyMain *pymain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Initialize the main interpreter.
|
|
||||||
*
|
|
||||||
* Replaces previous call to Py_Initialize()
|
|
||||||
*
|
|
||||||
* Return 0 on success.
|
|
||||||
* Set pymain->err and return -1 on error.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
pymain_init_main_interpreter(_PyMain *pymain)
|
|
||||||
{
|
|
||||||
_PyInitError err;
|
|
||||||
|
|
||||||
err = _Py_InitializeMainInterpreter(&pymain->config);
|
|
||||||
if (_Py_INIT_FAILED(err)) {
|
|
||||||
pymain->err = err;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pymain_header(_PyMain *pymain)
|
pymain_header(_PyMain *pymain)
|
||||||
{
|
{
|
||||||
|
@ -2357,7 +2336,9 @@ pymain_init_python_main(_PyMain *pymain)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pymain_init_main_interpreter(pymain)) {
|
err = _Py_InitializeMainInterpreter(&pymain->config);
|
||||||
|
if (_Py_INIT_FAILED(err)) {
|
||||||
|
pymain->err = err;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1173,7 +1173,7 @@ create_filter(PyObject *category, _Py_Identifier *id)
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
init_filters(const _PyCoreConfig *config)
|
init_filters(void)
|
||||||
{
|
{
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
/* Py_DEBUG builds show all warnings by default */
|
/* Py_DEBUG builds show all warnings by default */
|
||||||
|
@ -1218,8 +1218,8 @@ static struct PyModuleDef warningsmodule = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PyObject*
|
PyMODINIT_FUNC
|
||||||
_PyWarnings_InitWithConfig(const _PyCoreConfig *config)
|
_PyWarnings_Init(void)
|
||||||
{
|
{
|
||||||
PyObject *m;
|
PyObject *m;
|
||||||
|
|
||||||
|
@ -1228,7 +1228,7 @@ _PyWarnings_InitWithConfig(const _PyCoreConfig *config)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_PyRuntime.warnings.filters == NULL) {
|
if (_PyRuntime.warnings.filters == NULL) {
|
||||||
_PyRuntime.warnings.filters = init_filters(config);
|
_PyRuntime.warnings.filters = init_filters();
|
||||||
if (_PyRuntime.warnings.filters == NULL)
|
if (_PyRuntime.warnings.filters == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1259,12 +1259,3 @@ _PyWarnings_InitWithConfig(const _PyCoreConfig *config)
|
||||||
_PyRuntime.warnings.filters_version = 0;
|
_PyRuntime.warnings.filters_version = 0;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
_PyWarnings_Init(void)
|
|
||||||
{
|
|
||||||
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
|
||||||
const _PyCoreConfig *config = &interp->core_config;
|
|
||||||
return _PyWarnings_InitWithConfig(config);
|
|
||||||
}
|
|
||||||
|
|
|
@ -737,7 +737,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize _warnings. */
|
/* Initialize _warnings. */
|
||||||
if (_PyWarnings_InitWithConfig(&interp->core_config) == NULL) {
|
if (_PyWarnings_Init() == NULL) {
|
||||||
return _Py_INIT_ERR("can't initialize warnings");
|
return _Py_INIT_ERR("can't initialize warnings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +847,9 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize warnings. */
|
/* Initialize warnings. */
|
||||||
if (PySys_HasWarnOptions()) {
|
if (interp->config.warnoptions != NULL &&
|
||||||
|
PyList_Size(interp->config.warnoptions) > 0)
|
||||||
|
{
|
||||||
PyObject *warnings_module = PyImport_ImportModule("warnings");
|
PyObject *warnings_module = PyImport_ImportModule("warnings");
|
||||||
if (warnings_module == NULL) {
|
if (warnings_module == NULL) {
|
||||||
fprintf(stderr, "'import warnings' failed; traceback:\n");
|
fprintf(stderr, "'import warnings' failed; traceback:\n");
|
||||||
|
@ -1021,9 +1023,15 @@ Py_FinalizeEx(void)
|
||||||
|
|
||||||
/* Copy the core config, PyInterpreterState_Delete() free
|
/* Copy the core config, PyInterpreterState_Delete() free
|
||||||
the core config memory */
|
the core config memory */
|
||||||
|
#ifdef Py_REF_DEBUG
|
||||||
int show_ref_count = interp->core_config.show_ref_count;
|
int show_ref_count = interp->core_config.show_ref_count;
|
||||||
|
#endif
|
||||||
|
#ifdef Py_TRACE_REFS
|
||||||
int dump_refs = interp->core_config.dump_refs;
|
int dump_refs = interp->core_config.dump_refs;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_PYMALLOC
|
||||||
int malloc_stats = interp->core_config.malloc_stats;
|
int malloc_stats = interp->core_config.malloc_stats;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Remaining threads (e.g. daemon threads) will automatically exit
|
/* Remaining threads (e.g. daemon threads) will automatically exit
|
||||||
after taking the GIL (in PyEval_RestoreThread()). */
|
after taking the GIL (in PyEval_RestoreThread()). */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue