From 6911676b53dcb913a2935d3d747cfc8106b260b9 Mon Sep 17 00:00:00 2001 From: elvez Date: Wed, 9 Aug 2006 00:50:45 +0000 Subject: [PATCH] - Added some code for better error-reporting in case of malformed policies. Actually it`s commented because it doesn`t work... git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@831 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/python_cpu_policy.cc | 28 +++++++++++++++++-- .../pyloader/src/python_cpu_policy_manager.cc | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/pyloader/src/python_cpu_policy.cc b/plugins/pyloader/src/python_cpu_policy.cc index 8d5e851..68686ba 100644 --- a/plugins/pyloader/src/python_cpu_policy.cc +++ b/plugins/pyloader/src/python_cpu_policy.cc @@ -35,6 +35,12 @@ using namespace std; PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException) : _upolicy_dict(NULL), _adapter(NULL), _name(name) { + //PyRun_SimpleString("import StringIO\nimport sys\nsys.stderr = cStringIO.StringIO()\n"); + + //PyObject* pBuiltinsMod = PyImport_ImportModule("__builtin__"); + //PyObject* pBuiltinsDict = PyModule_GetDict(pBuiltinsMod); + + PyObject* pLoadmeStr = PyString_FromString(name); PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr); Py_DECREF(pLoadmeStr); @@ -42,7 +48,17 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio if( !pUserCPUPolicyModule ) { PyErr_Print(); // Error in import - throw MalformedPolicyException("this message should be the stuff printed by PyErr_Print"); + + +// PyObject* msg = PyRun_String("import sys\nsys.stderr.getvalue()", Py_eval_input, pBuiltinsDict, NULL); + + +// if(msg == NULL) +// PyErr_Print(); + +// char* str = PyString_AsString(msg); +// throw MalformedPolicyException(PyString_AS_STRING(msg)); + throw MalformedPolicyException(""); } // Dictionary with defined ``symbols'' for .pyc file @@ -69,9 +85,15 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio PyTuple_SetItem(pAdapterCtorParam, 0, pCPUPolicyClass); _adapter = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL); Py_DECREF(pAdapterCtorParam); - assert(_adapter); - + Py_DECREF(pScriptAdapterModule); + + if(_adapter == NULL) + { + PyErr_Print(); + throw MalformedPolicyException(_("unable to instantiate ScriptAdapter, " + "check that all methods are implemented")); + } // And now, who's your daddy, huh? } diff --git a/plugins/pyloader/src/python_cpu_policy_manager.cc b/plugins/pyloader/src/python_cpu_policy_manager.cc index e131b8d..9e50a60 100644 --- a/plugins/pyloader/src/python_cpu_policy_manager.cc +++ b/plugins/pyloader/src/python_cpu_policy_manager.cc @@ -141,7 +141,7 @@ PythonCPUPolicyManager::collect_policies() } catch(MalformedPolicyException e) { - // TODO do something here someday + std::cerr << e.what() << endl; } } else