New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-36328: Fix compiler warning in Py_NewInterpreter() #12381
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in new_interpreter()
means this change is technically unnecessary. However, it's innocuous and mostly correct. The compiler is probably thrown off by how "fatal" errors are handled in the "init failed" cases.
Regardless, I recommend adding *tstate = NULL;
at the beginning of new_interpreter()
instead of in the various failure cases. With that you shouldn't need to change Py_NewInterpreter()
. It will also benefit any other call sites.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
FWIW, a related remaining issue I have with That said, it isn't that big a deal and you don't need to address it in this PR (or at all). :) However, it may be worth considering fixing here or opening a separate issue. At very least a comment would help. Dealing with it in the |
@ericsnowcurrently when adding diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 49a2f18e49..0c9ab4a95e 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1276,7 +1276,7 @@ static _PyInitError
new_interpreter(PyThreadState **tstate_p)
{
PyInterpreterState *interp;
- PyThreadState *tstate, *save_tstate;
+ PyThreadState *tstate = NULL, *save_tstate;
PyObject *bimod, *sysmod;
_PyInitError err;
@@ -1434,7 +1434,7 @@ handle_error:
PyThreadState *
Py_NewInterpreter(void)
{
- PyThreadState *tstate = NULL;
+ PyThreadState *tstate;
_PyInitError err = new_interpreter(&tstate);
if (_Py_INIT_FAILED(err)) {
_Py_ExitInitError(err); Python/pylifecycle.c: Dans la fonction « Py_NewInterpreter »:
Python/pylifecycle.c:1442:12: warning: « tstate » pourrait être utilisé sans être initialisé dans cette fonction [-Wmaybe-uninitialized]
return tstate;
^~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sadly, compiler are weak static analyzers which commonly emit false alarms. Adding "= NULL" doesn't hurt performance but allow to focus on real bugs: real warnings, by ignoring such false alarm.
I see multiple cases where new_interpreter() returns NULL on purpose. I have no opinion on this API. At least, the code didn't change since Python 3.6: it's not a a regression my recent changes using _PyInitError.
Honestly, I don't understand Py_NewInterpreter() API. I don't understand why some errors are fatal, but some others are not. Sadly, the current Py_NewInterpreter() API can only return NULL to indicate an error... and the exception is not passed to the caller: "handle_error:" label prints the exception and clears it...
Maybe things can be done, but IMHO this PR is just fine: it does what it says, fix a compiler warning :-) |
https://bugs.python.org/issue36328