tools/mpy-tool: Make sure that all C-level variables are unique.

Fixes issue #2023.
This commit is contained in:
Damien George 2016-05-03 12:24:39 +01:00
parent b539a61490
commit 02fd83bcbc
1 changed files with 10 additions and 0 deletions

View File

@ -215,6 +215,9 @@ def extract_prelude(bytecode):
return ip, ip2, (n_state, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_pos_args, code_info_size) return ip, ip2, (n_state, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_pos_args, code_info_size)
class RawCode: class RawCode:
# a set of all escaped names, to make sure they are unique
escaped_names = set()
def __init__(self, bytecode, qstrs, objs, raw_codes): def __init__(self, bytecode, qstrs, objs, raw_codes):
# set core variables # set core variables
self.bytecode = bytecode self.bytecode = bytecode
@ -240,6 +243,13 @@ class RawCode:
def freeze(self, parent_name): def freeze(self, parent_name):
self.escaped_name = parent_name + self.simple_name.qstr_esc self.escaped_name = parent_name + self.simple_name.qstr_esc
# make sure the escaped name is unique
i = 2
while self.escaped_name in RawCode.escaped_names:
self.escaped_name = parent_name + self.simple_name.qstr_esc + str(i)
i += 1
RawCode.escaped_names.add(self.escaped_name)
# emit children first # emit children first
for rc in self.raw_codes: for rc in self.raw_codes:
rc.freeze(self.escaped_name + '_') rc.freeze(self.escaped_name + '_')