[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2020-03-12 Thread STINNER Victor


STINNER Victor  added the comment:

FYI I modified SystemError("bad call flags") error message to include the 
method name in bpo-39884.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-08-13 Thread Zackery Spytz


Change by Zackery Spytz :


--
pull_requests: +14986
pull_request: https://github.com/python/cpython/pull/14814

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-04-30 Thread Andreas Schneider


Andreas Schneider  added the comment:

And how do you deal with METH_VARARGS|METH_KEYWORDS functions which have 3 
arguments?

PyObject* myfunc(PyObject *py_obj, PyObject *args, PyObject *kwargs)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-04-30 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Yes, and this particular case was fixed in 
adfffc7343ce7ebc88ec734a803d3247ba8927fb.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-04-30 Thread Andreas Schneider


Andreas Schneider  added the comment:

Looking at:

https://github.com/python/cpython/commit/359a2f3daba49fde0d3a07fb3c7a8b051c450d08

This is not fixing the underlying issue but hiding it. The right fix would be 
to use a union for ml_meth providing members for the 3 different function. So 
the developer could assign them correctly and the compiler would warn if he 
would do something wrong. Casting to (void *) is just hiding the problem not 
fixing it!

--
nosy: +asn

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-03-05 Thread STINNER Victor

STINNER Victor  added the comment:


New changeset 359a2f3daba49fde0d3a07fb3c7a8b051c450d08 by Victor Stinner 
(Stéphane Wirtel) in branch 'master':
bpo-33012: Fix compilation warnings in memoryobject.c and _collectionsmodule.c 
(GH-12179)
https://github.com/python/cpython/commit/359a2f3daba49fde0d3a07fb3c7a8b051c450d08


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-03-05 Thread Stéphane Wirtel

Change by Stéphane Wirtel :


--
pull_requests: +12175

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2019-03-05 Thread STINNER Victor


STINNER Victor  added the comment:

I marked bpo-36197 as a duplicate of this issue:

"""
gcc -pthread -c -Wno-unused-result -Wsign-compare 
-DDYNAMIC_ANNOTATIONS_ENABLED=1 -g -Og -Wall-std=c99 -Wextra 
-Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers 
-Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include
-DPy_BUILD_CORE -o Objects/memoryobject.o Objects/memoryobject.c
Objects/memoryobject.c:3112:21: warning: cast between incompatible function 
types from 'PyObject * (*)(PyMemoryViewObject *, PyObject *, PyObject *)' {aka 
'struct _object * (*)(struct  *, struct _object *, struct _object 
*)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * 
(*)(struct _object *, struct _object *)'} [-Wcast-function-type]
 {"tobytes", (PyCFunction)memory_tobytes, METH_VARARGS|METH_KEYWORDS, 
memory_tobytes_doc},


I am preparing a small PR for this issue.
"""

=> PR 12179

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-29 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 77000bbb104021b89368b9f7cab6f1417794e348 by Victor Stinner in 
branch '3.6':
bpo-33012: Fix more invalid function cast warnings with gcc 8. (GH-10751) 
(GH-10796)
https://github.com/python/cpython/commit/77000bbb104021b89368b9f7cab6f1417794e348


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-29 Thread miss-islington


miss-islington  added the comment:


New changeset 1659c08d5d17357597f220c4d297b19e7a59737c by Miss Islington (bot) 
in branch '3.7':
bpo-33012: Fix more invalid function cast warnings with gcc 8. (GH-10751)
https://github.com/python/cpython/commit/1659c08d5d17357597f220c4d297b19e7a59737c


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-29 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +10043

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-29 Thread miss-islington


Change by miss-islington :


--
pull_requests: +10042

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Only one function cast warning is left, and it is a separate issue: issue33015.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 1c607155c9e363489036ae6258b165a3fae75134 by Serhiy Storchaka in 
branch 'master':
bpo-33012: Fix more invalid function cast warnings with gcc 8. (GH-10751)
https://github.com/python/cpython/commit/1c607155c9e363489036ae6258b165a3fae75134


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread miss-islington


miss-islington  added the comment:


New changeset d5c8bd8e4cc04873254f0bd38895a6479c23c8aa by Miss Islington (bot) 
in branch '3.6':
bpo-33012: Fix signatures of METH_NOARGS functions. (GH-10736) (GH-10748)
https://github.com/python/cpython/commit/d5c8bd8e4cc04873254f0bd38895a6479c23c8aa


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset ad8ac54aa3d2323bdb5feb5e858a922840358187 by Serhiy Storchaka in 
branch '3.7':
bpo-33012: Fix signatures of METH_NOARGS functions. (GH-10736) (GH-10748)
https://github.com/python/cpython/commit/ad8ac54aa3d2323bdb5feb5e858a922840358187


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread miss-islington


Change by miss-islington :


--
pull_requests: +9998

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +9996

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread STINNER Victor


STINNER Victor  added the comment:

> New changeset 62be74290aca26d16f3f55ece7ff6dad14e60e8d by Serhiy Storchaka in 
> branch 'master':
> bpo-33012: Fix invalid function cast warnings with gcc 8. (GH-6749)

I still get something 100 warnings with GCC 8.2.1 on Fedora 29. I wrote PR 
10744 to add a macro to cast a function pointer.

I chose to add a macro, so it will be easier to spot where we cast function 
pointers and change the implementation (cast) if needed at a single place.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +9991

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 62be74290aca26d16f3f55ece7ff6dad14e60e8d by Serhiy Storchaka in 
branch 'master':
bpo-33012: Fix invalid function cast warnings with gcc 8. (GH-6749)
https://github.com/python/cpython/commit/62be74290aca26d16f3f55ece7ff6dad14e60e8d


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 81524022d0c0df7a41f9b2b2df41e2ebe140e610 by Serhiy Storchaka in 
branch 'master':
bpo-33012: Fix signatures of METH_NOARGS funstions. (GH-10736)
https://github.com/python/cpython/commit/81524022d0c0df7a41f9b2b2df41e2ebe140e610


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +9983

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-11-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 4a934d490fac779d8954a8292369c4506bab23fa by Serhiy Storchaka in 
branch 'master':
bpo-33012: Fix invalid function cast warnings with gcc 8 in Argument Clinic. 
(GH-6748)
https://github.com/python/cpython/commit/4a934d490fac779d8954a8292369c4506bab23fa


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-10-24 Thread Michael Airey


Michael Airey  added the comment:

Try this - https://github.com/siddhesh/cpython/tree/func-cast

--
nosy: +resmord

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-10-24 Thread Gregory P. Smith


Change by Gregory P. Smith :


--
nosy: +gregory.p.smith
versions: +Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-10-15 Thread STINNER Victor


STINNER Victor  added the comment:

I marked bpo-34992 as a duplicate of this issue:

I use Fedora 28 and gcc (GCC) 8.1.1 20180712 (Red Hat 8.1.1-5)

and I get a lot of warnings, with the standard config of Python (./configure)

Objects/call.c: In function '_PyMethodDef_RawFastCallDict':
Objects/call.c:515:24: warning: cast between incompatible function types from 
'PyCFunction' {aka 'struct _object * (*)(struct _object *, struct _object *)'} 
to 'PyObject * (*)(PyObject *, PyObject *, PyObject *)' {aka 'struct _object * 
(*)(struct _object *, struct _object *, struct _object *)'} 
[-Wcast-function-type]
 result = (*(PyCFunctionWithKeywords)meth) (self, argstuple, 
kwargs);
^
Objects/call.c:530:20: warning: cast between incompatible function types from 
'PyCFunction' {aka 'struct _object * (*)(struct _object *, struct _object *)'} 
to 'PyObject * (*)(PyObject *, PyObject * const*, Py_ssize_t)' {aka 'struct 
_object * (*)(struct _object *, struct _object * const*, long int)'} 
[-Wcast-function-type]
 result = (*(_PyCFunctionFast)meth) (self, args, nargs);
^
Objects/call.c:538:49: warning: cast between incompatible function types from 
'PyCFunction' {aka 'struct _object * (*)(struct _object *, struct _object *)'} 
to 'PyObject * (*)(PyObject *, PyObject * const*, Py_ssize_t,  PyObject *)' 
{aka 'struct _object * (*)(struct _object *, struct _object * const*, long int, 
 struct _object *)'} [-Wcast-function-type]
 _PyCFunctionFastWithKeywords fastmeth = 
(_PyCFunctionFastWithKeywords)meth;



+- 827 warnings

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-09-23 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

If I click the link for PR 6748, I see a page with "We went looking everywhere, 
but couldn’t find those commits."  Maybe the PR needs to be refreshed or closed 
and maybe reopened. PR 6749 looks normal.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-06-03 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

The problem with invalid function signatures was initially reported in old 
issue1648268.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-28 Thread Xavier de Gaye

Xavier de Gaye  added the comment:

> There are still quite a few similar warnings on git-master. Do they indicate 
> the same problem or should I open new issues?

This is the same issue, the warning line ends with [-Wcast-function-type].

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-28 Thread Xavier de Gaye

Xavier de Gaye  added the comment:

> Pedantically the correct way is to cast to a function pointer with no 
> prototype (empty parentheses)

Thanks for raising this point Antti. This is hinted at by the gcc 8 
documentation on -Wcast-function-type: "The function type void (*) (void) is 
special and matches everything, which can be used to suppress this warning" 
[1]. One cannot use empty parentheses though as this raises -Wstrict-prototypes 
on Python builds with gcc and -Wcast-function-type with gcc 8.

So (void *) may be replaced with (void (*) (void)) in my previous code snippets 
and also in PR 6748 and PR 6749 (I just checked my code).

[1] 
https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html#Warning-Options

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-28 Thread Chih-Hsuan Yen

Chih-Hsuan Yen  added the comment:

There are still quite a few similar warnings on git-master. Do they indicate 
the same problem or should I open new issues?

For example:

gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall 
-Wstrict-prototypes-std=c99 -Wextra -Wno-unused-result 
-Wno-unused-parameter -Wno-missing-field-initializers 
-Werror=implicit-function-declaration   -I. -I./Include-DPy_BUILD_CORE -o 
Objects/bytearrayobject.o Objects/bytearrayobject.c
In file included from Objects/bytearrayobject.c:96:
Objects/clinic/bytearrayobject.c.h:677:23: warning: cast between incompatible 
function types from ‘PyObject * (*)(PyByteArrayObject *, PyObject * const*, 
Py_ssize_t)’ {aka ‘struct _object * (*)(struct  *, struct _object * 
const*, long int)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct 
_object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, 
bytearray_reduce_ex__doc__},
   ^
Objects/bytearrayobject.c:2136:5: note: in expansion of macro 
‘BYTEARRAY_REDUCE_EX_METHODDEF’
 BYTEARRAY_REDUCE_EX_METHODDEF
 ^

I'm using GCC 8.1.0 on Arch Linux.

--
nosy: +yan12125

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-28 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

> Pedantically the correct way is to cast to a function pointer with no 
> prototype (empty parentheses) and from that to the target type. See for 
> example. See for example https://godbolt.org/g/FdPdUj

This is one way that the gcc diagnostics explicitly allow in addition to 
variable arguments like so: https://godbolt.org/g/Dtb4fv

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-27 Thread Antti Haapala

Antti Haapala  added the comment:

Well, there's only one problem with casting to void *: while converting the 
function pointer to another *is* standard-compliant, and GCC is being just 
hypersensitive here, casting a function pointer to void * isn't, though it is a 
common extension (http://port70.net/~nsz/c/c11/n1570.html#J.5.7).

Pedantically the correct way is to cast to a function pointer with no prototype 
(empty parentheses) and from that to the target type. See for example. See for 
example https://godbolt.org/g/FdPdUj

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-27 Thread Xavier de Gaye

Xavier de Gaye  added the comment:

> But the problem is that additional flags can be used, e.g. METH_CLASS.

Right, https://docs.python.org/3/c-api/structures.html says: "The individual 
flags indicate either a calling convention or a binding convention". This may 
be overcome by introducing another macro with 2 arguments, the second argument 
being used to set the binding convention flag:

#define SET_METH_VARARGS_KEYWORDS_FLAG(func, flag) \
(PyCFunction)(void *)(PyCFunctionWithKeywords)func, 
METH_VARARGS|METH_KEYWORDS|flag
#define SET_METH_VARARGS_KEYWORDS(func) SET_METH_VARARGS_KEYWORDS_FLAG(func, 
0x)

The refactoring would be quite large though.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-26 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Great idea!

But the problem is that additional flags can be used, e.g. METH_CLASS.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-26 Thread Xavier de Gaye

Xavier de Gaye  added the comment:

I propose to enhance the changes made by PR 6748 and PR 6749 so that gcc 8 
triggers a warning when the function type of a PyMethodDef element does not 
match its flags by using a macro (see below) that casts the function first to 
the function type corresponding to those flags and then to (void *) as done in 
those PRs to silence the warning when cast to PyCFunction. This would allow 
detecting bugs such as the one found in issue33454.

With the following patch (it is just an example) gcc 8 would emit a warning if 
bisect_right() does not match the type (in the sense defined by 
-Wcast-function-type) of PyCFunctionWithKeywords:

diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c
index 831e10aa60..85fb0c188e 100644
--- a/Modules/_bisectmodule.c
+++ b/Modules/_bisectmodule.c
@@ -216,15 +216,14 @@ If x is already in a, insert it to the left of the 
leftmost x.\n\
 Optional args lo (default 0) and hi (default len(a)) bound the\n\
 slice of a to be searched.\n");
 
+#define SET_METH_VARARGS_KEYWORDS(func) \
+(PyCFunction)(void *)(PyCFunctionWithKeywords)(func), 
METH_VARARGS|METH_KEYWORDS
+
 static PyMethodDef bisect_methods[] = {
-{"bisect_right", (PyCFunction)bisect_right,
-METH_VARARGS|METH_KEYWORDS, bisect_right_doc},
-{"insort_right", (PyCFunction)insort_right,
-METH_VARARGS|METH_KEYWORDS, insort_right_doc},
-{"bisect_left", (PyCFunction)bisect_left,
-METH_VARARGS|METH_KEYWORDS, bisect_left_doc},
-{"insort_left", (PyCFunction)insort_left,
-METH_VARARGS|METH_KEYWORDS, insort_left_doc},
+{"bisect_right", SET_METH_VARARGS_KEYWORDS(bisect_right), 
bisect_right_doc},
+{"insort_right", SET_METH_VARARGS_KEYWORDS(insort_right), 
insort_right_doc},
+{"bisect_left", SET_METH_VARARGS_KEYWORDS(bisect_left), bisect_left_doc},
+{"insort_left", SET_METH_VARARGS_KEYWORDS(insort_left), insort_left_doc},
 {NULL, NULL} /* sentinel */
 };

--
nosy: +xdegaye

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-25 Thread Eitan Adler

Change by Eitan Adler :


--
nosy: +eitan.adler

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-25 Thread miss-islington

miss-islington  added the comment:


New changeset 20b797dafa149afcdd7b64e489eb8ea1386d8eb4 by Miss Islington (bot) 
in branch '3.6':
bpo-33012: Add -Wno-cast-function-type for gcc 8. (GH-6757)
https://github.com/python/cpython/commit/20b797dafa149afcdd7b64e489eb8ea1386d8eb4


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-25 Thread miss-islington

Change by miss-islington :


--
pull_requests: +6751

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-25 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset ef91ddeae79497fac25545dd68ee55a5a3c60e8d by Serhiy Storchaka in 
branch '3.7':
bpo-33012: Add -Wno-cast-function-type for gcc 8. (GH-6757)
https://github.com/python/cpython/commit/ef91ddeae79497fac25545dd68ee55a5a3c60e8d


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

I think it safer to silence this kind of warnings in 3.7 and 3.6. PR 6757 does 
this.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6444

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread pmpp

Change by pmpp :


--
nosy: +pmpp

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

See also issue33454 about a real bug found thanks to these warnings.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Charalampos Stratakis

Charalampos Stratakis  added the comment:

Is it possible/feasible to fix that for the 3.7 and 3.6 branches as well?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

The following PRs fix warnings in casts to PyCFunction for method conventions 
different from METH_NOARGS, METH_O and
METH_VARARGS. PR 6748 does this for Argument Clinic generated code (all files 
except Tools/clinic/clinic.py are generated). PR 6749 does it for hand-written 
code. It also fixes few missed or new cases for METH_NOARGS.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6437

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-05-10 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6436

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-30 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 6405feecda6a5d5dd7a4240eb3054a2676ed29b1 by Serhiy Storchaka in 
branch 'master':
bpo-33012: Fix invalid function casts for long_long. (GH-6652)
https://github.com/python/cpython/commit/6405feecda6a5d5dd7a4240eb3054a2676ed29b1


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-30 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6348

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-30 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

Yeah, there are multiple such uses that need wrappers to actually fix for gcc8, 
which will be released this week.  I think I'll have more time for some more 
patches in this vein this weekend.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-30 Thread STINNER Victor

STINNER Victor  added the comment:

The commit 55edd0c185ad2d895b5d73e47d67049bc156b654 introduced a new warning:

gcc -pthread -c -Wno-unused-result -Wsign-compare -g -Og -Wall 
-Wstrict-prototypes -O0   -std=c99 -Wextra -Wno-unused-result 
-Wno-unused-parameter -Wno-missing-field-initializers 
-Werror=implicit-function-declaration   -I. -I./Include   -fPIC -DPy_BUILD_CORE 
-o Objects/longobject.o Objects/longobject.c
Objects/longobject.c:5359:5: warning: initialisation depuis un type pointeur 
incompatible [-Wincompatible-pointer-types]
 long_long,  /*nb_int*/
 ^
Objects/longobject.c:5359:5: note: (près de l'initialisation de « 
long_as_number.nb_int »)
Objects/longobject.c:5376:5: warning: initialisation depuis un type pointeur 
incompatible [-Wincompatible-pointer-types]
 long_long,  /* nb_index */
 ^
Objects/longobject.c:5376:5: note: (près de l'initialisation de « 
long_as_number.nb_index »)


It seems like a conversion to (unaryfunc) is needed when passing long_long as 
nb_int in long_as_number.

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-29 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 55edd0c185ad2d895b5d73e47d67049bc156b654 by Serhiy Storchaka 
(Siddhesh Poyarekar) in branch 'master':
bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. 
(GH-6030)
https://github.com/python/cpython/commit/55edd0c185ad2d895b5d73e47d67049bc156b654


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-09 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

Fair enough, I'll reduce my scope of changes for this patchset, especially 
since I'm unable to find enough time to work on the remaining changes I had 
thought of in the coming weeks.

I'll post an updated patch soonish.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-04 Thread Martin Panter

Martin Panter  added the comment:

Sorry, I realize there is a problem remaining with the pointer types for 
"Noddy_name" (Noddy vs PyObject pointers), so you can't remove the cast there. 
But my suggestion should still apply to other places, for instance the 
"error_out" method in Doc/howto/cporting.rst.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-04-01 Thread Martin Panter

Martin Panter  added the comment:

Siddhesh, it looks like your fixes make the C function signatures match the 
signature expected in the PyMethodDef structure. If so, I suggest to remove the 
(PyCFunction) casts from those structure definitions as well. For instance, now 
that we have

  PyObject *Noddy_name(Noddy *self, PyObject *Py_UNUSED(ignored))

I suggest changing

  PyMethodDef Noddy_methods[] = {
  {"name", (PyCFunction)Noddy_name, METH_NOARGS, ...

to

  PyMethodDef Noddy_methods[] = {
  {"name", Noddy_name, METH_NOARGS, ...

I suspect the casts were only added to hide compiler warnings related to this 
bug.

If you are proposing to add an ellipsis (...) to the definition of PyCFunction, 
that seems misguided. I understand this is incompatible under standard C. Are 
you relying on a GCC extension perhaps? Python is used with other compilers too.

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

I forgot to clarify that the function cast warning allows for variable argument 
casts as a wildcard, which is my basis for the PyObject *(*)(PyObject *, 
PyObject *, ...) fix proposal.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

> 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.

The explicit cast is precisely what enables the more nuanced function cast 
warning where it checks the function for type compatibility.  That is, it will 
check the types of the return and arguments and then warn in case of mismatch.

> 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. 

AFAICT, there is no right prototype for the METH_NOARGS function; there used to 
be a PyCFunctionWithNoArguments but that seems to have fallen out of favour 
some time back.  The prototype that seems to be commonly in use (and in clinic 
as well, which is what I based my patches on) is the PyCFunction, which seems 
like a safe way to do things.

> 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.

I have a patch in the works that makes it PyObject *(*)(PyObject *, PyObject *, 
...)

which allows for two compulsory arguments (fits in with most cases, provided 
the METH_NOARGS patch is accepted) and then the rest depending on the type of 
the cast function.  The rest of the PyMethodDef functions are much simpler 
fixes this way.  It also seems like a more intuitive description of the 
callbacks.

Then there are getter and setter and other function pointers that need similar 
fixes to METH_NOARGS.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Antti Haapala

Antti Haapala  added the comment:

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
dependencies: +Questionable code in OrderedDict definition

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Siddhesh Poyarekar

Siddhesh Poyarekar  added the comment:

> I don't have GCC 8 so I cannot verify this bug, but *function pointer casts* 
> are fine - any function pointer can be cast to any other function pointer - 
> it is only that they must *not* be called unless cast back again to be 
> compatible with the function definition. Any fix to the contrary might well 
> *cause* undefined behaviour!

Please see the attached PR; METH_NOARGS callbacks are inconsistent in their 
signature and many have just one argument while they're called with two 
arguments, the second being NULL.  The patch fixes these to consistently take 
and call with two arguments.

> Could you provide a sample of the *actual warnings* so that they could be 
> studied?

Here's one of a few hundred.

Objects/bytesobject.c:3085:25: warning: cast between incompatible function 
types from ‘PyObject * (*)(striterobject *)’ {aka ‘struct _object * (*)(struct 
 *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct 
_object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
 {"__reduce__",  (PyCFunction)striter_reduce, METH_NOARGS,
 ^
This is a new warning in gcc8, so you'll likely not find much reference, but 
here's a gcc bug report that might give you more context:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84531

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-15 Thread Antti Haapala

Antti Haapala  added the comment:

I don't have GCC 8 so I cannot verify this bug, but *function pointer casts* 
are fine - any function pointer can be cast to any other function pointer - it 
is only that they must *not* be called unless cast back again to be compatible 
with the function definition. Any fix to the contrary might well *cause* 
undefined behaviour!

Could you provide a sample of the *actual warnings* so that they could be 
studied?

--
nosy: +ztane

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-08 Thread Siddhesh Poyarekar

Change by Siddhesh Poyarekar :


--
keywords: +patch
pull_requests: +5792
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-06 Thread Charalampos Stratakis

Charalampos Stratakis  added the comment:

We are getting hit by that quite often on Fedora, with the transition to gcc 8 
and it creates unnecessary noise at our build logs. Thanks for working on that.

When you sent your PR I can test it within our build system and verify if it 
works.

--
nosy: +cstratak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-06 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Argument Clinic generates the following declaration for the second parameter of 
METH_NOARGS functions:

PyObject *Py_UNUSED(ignored)

It would be nice to follow the same style.

If the first parameter is of type PyObject* too, the explicit cast to 
PyCFunction can be removed.

Skip the curses module. It will be converted to Argument Clinic.

--
nosy: +serhiy.storchaka
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33012] Invalid function cast warnings with gcc 8 for METH_NOARGS

2018-03-06 Thread Siddhesh Poyarekar

New submission from Siddhesh Poyarekar :

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.  The fix is pretty simple but needs to be applied widely.  I'm 
slowly knocking them off in my spare time; WIP here, which has a few other 
types of warnings mixed in that I'll sift out during submission and also create 
separate bug reports for:

https://github.com/siddhesh/cpython/tree/func-cast

I'll clean up and post PR(s) once I am done but I figured I should file this 
report first since it is a pretty big change in terms of number of files 
touched and wanted to be sure that I'm making changes the way the community 
prefers.

--
components: Build
messages: 313317
nosy: siddhesh
priority: normal
severity: normal
status: open
title: Invalid function cast warnings with gcc 8 for METH_NOARGS
type: compile error

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com