| 29 | *****************************************************************************/ |
| 30 | |
| 31 | int |
| 32 | PP_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 | |
| 66 | int |
no test coverage detected