(sym *symbol, fsym *Func)
| 217 | } |
| 218 | |
| 219 | func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) { |
| 220 | isMethod := (sym != nil) |
| 221 | isIface := false |
| 222 | symNm := "" |
| 223 | if isMethod { |
| 224 | symNm = sym.goname |
| 225 | isIface = sym.isInterface() |
| 226 | if !isIface { |
| 227 | symNm = "*" + symNm |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | pkgname := g.cfg.Name |
| 232 | |
| 233 | _, gdoc, _ := extractPythonName(fsym.GoName(), fsym.Doc()) |
| 234 | ifchandle, gdoc := isIfaceHandle(gdoc) |
| 235 | |
| 236 | sig := fsym.Signature() |
| 237 | res := sig.Results() |
| 238 | args := sig.Params() |
| 239 | nres := len(res) |
| 240 | |
| 241 | rvIsErr := false // set to true if the main return is an error |
| 242 | if nres == 1 { |
| 243 | ret := res[0] |
| 244 | if isErrorType(ret.GoType()) { |
| 245 | rvIsErr = true |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | g.pywrap.Printf(":\n") |
| 250 | g.pywrap.Indent() |
| 251 | g.pywrap.Printf(`"""%s"""`, gdoc) |
| 252 | g.pywrap.Printf("\n") |
| 253 | |
| 254 | g.gofile.Printf(" {\n") |
| 255 | g.gofile.Indent() |
| 256 | if fsym.hasfun { |
| 257 | for i, arg := range args { |
| 258 | if arg.sym.isSignature() { |
| 259 | g.gofile.Printf("_fun_arg := %s\n", pySafeArg(arg.Name(), i)) |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | // release GIL |
| 265 | g.gofile.Printf("_saved_thread := C.PyEval_SaveThread()\n") |
| 266 | if !rvIsErr && nres != 2 { |
| 267 | // reacquire GIL after return |
| 268 | g.gofile.Printf("defer C.PyEval_RestoreThread(_saved_thread)\n") |
| 269 | } |
| 270 | |
| 271 | if isMethod { |
| 272 | g.gofile.Printf( |
| 273 | `vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "%s") |
| 274 | if __err != nil { |
| 275 | `, symNm) |
| 276 | g.gofile.Indent() |
no test coverage detected