fix struct handling in Py3
authorStefan Behnel <scoder@users.berlios.de>
Fri, 21 Aug 2009 11:37:57 +0000 (13:37 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 21 Aug 2009 11:37:57 +0000 (13:37 +0200)
Cython/Compiler/ExprNodes.py
Cython/Compiler/PyrexTypes.py

index 0f77303aeb59ad42912b47e033443cd840523f2f..8ffc44d98032fb0600e5af0090dcac2ffdb8f009 100644 (file)
@@ -3528,9 +3528,10 @@ class DictNode(ExprNode):
                     error(item.key.pos, "Invalid struct field identifier")
                     item.key = IdentifierStringNode(item.key.pos, value="<error>")
                 else:
-                    member = dst_type.scope.lookup_here(item.key.value)
+                    key = str(item.key.value) # converts string literals to unicode in Py3
+                    member = dst_type.scope.lookup_here(key)
                     if not member:
-                        error(item.key.pos, "struct '%s' has no field '%s'" % (dst_type, item.key.value))
+                        error(item.key.pos, "struct '%s' has no field '%s'" % (dst_type, key))
                     else:
                         value = item.value
                         if isinstance(value, CoerceToPyTypeNode):
index e49b067daf84941f8a852d4ad70c59ce29da09b3..7936b91fabf385899e6617ccc7aed027d286c423 100644 (file)
@@ -1358,7 +1358,8 @@ class CStructOrUnionType(CType):
 
     def __eq__(self, other):
         try:
-            return self.name == other.name
+            return (isinstance(other, CStructOrUnionType) and
+                    self.name == other.name)
         except AttributeError:
             return False
 
@@ -1370,6 +1371,14 @@ class CStructOrUnionType(CType):
             # *some* kind of order
             return False
 
+    def __hash__(self):
+        try:
+            return self.__hashval
+        except AttributeError:
+            hashval = self.__hashval = hash(self.cname) ^ (sum([
+                hash(field.name) for field in self.scope.var_entries]) % 0xffff)
+            return hashval
+
     def is_complete(self):
         return self.scope is not None