mirror of https://github.com/go-python/gopy.git
bind: better handling of wrapping for nested structs
This commit is contained in:
parent
405ce0ee56
commit
0feb50a4bc
|
@ -514,6 +514,15 @@ func (g *cpyGen) genStructMemberGetter(cpy Struct, i int, f types.Object) {
|
|||
)
|
||||
|
||||
ft := f.Type()
|
||||
if needWrapType(ft) {
|
||||
g.decl.Printf("/* wrapper for field %s.%s.%s */\n",
|
||||
pkg.Name(),
|
||||
cpy.GoName(),
|
||||
f.Name(),
|
||||
)
|
||||
g.decl.Printf("typedef void* GoPy_%[1]s_field_%d;\n", cpy.ID(), i+1)
|
||||
}
|
||||
|
||||
g.decl.Printf("static PyObject*\n")
|
||||
g.decl.Printf(
|
||||
"_gopy_%[1]s_getter_%[2]d(_gopy_%[1]s *self, void *closure); /* %[3]s */\n",
|
||||
|
@ -558,7 +567,7 @@ func (g *cpyGen) genStructMemberGetter(cpy Struct, i int, f types.Object) {
|
|||
g.impl.Printf("PyObject *o = NULL;\n")
|
||||
ftname := cgoTypeName(ft)
|
||||
if needWrapType(ft) {
|
||||
ftname = fmt.Sprintf("GoPy_%[1]s_field_%d", cpy.GoName(), i+1)
|
||||
ftname = fmt.Sprintf("GoPy_%[1]s_field_%d", cpy.ID(), i+1)
|
||||
g.impl.Printf(
|
||||
"%[1]s cgopy_ret = GoPy_%[2]s_getter_%[3]d(self->cgopy);\n",
|
||||
ftname,
|
||||
|
|
|
@ -216,8 +216,7 @@ func (g *goGen) genStruct(s Struct) {
|
|||
)
|
||||
|
||||
if needWrapType(ft) {
|
||||
dt := getTypedesc(ft)
|
||||
g.Printf("%s(unsafe.Pointer(&ret.%s))\n", dt.cgotype, f.Name())
|
||||
g.Printf("return %s(unsafe.Pointer(&ret.%s))\n", ftname, f.Name())
|
||||
} else {
|
||||
g.Printf("return ret.%s\n", f.Name())
|
||||
}
|
||||
|
@ -232,8 +231,10 @@ func (g *goGen) genStruct(s Struct) {
|
|||
g.Indent()
|
||||
fset := "v"
|
||||
if needWrapType(ft) {
|
||||
dt := getTypedesc(ft)
|
||||
fset = fmt.Sprintf("%s(unsafe.Pointer(&v))", dt.cgotype)
|
||||
fset = fmt.Sprintf("*(*%s.%s)(unsafe.Pointer(v))",
|
||||
f.Pkg().Name(),
|
||||
types.TypeString(f.Type(), types.RelativeTo(f.Pkg())),
|
||||
)
|
||||
}
|
||||
g.Printf(
|
||||
"(*%[1]s)(unsafe.Pointer(self)).%[2]s = %[3]s\n",
|
||||
|
|
Loading…
Reference in New Issue