def bytecode_trace(self, frame):
     "Trace function called before each bytecode."
     # First, call yield_thread() before each Nth bytecode,
     #     as selected by sys.setcheckinterval()
     ticker = self.ticker
     if ticker <= 0:
         Action.perform_actions(self.space.pending_actions)
         Action.perform_actions(self.pending_actions)
         ticker = self.space.sys.checkinterval
     self.ticker = ticker - 1
     if frame.w_f_trace is None or self.is_tracing:
         return
     self._do_bytecode_trace(frame)
Exemple #2
0
    def _do_bytecode_trace(self, frame):
        if self.ticker < 0:
            Action.perform_actions(self.space.pending_actions)
            Action.perform_actions(self.pending_actions)
            self.ticker = self.space.sys.checkinterval
        if frame.w_f_trace is None or self.is_tracing:
            return
        code = frame.pycode
        if frame.instr_lb <= frame.last_instr < frame.instr_ub:
            if frame.last_instr <= frame.instr_prev:
                # We jumped backwards in the same line.
                self._trace(frame, 'line', self.space.w_None)
        else:
            size = len(code.co_lnotab) / 2
            addr = 0
            line = code.co_firstlineno
            p = 0
            lineno = code.co_lnotab
            while size > 0:
                c = ord(lineno[p])
                if (addr + c) > frame.last_instr:
                    break
                addr += c
                if c:
                    frame.instr_lb = addr

                line += ord(lineno[p + 1])
                p += 2
                size -= 1

            if size > 0:
                while True:
                    size -= 1
                    if size < 0:
                        break
                    addr += ord(lineno[p])
                    if ord(lineno[p + 1]):
                        break
                    p += 2
                frame.instr_ub = addr
            else:
                frame.instr_ub = sys.maxint

            if frame.instr_lb == frame.last_instr: # At start of line!
                frame.f_lineno = line
                self._trace(frame, 'line', self.space.w_None)

        frame.instr_prev = frame.last_instr
Exemple #3
0
def wrap_oserror_as_ioerror(space, e):
    assert isinstance(e, OSError)
    errno = e.errno
    if errno == EINTR:
        # A signal was sent to the process and interupted
        # a systemcall. We want to trigger running of
        # any installed interrupt handlers.
        # XXX: is there a better way?
        ec = space.getexecutioncontext()
        Action.perform_actions(space.pending_actions)
        Action.perform_actions(ec.pending_actions)
    try:
        msg = os.strerror(errno)
    except ValueError:
        msg = 'error %d' % errno
    w_error = space.call_function(space.w_IOError,
                                  space.wrap(errno),
                                  space.wrap(msg))
    return OperationError(space.w_IOError, w_error)