MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / PP_Run_Method

Function PP_Run_Method

src/Base/PyTools.c:31–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 *****************************************************************************/
30
31int
32PP_Run_Method(PyObject *pobject, const char *method,
33 const char *resfmt, void *cresult, /* convert to c/c++ */
34 const char *argfmt, ... /* arg,... */ ) /* convert to python */
35{
36 PyObject *pmeth = NULL, *pargs = NULL, *presult = NULL;
37 va_list argslist; /* "pobject.method(args)" */
38 va_start(argslist, argfmt);
39
40 Py_Initialize(); /* init if first time */
41 pmeth = PyObject_GetAttrString(pobject, method);
42 if (pmeth == NULL) { /* get callable object */
43 va_end(argslist);
44 return -1; /* bound method? has self */
45 }
46
47 pargs = Py_VaBuildValue(argfmt, argslist); /* args: c->python */
48 va_end(argslist);
49
50 if (pargs == NULL) {
51 Py_DECREF(pmeth);
52 return -1;
53 }
54 if (PP_DEBUG) /* debug it too? */
55 presult = PP_Debug_Function(pmeth, pargs);
56 else
57 presult = PyObject_CallObject(pmeth, pargs); /* run interpreter */
58
59 Py_DECREF(pmeth);
60 Py_DECREF(pargs);
61
62 return PP_Convert_Result(presult, resfmt, cresult); /* to C format */
63}
64
65
66int

Callers 3

runMethodVoidMethod · 0.85
runMethodObjectMethod · 0.85
PP_Fetch_Error_TextFunction · 0.85

Calls 2

PP_Debug_FunctionFunction · 0.85
PP_Convert_ResultFunction · 0.85

Tested by

no test coverage detected