|
|
@ -2102,39 +2102,33 @@ PyObject* PythonInterface::RunFunction(PyObject* module, const char* name, PyObj |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PyObject* PythonInterface::ParseArgs(const char* args) |
|
|
|
bool PythonInterface::RunFunctionStringArg(const char* module, const char* name, const char* arg) |
|
|
|
{ |
|
|
|
|
|
|
|
PyObject* result = NULL; |
|
|
|
|
|
|
|
PyObject* scope = PyDict_New(); |
|
|
|
|
|
|
|
if (scope)
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//- Py_eval_input makes this function accept only single expresion (not statement)
|
|
|
|
|
|
|
|
//- When using empty scope, functions and classes like 'file' or '__import__' are not visible
|
|
|
|
|
|
|
|
result = PyRun_String(args, Py_eval_input, scope, NULL); |
|
|
|
|
|
|
|
Py_DECREF(scope); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool PythonInterface::RunFunctionSafe(const char* module, const char* function, const char* args)
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
PyObject* moduleObj = ImportModule(module); |
|
|
|
PyObject* moduleObj = ImportModule(module); |
|
|
|
bool result = false; |
|
|
|
bool result = false; |
|
|
|
if (moduleObj)
|
|
|
|
if (moduleObj)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
PyObject* argsObj = ParseArgs(args); |
|
|
|
PyObject* argObj = PyString_FromString(arg); |
|
|
|
|
|
|
|
if (argObj) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PyObject* argsObj = PyTuple_New(1); |
|
|
|
if (argsObj) |
|
|
|
if (argsObj) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PyObject* callResult = RunFunction(moduleObj, function, argsObj); |
|
|
|
// PyTuple_SET_ITEM steals the reference to argObj.
|
|
|
|
|
|
|
|
PyTuple_SET_ITEM(argsObj, 0, argObj); |
|
|
|
|
|
|
|
PyObject* callResult = RunFunction(moduleObj, name, argsObj); |
|
|
|
if (callResult) |
|
|
|
if (callResult) |
|
|
|
{ |
|
|
|
{ |
|
|
|
result = true; |
|
|
|
result = true; |
|
|
|
Py_DECREF(callResult); |
|
|
|
Py_DECREF(callResult); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Py_DECREF(argsObj); |
|
|
|
Py_DECREF(argsObj); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Py_DECREF(argObj); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
Py_DECREF(moduleObj); |
|
|
|
Py_DECREF(moduleObj); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|