mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[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:
parent
4eb0d49c23
commit
5a1c2945e4
@ -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();
|
||||||
|
|
||||||
|
@ -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" );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user