Commit 02fd83bc authored by Damien George's avatar Damien George
Browse files

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

Fixes issue #2023.
parent b539a614
......@@ -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)
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):
# set core variables
self.bytecode = bytecode
......@@ -240,6 +243,13 @@ class RawCode:
def freeze(self, parent_name):
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
# emit children first
for rc in self.raw_codes:
rc.freeze(self.escaped_name + '_')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment