Commit eaf13bcb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Implement traceback.format_stack + print_stack

Now that we have frame support including f_back, we can
use the cpython implementations of these functions.

We don't have the same traceback objects (don't have
tb_frame or tb_next), so there are still some modifications
to the traceback library.
parent 8802a933
......@@ -292,29 +292,29 @@ def print_stack(f=None, limit=None, file=None):
stack frame at which to start. The optional 'limit' and 'file'
arguments have the same meaning as for print_exception().
"""
if f is not None or limit is not None:
raise NotImplementedError("print_stack() does not currently support the 'f' or 'limit' arguments in Pyston")
try:
raise ZeroDivisionError
except ZeroDivisionError:
# Make use of Pyston's incorrect behavior, that we generate exception tracebacks all the
# way to the top stack frame:
l = format_exception(*sys.exc_info())[1:-2]
for s in l:
_print(file, s, '')
if f is None:
# Pyston change:
"""
try:
raise ZeroDivisionError
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back
"""
f = sys._getframe(1)
print_list(extract_stack(f, limit), file)
def format_stack(f=None, limit=None):
"""Shorthand for 'format_list(extract_stack(f, limit))'."""
raise NotImplementedError("This function is currently not implemented in Pyston")
if f is None:
# Pyston change:
"""
try:
raise ZeroDivisionError
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back
"""
f = sys._getframe(1)
return format_list(extract_stack(f, limit))
def extract_stack(f=None, limit = None):
......@@ -327,12 +327,15 @@ def extract_stack(f=None, limit = None):
from oldest to newest stack frame.
"""
raise NotImplementedError("This function is currently not implemented in Pyston")
if f is None:
# Pyston change:
"""
try:
raise ZeroDivisionError
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back
"""
f = sys._getframe(1)
if limit is None:
if hasattr(sys, 'tracebacklimit'):
limit = sys.tracebacklimit
......
# A test of both the tracebacks we generate and the tracebacks module
# A test of both the tracebacks we generate and the traceback module
#
# (We keep fixing tracebacks in one case to break them in another, so it's time for a test.)
#
......@@ -103,6 +103,15 @@ except:
except:
traceback.print_exc(file=sys.stdout)
def f(n):
if n:
return f(n - 1)
traceback.print_stack(file=sys.stdout)
print
return traceback.format_stack()
print
print ''.join(f(5))
# Output some extra stuff at the end so that it doesn't look like the script crashed with an exception:
print
......
Markdown is supported
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