simplify search for duplicate values in SwitchTransform and make it safer for unexpec...
authorStefan Behnel <stefan_ml@behnel.de>
Sun, 12 May 2013 12:22:16 +0000 (14:22 +0200)
committerStefan Behnel <stefan_ml@behnel.de>
Sun, 12 May 2013 12:22:16 +0000 (14:22 +0200)
Cython/Compiler/Optimize.py

index 555ef88..b0ae989 100644 (file)
@@ -874,7 +874,12 @@ class SwitchTransform(Visitor.VisitorTransform):
             else:
                 # this isn't completely safe as we don't know the
                 # final C value, but this is about the best we can do
-                seen.add(getattr(getattr(value, 'entry', None), 'cname'))
+                try:
+                    if value.entry.cname in seen:
+                        return True
+                except AttributeError:
+                    return True  # play safe
+                seen.add(value.entry.cname)
         return False
 
     def visit_IfStatNode(self, node):