[IronPython] Traceback Stack Bugs

Michael Foord fuzzyman at voidspace.org.uk
Sat Jan 6 01:58:17 CET 2007


Hello team,

Whilst optimising Resolver we discovered a bug in the handling of 
traceback objects with IronPython.

The following code behaves differently under IronPython and CPython :

import sys
def extract_tb():
     tb = sys.exc_info()[2]
     stackInfo = []
     while tb:
         f = tb.tb_frame
         lineno = tb.tb_lineno
         co = f.f_code
         filename = co.co_filename
         stackInfo.append((filename, lineno))
         tb = tb.tb_next
     return stackInfo

try:
     raise ValueError('stuff')
except:
     print extract_tb()

try:
     raise ValueError('stuff')
except:
     print extract_tb()


Under IronPython :

[]
[]


Under CPython :

[('C:\\Python Projects\\modules in 
progress\\ironpython\\tracebackBug.py', 15)]
[('C:\\Python Projects\\modules in 
progress\\ironpython\\tracebackBug.py', 20)]

If you exec a compiled code object which raises an exception (instead of 
directly raising the error) the CPython traceback starts with the Python 
code, whereas the IronPython traceback starts with the code object and 
goes no further back. (So a different bug...)

The bug I was actually trying to expose is that in Resolver we were 
finding that the traceback objects were not being cleared out - the 
stack (using the extract_tb function above) was getting longer and 
longer. Adding an explicit sys.clear_exc() solved our problem, but it 
foxed us for a while.

Unfortunately I can't reproduce this bug easily - but you can see that 
something screwy is going on.

Michael
http://www.voidspace.org.uk/ironpython/index.shtml



More information about the Ironpython-users mailing list