From c26d21efbb65e198e95c23f31f5197e642ce542a Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Fri, 14 May 2010 12:28:16 +0000 Subject: [PATCH] add error handling. Patch by Christian Engwer [[Imported from SVN: r3331]] --- ag-common/functions/pythonfunction.hh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ag-common/functions/pythonfunction.hh b/ag-common/functions/pythonfunction.hh index 0f0452f0..ade6e246 100644 --- a/ag-common/functions/pythonfunction.hh +++ b/ag-common/functions/pythonfunction.hh @@ -98,6 +98,14 @@ struct EmbeddedPython PyObject* pModule = PyImport_Import(pModuleName); PyObject* pMember = PyObject_GetAttrString(pModule, memberName.c_str()); + if (!pModuleName) + DUNE_THROW(Dune::Exception, "failed to construct python string for " << moduleName); + if (!pModule) + DUNE_THROW(Dune::Exception, "failed to retrieve python module " << moduleName); + if (!pMember) + DUNE_THROW(Dune::Exception, "failed to retrieve python member " << memberName + << " from module " << moduleName); + // decrement reference counts Py_DECREF(pModuleName); Py_DECREF(pModule); @@ -111,6 +119,13 @@ struct EmbeddedPython PyObject* pClassArgs = PyTuple_New(0); PyObject* pObject = PyObject_CallObject(pClass, pClassArgs); + if (!pClass) + DUNE_THROW(Dune::Exception, "failed to retrieve python class " << className); + if (!pClassArgs) + DUNE_THROW(Dune::Exception, "failed to create python class arguments"); + if (!pObject) + DUNE_THROW(Dune::Exception, "failed to create python class object for class " << className); + // decrement reference counts Py_DECREF(pClass); Py_DECREF(pClassArgs); @@ -222,7 +237,9 @@ class PythonFunction : PyRun_SimpleString(s.str().c_str()); // get reference for python function - setCallable(EmbeddedPython::getModuleMember("__main__", name), true); + PyObject* fnkt = EmbeddedPython::getModuleMember("__main__", name); + assert(fnkt != 0); + setCallable(fnkt, true); } virtual ~PythonFunction() -- GitLab