[0.3.x] fixed : every call to pykd leads to big stack alloctaion

git-svn-id: https://pykd.svn.codeplex.com/svn@86870 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-12-17 09:08:38 +00:00 committed by Mikhail I. Izmestev
parent 4eb0d49c23
commit 5a1c2945e4
2 changed files with 43 additions and 27 deletions

View File

@ -9,6 +9,7 @@
namespace pykd { namespace pykd {
template< class TExcept > template< class TExcept >
struct exceptPyType{ struct exceptPyType{
static python::handle<> pyExceptType; static python::handle<> pyExceptType;
@ -43,34 +44,55 @@ public:
python::scope().attr( className.c_str() ) = ob; python::scope().attr( className.c_str() ) = ob;
exceptPyType<TExcept>::pyExceptType = python::handle<>( ob.ptr() ); exceptPyType<TExcept>::pyExceptType = python::handle<>( ob.ptr() );
python::register_exception_translator<TExcept>( &exceptionTranslate );
} }
static
void
exceptionTranslate(const TExcept &e ) {
python::object exceptObj = python::object( exceptPyType<TExcept>::pyExceptType )( e.what() );
PyErr_SetObject( exceptPyType<TExcept>::pyExceptType.get(), exceptObj.ptr());
}
}; };
//////////////////////////////////////////////////////////////////////////////
struct ExceptionTranslator {
static inline void exceptionTranslate(const kdlib::DbgException &e )
void {
indexTranslate(const kdlib::IndexException &e ) { if ( typeid(e).hash_code() == typeid(kdlib::MemoryException).hash_code() )
{
python::object exceptObj = python::object( exceptPyType<kdlib::MemoryException>::pyExceptType )( e.what() );
PyErr_SetObject( exceptPyType<kdlib::MemoryException>::pyExceptType.get(), exceptObj.ptr());
return;
}
if ( typeid(e).hash_code() == typeid(kdlib::SymbolException).hash_code() )
{
python::object exceptObj = python::object( exceptPyType<kdlib::SymbolException>::pyExceptType )( e.what() );
PyErr_SetObject( exceptPyType<kdlib::SymbolException>::pyExceptType.get(), exceptObj.ptr());
return;
}
if ( typeid(e).hash_code() == typeid(kdlib::TypeException).hash_code() )
{
python::object exceptObj = python::object( exceptPyType<kdlib::TypeException>::pyExceptType )( e.what() );
PyErr_SetObject( exceptPyType<kdlib::TypeException>::pyExceptType.get(), exceptObj.ptr());
return;
}
if ( typeid(e).hash_code() == typeid(kdlib::IndexException).hash_code() )
{
PyErr_SetString( PyExc_IndexError, "Index out of range"); PyErr_SetString( PyExc_IndexError, "Index out of range");
return;
} }
}; python::object exceptObj = python::object( exceptPyType<kdlib::DbgException>::pyExceptType )( e.what() );
PyErr_SetObject( exceptPyType<kdlib::DbgException>::pyExceptType.get(), exceptObj.ptr());
}
/////////////////////////////////////////////////////////////////////////////////// inline void registerExceptions()
{
pykd::exception<kdlib::DbgException>( "DbgException", "Pykd base exception class" );
pykd::exception<kdlib::MemoryException,kdlib::DbgException>( "MemoryException", "Target memory access exception class" );
pykd::exception<kdlib::SymbolException,kdlib::DbgException>( "SymbolException", "Symbol exception" );
pykd::exception<kdlib::TypeException,kdlib::SymbolException>( "TypeException", "type exception" );
python::register_exception_translator<kdlib::DbgException>( &exceptionTranslate );
}
/////////////////////////////////////////////////////////////////////////////////////
void printException(); void printException();

View File

@ -772,14 +772,8 @@ BOOST_PYTHON_MODULE( pykd )
// "There is no return value"); // "There is no return value");
; ;
python::register_exception_translator<kdlib::IndexException>( &ExceptionTranslator::indexTranslate ); // C++ exception translation to python
pykd::registerExceptions();
// kdlib exception
pykd::exception<kdlib::DbgException>( "DbgException", "Pykd base exception class" );
pykd::exception<kdlib::MemoryException,kdlib::DbgException>( "MemoryException", "Target memory access exception class" );
pykd::exception<kdlib::SymbolException,kdlib::DbgException>( "SymbolException", "Symbol exception" );
pykd::exception<kdlib::TypeException,kdlib::SymbolException>( "TypeException", "type exception" );
} }
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////