mirror of https://github.com/go-python/gopy.git
Merge pull request #288 from kjahed/kjahed/support_error_slice
support error slices
This commit is contained in:
commit
cb06da25ff
|
@ -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
|
||||
`
|
||||
|
||||
|
|
|
@ -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&",
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue