# HG changeset patch # User Paul Boddie # Date 1480954714 -3600 # Node ID feefdbfb5934979aa54bc7321ea17ef2ab50f30b # Parent 9f7a9aff1ca4cf64eaf898cd3aa84fd93d90b164 Encode type attributes explicitly, avoiding identification issues when classes are defined in locations that are reused for other objects. diff -r 9f7a9aff1ca4 -r feefdbfb5934 encoders.py --- a/encoders.py Mon Dec 05 16:03:06 2016 +0100 +++ b/encoders.py Mon Dec 05 17:18:34 2016 +0100 @@ -389,6 +389,18 @@ return "#%s" % path +def decode_type_attribute(s): + + "Decode the special type attribute 's'." + + return s[1:] + +def is_type_attribute(s): + + "Return whether 's' is a type attribute name." + + return s.startswith("#") + # A mapping from kinds to structure size reference prefixes. diff -r 9f7a9aff1ca4 -r feefdbfb5934 generator.py --- a/generator.py Mon Dec 05 16:03:06 2016 +0100 +++ b/generator.py Mon Dec 05 17:18:34 2016 +0100 @@ -29,7 +29,8 @@ encode_path, \ encode_predefined_reference, encode_size, \ encode_symbol, encode_tablename, \ - encode_type_attribute + encode_type_attribute, decode_type_attribute, \ + is_type_attribute from os import listdir from os.path import exists, isdir, join, split from referencing import Reference @@ -824,6 +825,12 @@ structure.append("%s /* %s */" % (constant_value, attrname)) continue + # Special class relationship attributes. + + elif is_type_attribute(attrname): + structure.append("{0, &%s}" % encode_path(decode_type_attribute(attrname))) + continue + structure.append(self.encode_member(origin, attrname, attr, kind)) def encode_member(self, path, name, ref, structure_type):