Use assert instead of if without else to ensure an object pointer is not NULL.
authorThomas Hunger <hto@arcor.de>
Fri, 21 Sep 2007 11:16:39 +0000 (13:16 +0200)
committerThomas Hunger <hto@arcor.de>
Fri, 21 Sep 2007 11:16:39 +0000 (13:16 +0200)
gcc complained that a variable might be used uninitialized, which is
true. If NULL is passed, all code gets executed with an
uninitialized variable which is an error in almost every case.
Since python itself never passes NULL, only a real error in
other c code could trigger the assert.

Cython/Compiler/Nodes.py

index 8f6b729f155b6d0f424a72892a610fb20b6e2f37..12cc26dbd2ae5d51b21abb71f7df9d46fc2b329a 100644 (file)
@@ -1141,9 +1141,8 @@ class DefNode(FuncDefNode):
         old_type = arg.hdr_type
         new_type = arg.type
         if old_type.is_pyobject:
-            code.putln("if (likely(%s)) {" % arg.hdr_cname)
+            code.putln("assert(%s);" % arg.hdr_cname)
             self.generate_arg_conversion_from_pyobject(arg, code)
-            code.putln("}")
         elif new_type.is_pyobject:
             self.generate_arg_conversion_to_pyobject(arg, code)
         else: