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:14ztanesetrecipients: + ztane, serhiy.storchaka, siddhesh, cstratak
2018-03-15 15:27:14ztanesetmessageid: <1521127634.83.0.467229070634.issue33012@psf.upfronthosting.co.za>
2018-03-15 15:27:14ztanelinkissue33012 messages
2018-03-15 15:27:14ztanecreate