Message313886
| Author |
ztane |
| Recipients |
cstratak, serhiy.storchaka, siddhesh, ztane |
| Date |
2018年03月15日.15:27:14 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1521127634.83.0.467229070634.issue33012@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Yea, I looked into `ceval.c` and the function is *called incorrectly*, so there is undefined behaviour there - it has been wrong all along, in 3.5 all the way down to 2-something
if (flags & (METH_NOARGS | METH_O)) {
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
if (flags & METH_NOARGS && na == 0) {
C_TRACE(x, (*meth)(self,NULL));
x = _Py_CheckFunctionResult(func, x, NULL);
}
The warning in GCC shouldn't probably have been enabled at all in `-Wall -Wextra` because the cast is explicit. However, it is somewhat true.
However, the correct way to fix would be to have the METH_NOARGS case cast the function to the right prototype. There exists lots of existing code that *is* going to break too.
Perhaps PyCFunction should declare no prototype, i.e. empty parentheses, for backwards compatibility:
typedef PyObject *(*PyCFunction)();
and deprecate it; start using a new typedef for it - and then add proper casts in every place that call a function. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2018年03月15日 15:27:14 | ztane | set | recipients:
+ ztane, serhiy.storchaka, siddhesh, cstratak |
| 2018年03月15日 15:27:14 | ztane | set | messageid: <1521127634.83.0.467229070634.issue33012@psf.upfronthosting.co.za> |
| 2018年03月15日 15:27:14 | ztane | link | issue33012 messages |
| 2018年03月15日 15:27:14 | ztane | create |
|