@@ -19,10 +19,11 @@ func (g *pyGen) genFuncSig(sym *symbol, fsym *Func) bool {
19
19
return false
20
20
}
21
21
22
- gname , _ , err := extractPythonName (fsym .GoName (), fsym .Doc ())
22
+ gname , gdoc , err := extractPythonName (fsym .GoName (), fsym .Doc ())
23
23
if err != nil {
24
24
return false
25
25
}
26
+ ifchandle , gdoc := isIfaceHandle (gdoc )
26
27
27
28
sig := fsym .sig
28
29
args := sig .Params ()
@@ -55,11 +56,16 @@ func (g *pyGen) genFuncSig(sym *symbol, fsym *Func) bool {
55
56
return false
56
57
}
57
58
anm := pySafeArg (arg .Name (), i )
58
- goArgs = append ( goArgs , fmt . Sprintf ( "%s %s" , anm , sarg . cgoname ))
59
- if sarg . cpyname == "PyObject*" {
60
- pyArgs = append (pyArgs , fmt .Sprintf ("param('%s', '%s', transfer_ownership=False )" , sarg . cpyname , anm ))
59
+ if ifchandle && arg . sym . goname == "interface{}" {
60
+ goArgs = append ( goArgs , fmt . Sprintf ( "%s %s" , anm , CGoHandle ))
61
+ pyArgs = append (pyArgs , fmt .Sprintf ("param('%s', '%s')" , PyHandle , anm ))
61
62
} else {
62
- pyArgs = append (pyArgs , fmt .Sprintf ("param('%s', '%s')" , sarg .cpyname , anm ))
63
+ goArgs = append (goArgs , fmt .Sprintf ("%s %s" , anm , sarg .cgoname ))
64
+ if sarg .cpyname == "PyObject*" {
65
+ pyArgs = append (pyArgs , fmt .Sprintf ("param('%s', '%s', transfer_ownership=False)" , sarg .cpyname , anm ))
66
+ } else {
67
+ pyArgs = append (pyArgs , fmt .Sprintf ("param('%s', '%s')" , sarg .cpyname , anm ))
68
+ }
63
69
}
64
70
wpArgs = append (wpArgs , anm )
65
71
}
@@ -138,6 +144,15 @@ func (g *pyGen) genMethod(s *symbol, o *Func) {
138
144
}
139
145
}
140
146
147
+ func isIfaceHandle (gdoc string ) (bool , string ) {
148
+ const PythonIface = "\n gopy:interface=handle"
149
+ if idx := strings .Index (gdoc , PythonIface ); idx > 0 {
150
+ gdoc = gdoc [:idx ] + gdoc [idx + len (PythonIface )+ 1 :]
151
+ return true , gdoc
152
+ }
153
+ return false , gdoc
154
+ }
155
+
141
156
func (g * pyGen ) genFuncBody (sym * symbol , fsym * Func ) {
142
157
isMethod := (sym != nil )
143
158
isIface := false
@@ -153,6 +168,7 @@ func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
153
168
pkgname := g .outname
154
169
155
170
_ , gdoc , _ := extractPythonName (fsym .GoName (), fsym .Doc ())
171
+ ifchandle , gdoc := isIfaceHandle (gdoc )
156
172
157
173
sig := fsym .Signature ()
158
174
res := sig .Results ()
@@ -233,7 +249,9 @@ if err != nil {
233
249
for i , arg := range args {
234
250
na := ""
235
251
anm := pySafeArg (arg .Name (), i )
236
- if arg .sym .isSignature () {
252
+ if ifchandle && arg .sym .goname == "interface{}" {
253
+ na = fmt .Sprintf (`gopyh.VarFmHandle((gopyh.CGoHandle)(%s), "interface{}")` , anm )
254
+ } else if arg .sym .isSignature () {
237
255
na = fmt .Sprintf ("%s" , arg .sym .py2go )
238
256
} else {
239
257
if arg .sym .py2go != "" {
@@ -243,7 +261,13 @@ if err != nil {
243
261
}
244
262
}
245
263
callArgs = append (callArgs , na )
246
- if arg .sym .hasHandle () {
264
+ if arg .sym .goname == "interface{}" {
265
+ if ifchandle {
266
+ wrapArgs = append (wrapArgs , fmt .Sprintf ("%s.handle" , anm ))
267
+ } else {
268
+ wrapArgs = append (wrapArgs , anm )
269
+ }
270
+ } else if arg .sym .hasHandle () {
247
271
wrapArgs = append (wrapArgs , fmt .Sprintf ("%s.handle" , anm ))
248
272
} else {
249
273
wrapArgs = append (wrapArgs , anm )
0 commit comments