| 104 | *****************************************************************************/ |
| 105 | |
| 106 | int |
| 107 | PP_Run_Function(const char *modname, const char *funcname, /* load from module */ |
| 108 | const char *resfmt, void *cresult, /* convert to c/c++ */ |
| 109 | const char *argfmt, ... /* arg, arg... */ ) /* convert to python */ |
| 110 | { |
| 111 | /* call a function or class in a module */ |
| 112 | PyObject *func = NULL, *args = NULL, *presult = NULL; |
| 113 | va_list argslist; |
| 114 | va_start(argslist, argfmt); /* "modname.funcname(args)" */ |
| 115 | |
| 116 | func = PP_Load_Attribute(modname, funcname); /* may reload; incref'd */ |
| 117 | if (func == NULL) { /* func or class or C type */ |
| 118 | va_end(argslist); |
| 119 | return -1; |
| 120 | } |
| 121 | args = Py_VaBuildValue(argfmt, argslist); /* convert args to python */ |
| 122 | va_end(argslist); |
| 123 | if (args == NULL) { /* args incref'd */ |
| 124 | Py_DECREF(func); |
| 125 | return -1; |
| 126 | } |
| 127 | if (PP_DEBUG && strcmp(modname, "pdb") != 0) /* debug this call? */ |
| 128 | presult = PP_Debug_Function(func, args); /* run in pdb; incref'd */ |
| 129 | else |
| 130 | presult = PyObject_CallObject(func, args); /* run function; incref'd */ |
| 131 | |
| 132 | Py_DECREF(func); |
| 133 | Py_DECREF(args); /* result may be None */ |
| 134 | return PP_Convert_Result(presult, resfmt, cresult); /* convert result to C*/ |
| 135 | } |
| 136 | |
| 137 | |
| 138 | PyObject * |
no test coverage detected