From: Stefan Behnel Date: Fri, 21 Aug 2009 11:37:57 +0000 (+0200) Subject: fix struct handling in Py3 X-Git-Tag: 0.12.alpha0~230 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a22a4487a4f7cfd47a556cc432738ec6fedb2a89;p=cython.git fix struct handling in Py3 --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 0f77303a..8ffc44d9 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3528,9 +3528,10 @@ class DictNode(ExprNode): error(item.key.pos, "Invalid struct field identifier") item.key = IdentifierStringNode(item.key.pos, value="") 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): diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index e49b067d..7936b91f 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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