diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 14cf22d7b8dc23f8ab5045e4e23d1f208acbccdd..1f51f1f35a0d4e30ff179e9a6d3ecf649e6fe60b 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -847,7 +847,7 @@ class GlobalState(object): # In time, hopefully the literals etc. will be # supplied directly instead. # - # const_cnames_used set global index of unique constant identifiers + # const_cnames_used dict global counter for unique constant identifiers # # parts {string:CCodeWriter} @@ -903,7 +903,7 @@ class GlobalState(object): self.module_node = module_node # because some utility code generation needs it # (generating backwards-compatible Get/ReleaseBuffer - self.const_cnames_used = set() + self.const_cnames_used = {} self.string_const_index = {} self.pyunicode_ptr_const_index = {} self.int_const_index = {} @@ -1108,12 +1108,11 @@ class GlobalState(object): def new_const_cname(self, prefix='', value=''): value = replace_identifier('_', value)[:32].strip('_') used = self.const_cnames_used - counter = 1 name_suffix = value while name_suffix in used: - counter += 1 + counter = used[value] = used[value] + 1 name_suffix = '%s_%d' % (value, counter) - used.add(name_suffix) + used[name_suffix] = 1 return "%s%s%s" % (Naming.const_prefix, prefix, name_suffix) def add_cached_builtin_decl(self, entry): diff --git a/tests/run/strliterals.pyx b/tests/run/strliterals.pyx index cbf760ba1a1b98ed53390afb967c589fe250fc58..517a45a48af3d18917286db720b1a9bfeb84ea91 100644 --- a/tests/run/strliterals.pyx +++ b/tests/run/strliterals.pyx @@ -149,7 +149,7 @@ __doc__ = ur""" True >>> same_cname - [b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3'] + [b'abc\xf0_2', b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3'] >>> newlines 'Aaa\n' @@ -194,7 +194,7 @@ uresc = ur'\12\'\"\\' bytes_uescape = b'\u1234\U12345678\u\u1\u12\uX' str_uescape = '\u0063\U00012345\N{SNOWMAN}\x42' -same_cname = [b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3'] +same_cname = [b'abc\xf0_2', b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3'] newlines = "Aaa\n"