support error slices

This commit is contained in:
Karim Jahed 2022-06-29 11:28:29 -04:00
parent 0eb43bb47f
commit 8578af24af
2 changed files with 12 additions and 4 deletions

View File

@ -164,6 +164,14 @@ func complex128PyToGo(o *C.PyObject) complex128 {
return complex(float64(v.real), float64(v.imag))
}
// errorGoToPy converts a Go error to python-compatible C.CString
func errorGoToPy(e error) *C.char {
if e != nil {
return C.CString(e.Error())
}
return C.CString("")
}
%[9]s
`

View File

@ -24,7 +24,7 @@ func makeGoPackage() {
func addStdSliceMaps() {
makeGoPackage()
gopk := goPackage.pkg
sltyps := []string{"int", "int64", "int32", "int16", "int8", "uint", "uint64", "uint32", "uint16", "uint8", "bool", "byte", "rune", "float64", "float32", "string"}
sltyps := []string{"int", "int64", "int32", "int16", "int8", "uint", "uint64", "uint32", "uint16", "uint8", "bool", "byte", "rune", "float64", "float32", "string", "error"}
for _, tn := range sltyps {
universe.addSliceType(gopk, nil, types.NewSlice(universe.sym(tn).gotyp), skType, "Slice_"+tn, "[]"+tn)
}
@ -342,16 +342,16 @@ func stdBasicTypes() map[string]*symbol {
gopkg: look("error").Pkg(),
goobj: look("error"),
gotyp: look("error").Type(),
kind: skType | skInterface,
kind: skType | skBasic,
goname: "error",
id: "error",
cpyname: "char*",
cgoname: "*C.char",
pysig: "str",
go2py: "C.CString",
go2py: "errorGoToPy",
py2go: "errors.New(C.GoString",
py2goParenEx: ")",
zval: `""`,
zval: `nil`,
pyfmt: "O&",
},
}