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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy