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()
|
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("static PyObject*\n")
|
||||||
g.decl.Printf(
|
g.decl.Printf(
|
||||||
"_gopy_%[1]s_getter_%[2]d(_gopy_%[1]s *self, void *closure); /* %[3]s */\n",
|
"_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")
|
g.impl.Printf("PyObject *o = NULL;\n")
|
||||||
ftname := cgoTypeName(ft)
|
ftname := cgoTypeName(ft)
|
||||||
if needWrapType(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(
|
g.impl.Printf(
|
||||||
"%[1]s cgopy_ret = GoPy_%[2]s_getter_%[3]d(self->cgopy);\n",
|
"%[1]s cgopy_ret = GoPy_%[2]s_getter_%[3]d(self->cgopy);\n",
|
||||||
ftname,
|
ftname,
|
||||||
|
|
|
@ -216,8 +216,7 @@ func (g *goGen) genStruct(s Struct) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if needWrapType(ft) {
|
if needWrapType(ft) {
|
||||||
dt := getTypedesc(ft)
|
g.Printf("return %s(unsafe.Pointer(&ret.%s))\n", ftname, f.Name())
|
||||||
g.Printf("%s(unsafe.Pointer(&ret.%s))\n", dt.cgotype, f.Name())
|
|
||||||
} else {
|
} else {
|
||||||
g.Printf("return ret.%s\n", f.Name())
|
g.Printf("return ret.%s\n", f.Name())
|
||||||
}
|
}
|
||||||
|
@ -232,8 +231,10 @@ func (g *goGen) genStruct(s Struct) {
|
||||||
g.Indent()
|
g.Indent()
|
||||||
fset := "v"
|
fset := "v"
|
||||||
if needWrapType(ft) {
|
if needWrapType(ft) {
|
||||||
dt := getTypedesc(ft)
|
fset = fmt.Sprintf("*(*%s.%s)(unsafe.Pointer(v))",
|
||||||
fset = fmt.Sprintf("%s(unsafe.Pointer(&v))", dt.cgotype)
|
f.Pkg().Name(),
|
||||||
|
types.TypeString(f.Type(), types.RelativeTo(f.Pkg())),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
g.Printf(
|
g.Printf(
|
||||||
"(*%[1]s)(unsafe.Pointer(self)).%[2]s = %[3]s\n",
|
"(*%[1]s)(unsafe.Pointer(self)).%[2]s = %[3]s\n",
|
||||||
|
|
Loading…
Reference in New Issue