Content-Length: 326098 | pFad | http://github.com/4cecoder/go-python/commit/2d6a486df6adfd3b2efb3437758f47f4797a8a9f

73 exceptions: fix nil pointer exception in PyErr_Fetch · 4cecoder/go-python@2d6a486 · GitHub
Skip to content

Commit 2d6a486

Browse files
committed
exceptions: fix nil pointer exception in PyErr_Fetch
Fixes sbinet#37
1 parent c1edbfa commit 2d6a486

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

exceptions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func PyErr_Clear() {
6161
//
6262
// 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.
6363
func PyErr_Fetch() (exc, val, tb *PyObject) {
64+
exc = &PyObject{}
65+
val = &PyObject{}
66+
tb = &PyObject{}
67+
6468
C.PyErr_Fetch(&exc.ptr, &val.ptr, &tb.ptr)
6569
return
6670
}

python_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ cPickle.loads("S'foo'\np1\n.") = "foo"
108108
})
109109
}
110110

111-
// EOF
111+
func TestErrFetch(t *testing.T) {
112+
t.Parallel()
113+
testPkg(t, pkg{
114+
path: "tests/errfetch",
115+
want: []byte("exc=&{<nil>}\nval=&{<nil>}\ntb=&{<nil>}\n"),
116+
})
117+
}

tests/errfetch/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sbinet/go-python"
7+
)
8+
9+
func init() {
10+
err := python.Initialize()
11+
if err != nil {
12+
panic(err.Error())
13+
}
14+
}
15+
16+
func main() {
17+
exc, val, tb := python.PyErr_Fetch()
18+
fmt.Printf("exc=%v\nval=%v\ntb=%v\n", exc, val, tb)
19+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/4cecoder/go-python/commit/2d6a486df6adfd3b2efb3437758f47f4797a8a9f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy