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 ...@@ -48,18 +48,6 @@ func (b *Block) execInternal(f *Frame, sendValue *Object) (*Object, *BaseExcepti
return ret, nil return ret, nil
} }
if len(f.checkpoints) == 0 { 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 return nil, raised
} }
f.state = f.PopCheckpoint() f.state = f.PopCheckpoint()
......
...@@ -17,8 +17,8 @@ const ( ...@@ -17,8 +17,8 @@ const (
type Code struct { type Code struct {
Object Object
name string name string `attr:"co_name"`
filename string filename string `attr:"co_filename"`
// argc is the number of positional arguments. // argc is the number of positional arguments.
argc int `attr:"co_argcount"` argc int `attr:"co_argcount"`
// minArgc is the number of positional non-keyword arguments (i.e. the // 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, ...@@ -112,9 +112,20 @@ func (c *Code) Eval(f *Frame, globals *Dict, args Args, kwargs KWArgs) (*Object,
bodyArgs[i] = arg.Def bodyArgs[i] = arg.Def
} }
} }
oldExc, oldTraceback := f.ExcInfo()
next := newFrame(f) next := newFrame(f)
next.code = c
next.globals = globals next.globals = globals
ret, raised := c.fn(next, bodyArgs) ret, raised := c.fn(next, bodyArgs)
f.FreeArgs(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 return ret, raised
} }
...@@ -38,6 +38,7 @@ type Frame struct { ...@@ -38,6 +38,7 @@ type Frame struct {
state RunState state RunState
globals *Dict `attr:"f_globals"` globals *Dict `attr:"f_globals"`
lineno int `attr:"f_lineno"` lineno int `attr:"f_lineno"`
code *Code `attr:"f_code"`
} }
// newFrame creates a new Frame whose parent frame is back. // newFrame creates a new Frame whose parent frame is back.
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
type Traceback struct { type Traceback struct {
Object Object
frame *Frame `attr:"tb_frame"` frame *Frame `attr:"tb_frame"`
next *Traceback next *Traceback `attr:"tb_next"`
lineno int `attr:"tb_lineno"` lineno int `attr:"tb_lineno"`
} }
......
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