This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xdegaye
Recipients cstratak, eitan.adler, martin.panter, miss-islington, pmpp, serhiy.storchaka, siddhesh, vstinner, xdegaye, ztane
Date 2018-05-26.15:16:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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");
+    (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 */
Date User Action Args
2018-05-26 15:16:28xdegayesetrecipients: + xdegaye, vstinner, pmpp, martin.panter, serhiy.storchaka, ztane, eitan.adler, siddhesh, cstratak, miss-islington
2018-05-26 15:16:28xdegayesetmessageid: <>
2018-05-26 15:16:28xdegayelinkissue33012 messages
2018-05-26 15:16:28xdegayecreate