diff --git a/bind/gencpy.go b/bind/gencpy.go index f3366b2..4d567ba 100644 --- a/bind/gencpy.go +++ b/bind/gencpy.go @@ -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, diff --git a/bind/gengo.go b/bind/gengo.go index cbb22c9..72c5e4b 100644 --- a/bind/gengo.go +++ b/bind/gengo.go @@ -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",