Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
exceptions: fix nil pointer exception in PyErr_Fetch
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
sbinet committed Mar 21, 2016
1 parent c1edbfa commit 2d6a486
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exceptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func PyErr_Clear() {
//
// Note This function is normally only used by code that needs to handle exceptions or by code that needs to save and restore the error indicator temporarily.
func PyErr_Fetch() (exc, val, tb *PyObject) {
exc = &PyObject{}
val = &PyObject{}
tb = &PyObject{}

C.PyErr_Fetch(&exc.ptr, &val.ptr, &tb.ptr)
return
}
Expand Down
8 changes: 7 additions & 1 deletion python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ cPickle.loads("S'foo'\np1\n.") = "foo"
})
}

// EOF
func TestErrFetch(t *testing.T) {
t.Parallel()
testPkg(t, pkg{
path: "tests/errfetch",
want: []byte("exc=&{<nil>}\nval=&{<nil>}\ntb=&{<nil>}\n"),
})
}
19 changes: 19 additions & 0 deletions tests/errfetch/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"fmt"

"github.com/sbinet/go-python"
)

func init() {
err := python.Initialize()
if err != nil {
panic(err.Error())
}
}

func main() {
exc, val, tb := python.PyErr_Fetch()
fmt.Printf("exc=%v\nval=%v\ntb=%v\n", exc, val, tb)
}

0 comments on commit 2d6a486

Please sign in to comment.