Merge pull request #288 from kjahed/kjahed/support_error_slice

support error slices
This commit is contained in:
Randall O'Reilly 2022-07-11 12:09:49 -07:00 committed by GitHub
commit cb06da25ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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&",
},
}