Skip to content

Commit cb06da2

Browse files
authored
Merge pull request #288 from kjahed/kjahed/support_error_slice
support error slices
2 parents 7175418 + 8578af2 commit cb06da2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

bind/gen.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ func complex128PyToGo(o *C.PyObject) complex128 {
164164
return complex(float64(v.real), float64(v.imag))
165165
}
166166
167+
// errorGoToPy converts a Go error to python-compatible C.CString
168+
func errorGoToPy(e error) *C.char {
169+
if e != nil {
170+
return C.CString(e.Error())
171+
}
172+
return C.CString("")
173+
}
174+
167175
%[9]s
168176
`
169177

bind/stdtypes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func makeGoPackage() {
2424
func addStdSliceMaps() {
2525
makeGoPackage()
2626
gopk := goPackage.pkg
27-
sltyps := []string{"int", "int64", "int32", "int16", "int8", "uint", "uint64", "uint32", "uint16", "uint8", "bool", "byte", "rune", "float64", "float32", "string"}
27+
sltyps := []string{"int", "int64", "int32", "int16", "int8", "uint", "uint64", "uint32", "uint16", "uint8", "bool", "byte", "rune", "float64", "float32", "string", "error"}
2828
for _, tn := range sltyps {
2929
universe.addSliceType(gopk, nil, types.NewSlice(universe.sym(tn).gotyp), skType, "Slice_"+tn, "[]"+tn)
3030
}
@@ -342,16 +342,16 @@ func stdBasicTypes() map[string]*symbol {
342342
gopkg: look("error").Pkg(),
343343
goobj: look("error"),
344344
gotyp: look("error").Type(),
345-
kind: skType | skInterface,
345+
kind: skType | skBasic,
346346
goname: "error",
347347
id: "error",
348348
cpyname: "char*",
349349
cgoname: "*C.char",
350350
pysig: "str",
351-
go2py: "C.CString",
351+
go2py: "errorGoToPy",
352352
py2go: "errors.New(C.GoString",
353353
py2goParenEx: ")",
354-
zval: `""`,
354+
zval: `nil`,
355355
pyfmt: "O&",
356356
},
357357
}

0 commit comments

Comments
 (0)