MAINT: f2py: don't generate code that triggers -Wsometimes-uninitialized#20940
MAINT: f2py: don't generate code that triggers -Wsometimes-uninitialized#20940rgommers merged 3 commits intonumpy:mainfrom
-Wsometimes-uninitialized#20940Conversation
…ized`
Warnings look like:
```
scipy/linalg/_flapackmodule.c:2200:9: warning: variable 'return_value' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (capi_j>capi_i)
^~~~~~~~~~~~~
scipy/linalg/_flapackmodule.c:2217:12: note: uninitialized use occurs here
return return_value;
^~~~~~~~~~~~
scipy/linalg/_flapackmodule.c:2200:5: note: remove the 'if' if its condition is always true
if (capi_j>capi_i)
^~~~~~~~~~~~~~~~~~
scipy/linalg/_flapackmodule.c:2099:21: note: initialize the variable 'return_value' to silence this warning
int return_value;
^
= 0
```
|
I take it you would like this backported? |
|
Is that the correct return value in those cases? |
Not sure, it may be that something else is missing. That code is pretty much unreadable. |
|
Figure |
I'll leave it to 1.22.3 then. I want to get the initial 1.22.x problems fixed up as soon as possible so we can deal with the more obscure ones. |
|
Since this code is generated it would be better to initialize it within the Basically I would prefer to fix the return statement generation than the initialization. |
|
Background: the referenced code corresponds to call-back functions that a Fortran function uses to call Python functions. Normally, a non-void call-back function is expected to return a value, that is, the user-provided Python function ought to return a numeric value. However, if it returns To fix this issue, we have the following objectives:
I suggest the following solution:
|
pearu
left a comment
There was a problem hiding this comment.
Handle complex return value case and trigger a warning if user-provided cb function does return a value.
|
Thanks @pearu. Do you just want to push to this PR? I'm happy for you to take it over. My change is just a minimal "make annoying warnings go away", but I have little desire to make further changes. |
|
@rgommers how about this: I'll push changes to your branch and make sure that numpy CI is green, and you'll take care of testing the scipy part? |
|
Sure, that sounds good! |
…ized` (numpy#20940) * MAINT: f2py: don't generate code that triggers `-Wsometimes-uninitialized` Warnings look like: ``` scipy/linalg/_flapackmodule.c:2200:9: warning: variable 'return_value' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (capi_j>capi_i) ^~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2217:12: note: uninitialized use occurs here return return_value; ^~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2200:5: note: remove the 'if' if its condition is always true if (capi_j>capi_i) ^~~~~~~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2099:21: note: initialize the variable 'return_value' to silence this warning int return_value; ^ = 0 ``` Also: - Initialize complex return value. - Warn on non-void callback returning None. - Use brackets in if-else block. This makes the code more readable. Co-authored-by: Pearu Peterson <pearu.peterson@gmail.com>
-Wsometimes-uninitialized-Wsometimes-uninitialized
…ized` (numpy#20940) * MAINT: f2py: don't generate code that triggers `-Wsometimes-uninitialized` Warnings look like: ``` scipy/linalg/_flapackmodule.c:2200:9: warning: variable 'return_value' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (capi_j>capi_i) ^~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2217:12: note: uninitialized use occurs here return return_value; ^~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2200:5: note: remove the 'if' if its condition is always true if (capi_j>capi_i) ^~~~~~~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2099:21: note: initialize the variable 'return_value' to silence this warning int return_value; ^ = 0 ``` Also: - Initialize complex return value. - Warn on non-void callback returning None. - Use brackets in if-else block. This makes the code more readable. Co-authored-by: Pearu Peterson <pearu.peterson@gmail.com>
…ized` (numpy#20940) * MAINT: f2py: don't generate code that triggers `-Wsometimes-uninitialized` Warnings look like: ``` scipy/linalg/_flapackmodule.c:2200:9: warning: variable 'return_value' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (capi_j>capi_i) ^~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2217:12: note: uninitialized use occurs here return return_value; ^~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2200:5: note: remove the 'if' if its condition is always true if (capi_j>capi_i) ^~~~~~~~~~~~~~~~~~ scipy/linalg/_flapackmodule.c:2099:21: note: initialize the variable 'return_value' to silence this warning int return_value; ^ = 0 ``` Also: - Initialize complex return value. - Warn on non-void callback returning None. - Use brackets in if-else block. This makes the code more readable. Co-authored-by: Pearu Peterson <pearu.peterson@gmail.com>
Warnings all look like: