Commit cf431b57 authored by Dylan Trotter's avatar Dylan Trotter

Remove exception restore logic from Block objects.

parent b2e82999
......@@ -37,18 +37,11 @@ func (b *Block) Exec(f *Frame, globals *Dict) (*Object, *BaseException) {
}
func (b *Block) execInternal(f *Frame, sendValue *Object) (*Object, *BaseException) {
oldExc, oldTraceback := f.ExcInfo()
// Re-enter function body while we have checkpoint handlers left.
for {
ret, raised := b.fn(f, sendValue)
if raised == nil {
// Restore exc_info to what it was when we left
// the previous frame.
f.RestoreExc(oldExc, oldTraceback)
return ret, nil
}
if len(f.checkpoints) == 0 {
return nil, raised
if raised == nil || len(f.checkpoints) == 0 {
return ret, raised
}
f.state = f.PopCheckpoint()
}
......
......@@ -79,36 +79,3 @@ func TestBlockExecRaises(t *testing.T) {
t.Errorf("exception traceback was %+v, want %+v", tb, wantTraceback)
}
}
func TestBlockExecRestoreExc(t *testing.T) {
e := mustCreateException(RuntimeErrorType, "uh oh")
ranB1, ranB2 := false, false
globals := NewDict()
b1 := NewBlock("<b1>", "foo.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
if got, _ := f.ExcInfo(); got != e {
t.Errorf("ExcInfo() = %v, want %v", got, e)
}
f.RestoreExc(nil, nil)
ranB1 = true
return None, nil
})
b2 := NewBlock("<b2>", "foo.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
f.RestoreExc(e, newTraceback(f, nil))
b1.Exec(f, globals)
// The exception was cleared by b1 but when returning to b2, it
// should have been restored.
if got, _ := f.ExcInfo(); got != e {
t.Errorf("ExcInfo() = %v, want <nil>", got)
}
f.RestoreExc(nil, nil)
ranB2 = true
return None, nil
})
b2.Exec(newFrame(nil), globals)
if !ranB1 {
t.Error("b1 did not run")
}
if !ranB2 {
t.Error("b2 did not run")
}
}
......@@ -56,3 +56,36 @@ func TestNewCode(t *testing.T) {
}
}
}
func TestCodeEvalRestoreExc(t *testing.T) {
e := mustCreateException(RuntimeErrorType, "uh oh")
ranC1, ranC2 := false, false
globals := NewDict()
c1 := NewCode("<c1>", "foo.py", nil, 0, func(f *Frame, _ []*Object) (*Object, *BaseException) {
if got, _ := f.ExcInfo(); got != e {
t.Errorf("ExcInfo() = %v, want %v", got, e)
}
f.RestoreExc(nil, nil)
ranC1 = true
return None, nil
})
c2 := NewCode("<c2>", "foo.py", nil, 0, func(f *Frame, _ []*Object) (*Object, *BaseException) {
f.RestoreExc(e, newTraceback(f, nil))
c1.Eval(f, globals, nil, nil)
// The exception was cleared by c1 but when returning to c2, it
// should have been restored.
if got, _ := f.ExcInfo(); got != e {
t.Errorf("ExcInfo() = %v, want <nil>", got)
}
f.RestoreExc(nil, nil)
ranC2 = true
return None, nil
})
c2.Eval(newFrame(nil), globals, nil, nil)
if !ranC1 {
t.Error("c1 did not run")
}
if !ranC2 {
t.Error("c2 did not run")
}
}
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