[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] [PATCH 4/5] Fix GCC cast-function-type warning
From: Stefan BrĂ¼ns <stefan.bruens () rwth-aachen ! de>
Date: 2018-09-29 14:27:48
Message-ID: e581223d-dacc-4d5b-a95f-fec3113edf50 () rwthex-w2-a ! rwth-ad ! de
[Download RAW message or body]
Python bindings require to cast PyCFunctionWithKeywords to PyCFunction.
The canonical way to do this is via an intermediate cast to
<void(*)(void)>:
"The function type "void (*) (void)" is special and matches everything,
which can be used to suppress this [-Wcast-function-type] warning."
The initial cast to PyCFunctionWithKeywords rejects any other type,
serving as a saveguard.
---
sipgen/gencode.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/sipgen/gencode.c b/sipgen/gencode.c
index e0d61c5..20dea03 100644
--- a/sipgen/gencode.c
+++ b/sipgen/gencode.c
@@ -4786,16 +4786,23 @@ static void prMethodTable(sipSpec *pt, sortedMethTab *mtable, \
int nr, for (i = 0; i < nr; ++i)
{
memberDef *md = mtable[i].md;
- const char *cast, *flags;
+ const char *cast, *flags, *cast_end;
if (noArgParser(md) || useKeywordArgs(md))
{
- cast = "(PyCFunction)";
+ if (generating_c) {
+ cast = "(PyCFunction)(";
+ cast_end = ")";
+ } else {
+ cast = \
"reinterpret_cast<PyCFunction>(reinterpret_cast<void(*)(void)>(reinterpret_cast<PyCFunctionWithKeywords>(";
+ cast_end = ")))";
+ }
flags = "|METH_KEYWORDS";
}
else
{
cast = "";
+ cast_end = "";
flags = "";
}
@@ -4803,7 +4810,7 @@ static void prMethodTable(sipSpec *pt, sortedMethTab *mtable, \
int nr, md->membernr = i;
prcode(fp,
-" {SIP_MLNAME_CAST(%N), %smeth_%L_%s, METH_VARARGS%s, ", md->pyname, cast, iff, \
md->pyname->text, flags); +" {SIP_MLNAME_CAST(%N), %smeth_%L_%s%s, METH_VARARGS%s, \
", md->pyname, cast, iff, md->pyname->text, cast_end, flags);
if (hasMemberDocstring(pt, overs, md, iff))
prcode(fp, "SIP_MLDOC_CAST(doc_%L_%s)", iff, md->pyname->text);
--
2.19.0
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic