Skip to content

Commit 2dfc9a3

Browse files
committed
Backport bugfixes from the trunk.
Add __getitem__() to a stack to support visitContinue(). Move mangle() here and define correctly.
1 parent a18d63e commit 2dfc9a3

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Tools/compiler/compiler/misc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ def push(self, elt):
3939
self.stack.append(elt)
4040
def top(self):
4141
return self.stack[-1]
42+
def __getitem__(self, index): # needed by visitContinue()
43+
return self.stack[index]
44+
45+
MANGLE_LEN = 256 # magic constant from compile.c
46+
47+
def mangle(name, klass):
48+
if not name.startswith('__'):
49+
return name
50+
if len(name) + 2 >= MANGLE_LEN:
51+
return name
52+
if name.endswith('__'):
53+
return name
54+
try:
55+
i = 0
56+
while klass[i] == '_':
57+
i = i + 1
58+
except IndexError:
59+
return name
60+
klass = klass[i:]
61+
62+
tlen = len(klass) + len(name)
63+
if tlen > MANGLE_LEN:
64+
klass = klass[:MANGLE_LEN-tlen]
65+
66+
return "_%s%s" % (klass, name)
67+

0 commit comments

Comments
 (0)