bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS#6030
bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS#6030serhiy-storchaka merged 6 commits intopython:masterfrom siddhesh:meth-noargs
Conversation
There was a problem hiding this comment.
This looks incorrect. But an existing code looks incorrect too. I suggest to revert this change (and all other questionable changes) and left them to a separate issue -- bpo-33031.
There was a problem hiding this comment.
OK, dropped from this PR.
There was a problem hiding this comment.
It should be compatible with reprfunc, not PyCFunction.
There was a problem hiding this comment.
I'll drop this one too since it looks like it will need an additional wrapper like odict_init.
There was a problem hiding this comment.
It should be compatible with getiterfunc, not PyCFunction.
There was a problem hiding this comment.
Likewise, I'll deal with it separately.
There was a problem hiding this comment.
It is getter.
void *Py_UNUSED(ignored)
``
There was a problem hiding this comment.
I'm tackling getters in a separate patch, so I'll drop this.
There was a problem hiding this comment.
void *Py_UNUSED(ignored)
There was a problem hiding this comment.
Likewise, I've got getter changes in another branch, so I'll fix it there.
There was a problem hiding this comment.
Needs the second argument of type void *. As well as other getters.
There was a problem hiding this comment.
I've made a separate bug report for the getters: issue33029.
There was a problem hiding this comment.
It is used both as PyCFunction and getter. It would be safer to declare the second parameter as void *.
There was a problem hiding this comment.
I suggest to left this for a separate issue.
There was a problem hiding this comment.
OK, I'll drop this and the other patch from this PR and make a different one.
There was a problem hiding this comment.
Explicit cast to PyCFunction at line 1590 is not needed.
The same with other functions which exactly match the signature of PyCFunction.
There was a problem hiding this comment.
I've kept the casts in place because we will eventually need it. To fully fix the warnings, the ml_meth type should be like so:
PyObject *(*) (PyObject *, PyObject *, ...)
so that it matches with all of the allowed method types provided that there is an explicit cast in place. Right now I am not sure if I should change the PyCFunction type to that or to make a new PyCFunctionAny just for ml_meth. Since we're on this topic, what do you think is the preferred change? I suppose both change API, but not in a completely incompatible way.
There was a problem hiding this comment.
The casts are not needed if the signature matches PyCFunction. It is still needed if the function has type PyCFunctionWithKeywords, PyNoArgsFunction, etc. Removing unneeded casts will clean up the code and can prevent introducing new bugs when the signature be changed unintentionally.
There was a problem hiding this comment.
Thanks for the review, I'm pushing a version with most of the fixes you suggested, except for removal of the cast. I've kept the casts in place because we will eventually need it. To fully fix the warnings, the ml_meth type should be like so:
PyObject *(*) (PyObject *, PyObject *, ...)
so that it matches with all of the allowed method types provided that there is an explicit cast in place. Right now I am not sure if I should change the PyCFunction type to that or to make a new PyCFunctionAny just for ml_meth. Since we're on this topic, what do you think is the preferred change? I suppose both change API, but not in a completely incompatible way.
There was a problem hiding this comment.
I've made a separate bug report for the getters: issue33029.
There was a problem hiding this comment.
OK, I'll drop this and the other patch from this PR and make a different one.
There was a problem hiding this comment.
I've kept the casts in place because we will eventually need it. To fully fix the warnings, the ml_meth type should be like so:
PyObject *(*) (PyObject *, PyObject *, ...)
so that it matches with all of the allowed method types provided that there is an explicit cast in place. Right now I am not sure if I should change the PyCFunction type to that or to make a new PyCFunctionAny just for ml_meth. Since we're on this topic, what do you think is the preferred change? I suppose both change API, but not in a completely incompatible way.
There was a problem hiding this comment.
I'm tackling getters in a separate patch, so I'll drop this.
There was a problem hiding this comment.
Likewise, I've got getter changes in another branch, so I'll fix it there.
There was a problem hiding this comment.
I'll drop this one too since it looks like it will need an additional wrapper like odict_init.
There was a problem hiding this comment.
Likewise, I'll deal with it separately.
There was a problem hiding this comment.
OK, dropped from this PR.
METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 (unreleased as of now) due to the argument mismatch. Fix this by adding a dummy unused argument.
METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 (unreleased as of now) due to the argument mismatch. Fix this by adding a dummy unused argument.
|
Hi, here's the new patchset with dropped casts and resolved conflicts. |
There was a problem hiding this comment.
Casting to PyCFunction below no longer needed. And this is the only use of PyCFunction, thus its declaration can be removed.
There was a problem hiding this comment.
Ah I missed this one, I'll fix it.
There was a problem hiding this comment.
The casts are not needed if the signature matches PyCFunction. It is still needed if the function has type PyCFunctionWithKeywords, PyNoArgsFunction, etc. Removing unneeded casts will clean up the code and can prevent introducing new bugs when the signature be changed unintentionally.
METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 (unreleased as of now) due to the argument mismatch. Fix this by adding a dummy unused argument wherever it isn't present and mark it as unused to make it consistent with other similar uses.
METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 (unreleased as of now) due to the argument mismatch. Fix this by adding a dummy unused argument.
METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 (unreleased as of now) due to the argument mismatch. Fix this by adding a dummy unused argument.
gcc 8 has added a new warning heuristic to detect invalid function casts and a stock python build seems to hit that warning quite often. The most common is the cast of a METH_NOARGS function (that uses just one argument) to a PyCFunction. Fix this by adding a dummy argument to all the affected callback functions.
I have split the changes by directory and also made a separate commit where the change was not just a trivial dummy argument addition, as is the case in a4ee3ad and 58eaf31.
https://bugs.python.org/issue33012