[PyQt] [PATCH v2 3/6] Use SIP_NULLPTR if return value is a pointer to an object

Stefan Brüns stefan.bruens at rwth-aachen.de
Mon Oct 1 02:58:46 BST 2018


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 at 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 2ce4b22..5112525 100644
--- a/sipgen/gencode.c
+++ b/sipgen/gencode.c
@@ -5913,7 +5913,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;
@@ -5944,17 +5944,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;
@@ -6080,7 +6084,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)
@@ -6183,7 +6187,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



More information about the PyQt mailing list