MCPcopy Create free account
hub / github.com/go-python/gopy / genFuncBody

Method genFuncBody

bind/gen_func.go:219–465  ·  view source on GitHub ↗
(sym *symbol, fsym *Func)

Source from the content-addressed store, hash-verified

217}
218
219func (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")
274if __err != nil {
275`, symNm)
276 g.gofile.Indent()

Callers 2

genFuncMethod · 0.95
genMethodMethod · 0.95

Calls 15

extractPythonNameFunction · 0.85
isIfaceHandleFunction · 0.85
isErrorTypeFunction · 0.85
pySafeArgFunction · 0.85
nonPtrNameFunction · 0.85
isInterfaceMethod · 0.80
SignatureMethod · 0.80
ResultsMethod · 0.80
ParamsMethod · 0.80
PrintfMethod · 0.80
IndentMethod · 0.80
isSignatureMethod · 0.80

Tested by

no test coverage detected