pypy / pypy / interpreter / pytraceback.py

Armin Rigo bf255bb 
Bruno Gola 528e8b6 
Armin Rigo bf255bb 




Armin Rigo 776190a 
Armin Rigo bf255bb 





Armin Rigo 776190a 
Armin Rigo bf255bb 




Armin Rigo 776190a 


Amaury Forgeot d… fe81f52 
Armin Rigo 776190a 

Eric van Riet Pa… 840a860 






Christian Tismer b71f22a 

Eric van Riet Pa… 840a860 



Christian Tismer b71f22a 

Eric van Riet Pa… 840a860 
Christian Tismer b71f22a 


Armin Rigo 776190a 
Christian Tismer b71f22a 


Armin Rigo bf255bb 

Samuele Pedroni feb61bd 
Anders Chrigströ… 7646637 
Armin Rigo 98a69d0 
Armin Rigo 776190a 
Armin Rigo 98a69d0 
Armin Rigo bf255bb 










Bruno Gola 528e8b6 


Carl Friedrich B… bbcc7cf 



Bruno Gola 528e8b6 
from pypy.interpreter import baseobjspace
from pypy.interpreter.error import OperationError


class PyTraceback(baseobjspace.Wrappable):
    """Traceback object

    Public app-level fields:
     * 'tb_frame'
     * 'tb_lasti'
     * 'tb_lineno'
     * 'tb_next'
    """

    def __init__(self, space, frame, lasti, next):
        self.space = space
        self.frame = frame
        self.lasti = lasti
        self.next = next

    def get_lineno(self):
        return offset2lineno(self.frame.pycode, self.lasti)

    def descr_tb_lineno(self, space):
        return space.wrap(self.get_lineno())

    def descr__reduce__(self, space):
        from pypy.interpreter.mixedmodule import MixedModule
        w_mod    = space.getbuiltinmodule('_pickle_support')
        mod      = space.interp_w(MixedModule, w_mod)
        new_inst = mod.get('traceback_new')
        w        = space.wrap

        tup_base = []
        tup_state = [
            w(self.frame),
            w(self.lasti),
            w(self.next),
            ]
        nt = space.newtuple
        return nt([new_inst, nt(tup_base), nt(tup_state)])

    def descr__setstate__(self, space, w_args):
        from pypy.interpreter.pyframe import PyFrame
        args_w = space.unpackiterable(w_args)
        w_frame, w_lasti, w_next = args_w
        self.frame = space.interp_w(PyFrame, w_frame)
        self.lasti = space.int_w(w_lasti)
        self.next = space.interp_w(PyTraceback, w_next, can_be_None=True)

def record_application_traceback(space, operror, frame, last_instruction):
    if frame.pycode.hidden_applevel:
        return
    tb = operror.get_traceback()
    tb = PyTraceback(space, frame, last_instruction, tb)
    operror.set_traceback(tb)

def offset2lineno(c, stopat):
    tab = c.co_lnotab
    line = c.co_firstlineno
    addr = 0
    for i in range(0, len(tab), 2):
        addr = addr + ord(tab[i])
        if addr > stopat:
            break
        line = line + ord(tab[i+1])
    return line

def check_traceback(space, w_tb, msg):
    from pypy.interpreter.typedef import PyTraceback
    tb = space.interpclass_w(w_tb)
    if tb is None or not space.is_true(space.isinstance(tb, 
            space.gettypeobject(PyTraceback.typedef))):
        raise OperationError(space.w_TypeError, space.wrap(msg))
    return tb
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.