[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] [PATCH 3/5] Use SIP_NULLPTR if return value is a pointer to an object
From:       Stefan Brüns <stefan.bruens () rwth-aachen ! de>
Date:       2018-09-29 14:27:47
Message-ID: 91138eb7-940a-4d64-854e-eb1f12daccee () rwthex-w2-a ! rwth-ad ! de
[Download RAW message or body]

Current versions of GCC and LLVM issue a warning "zero as null pointer
constant [-Wzero-as-null-pointer-constant]" if 0 is used.
In case a slot returns (no) PyObject, use SIP_NULLPTR.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
---
 sipgen/gencode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sipgen/gencode.c b/sipgen/gencode.c
index b08f255..e0d61c5 100644
--- a/sipgen/gencode.c
+++ b/sipgen/gencode.c
@@ -5924,7 +5924,7 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
         memberDef *md, FILE *fp)
 {
     char *arg_str, *decl_arg_str, *prefix, *ret_type;
-    int ret_int, has_args;
+    int ret_int, has_args, ret_ptr;
     overDef *od, *overs;
     scopedNameDef *fqcname;
     nameDef *pyname;
@@ -5955,17 +5955,21 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
     {
         ret_int = TRUE;
         ret_type = "int ";
+        ret_ptr = FALSE;
     }
     else
     {
         ret_int = FALSE;
+        ret_ptr = FALSE;
 
         if (isSSizeReturnSlot(md))
             ret_type = "SIP_SSIZE_T ";
         else if (isLongReturnSlot(md))
             ret_type = "long ";
-        else
+        else {
             ret_type = "PyObject *";
+            ret_ptr = TRUE;
+        }
     }
 
     has_args = TRUE;
@@ -6091,7 +6095,7 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
             prcode(fp,
 "        return %s;\n"
 "\n"
-                , (md->slot == cmp_slot ? "-2" : (ret_int ? "-1" : "0")));
+                , (md->slot == cmp_slot ? "-2" : (ret_int ? "-1" : (ret_ptr ? "SIP_NULLPTR" : "0"))));
         }
 
         if (has_args)
@@ -6194,7 +6198,7 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
                     prcode(fp, ", NULL);\n"
 "\n"
 "    return %s;\n"
-                        ,ret_int ? "-1" : "0");
+                        ,ret_int ? "-1" : (ret_ptr ? "SIP_NULLPTR" : "0"));
                 }
             }
         }
-- 
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