- 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
This commit is contained in:
parent
e975bfdd0b
commit
6911676b53
|
@ -35,6 +35,12 @@ using namespace std;
|
||||||
PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException)
|
PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException)
|
||||||
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
|
: _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* pLoadmeStr = PyString_FromString(name);
|
||||||
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
|
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
|
||||||
Py_DECREF(pLoadmeStr);
|
Py_DECREF(pLoadmeStr);
|
||||||
|
@ -42,7 +48,17 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
|
||||||
if( !pUserCPUPolicyModule )
|
if( !pUserCPUPolicyModule )
|
||||||
{
|
{
|
||||||
PyErr_Print(); // Error in import
|
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
|
// Dictionary with defined ``symbols'' for .pyc file
|
||||||
|
@ -69,9 +85,15 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
|
||||||
PyTuple_SetItem(pAdapterCtorParam, 0, pCPUPolicyClass);
|
PyTuple_SetItem(pAdapterCtorParam, 0, pCPUPolicyClass);
|
||||||
_adapter = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL);
|
_adapter = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL);
|
||||||
Py_DECREF(pAdapterCtorParam);
|
Py_DECREF(pAdapterCtorParam);
|
||||||
assert(_adapter);
|
|
||||||
|
|
||||||
Py_DECREF(pScriptAdapterModule);
|
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?
|
// And now, who's your daddy, huh?
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ PythonCPUPolicyManager::collect_policies()
|
||||||
}
|
}
|
||||||
catch(MalformedPolicyException e)
|
catch(MalformedPolicyException e)
|
||||||
{
|
{
|
||||||
// TODO do something here someday
|
std::cerr << e.what() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue