Commit b2e82999 authored by Dylan Trotter's avatar Dylan Trotter

Propagate tracebacks from code objects that raise. Expose some fields to Python.

parent 132d03e9
......@@ -48,18 +48,6 @@ func (b *Block) execInternal(f *Frame, sendValue *Object) (*Object, *BaseExcepti
return ret, nil
}
if len(f.checkpoints) == 0 {
if f.back != nil {
e, tb := f.ExcInfo()
if e != raised {
// This is likely due to a programming
// error. Prefer raised and start
// propagating from here.
tb = newTraceback(f, nil)
} else {
tb = newTraceback(f.back, tb)
}
f.RestoreExc(raised, tb)
}
return nil, raised
}
f.state = f.PopCheckpoint()
......
......@@ -17,8 +17,8 @@ const (
type Code struct {
Object
name string
filename string
name string `attr:"co_name"`
filename string `attr:"co_filename"`
// argc is the number of positional arguments.
argc int `attr:"co_argcount"`
// minArgc is the number of positional non-keyword arguments (i.e. the
......@@ -112,9 +112,20 @@ func (c *Code) Eval(f *Frame, globals *Dict, args Args, kwargs KWArgs) (*Object,
bodyArgs[i] = arg.Def
}
}
oldExc, oldTraceback := f.ExcInfo()
next := newFrame(f)
next.code = c
next.globals = globals
ret, raised := c.fn(next, bodyArgs)
f.FreeArgs(bodyArgs)
if raised == nil {
// Restore exc_info to what it was when we left the previous
// frame.
f.RestoreExc(oldExc, oldTraceback)
} else {
_, tb := f.ExcInfo()
tb = newTraceback(f, tb)
f.RestoreExc(raised, tb)
}
return ret, raised
}
......@@ -38,6 +38,7 @@ type Frame struct {
state RunState
globals *Dict `attr:"f_globals"`
lineno int `attr:"f_lineno"`
code *Code `attr:"f_code"`
}
// newFrame creates a new Frame whose parent frame is back.
......
......@@ -21,9 +21,9 @@ import (
// Traceback represents Python 'traceback' objects.
type Traceback struct {
Object
frame *Frame `attr:"tb_frame"`
next *Traceback
lineno int `attr:"tb_lineno"`
frame *Frame `attr:"tb_frame"`
next *Traceback `attr:"tb_next"`
lineno int `attr:"tb_lineno"`
}
func newTraceback(f *Frame, next *Traceback) *Traceback {
......
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