Show backtrace when catching a C++ exception through Python.
* Change: In PyHurricane.h, in HCATCH macro, show the backtrace when catching a C++ exception. No need to use the "hex" stream manipulator if we cast into (void*).
This commit is contained in:
parent
5435ca1933
commit
6e1d3f0372
|
@ -775,7 +775,7 @@ class tstream : public std::ostream {
|
|||
inline tstream& _tabw ( int count );
|
||||
public:
|
||||
// Overload for manipulators.
|
||||
inline tstream& operator<< ( std::ostream &(*pf)(std::ostream &) );
|
||||
inline tstream& operator<< ( std::ostream& (*pf)(std::ostream &) );
|
||||
private:
|
||||
int _minLevel;
|
||||
int _maxLevel;
|
||||
|
@ -844,9 +844,16 @@ template<typename T>
|
|||
inline tstream& operator<< ( tstream& o, const T* t )
|
||||
{ if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T*>(t); } return o; };
|
||||
|
||||
template<>
|
||||
inline tstream& operator<< ( tstream& o, std::ios_base& (*pf)(std::ios_base&) )
|
||||
{ if (o.enabled()) { static_cast<std::ostream&>(o) << pf; } return o; };
|
||||
|
||||
struct _Tsetw { int n_; };
|
||||
inline _Tsetw tsetw ( int n ) { return { n }; }
|
||||
|
||||
struct _Tsetf { int n_; };
|
||||
inline _Tsetf tsetf ( int n ) { return { n }; }
|
||||
|
||||
template<>
|
||||
inline tstream& operator<< ( tstream& o, _Tsetw manip )
|
||||
{ if (o.enabled()) { static_cast<std::ostream&>(o) << std::setw(manip.n_); } return o; }
|
||||
|
|
|
@ -685,12 +685,12 @@ extern "C" {
|
|||
#define DirectDeleteMethod(PY_FUNC_NAME, PY_SELF_TYPE) \
|
||||
static void PY_FUNC_NAME ( PY_SELF_TYPE *self ) \
|
||||
{ \
|
||||
cdebug_log(20,0) << #PY_SELF_TYPE"_DeAlloc(" << hex << self << ") " \
|
||||
<< hex << (void*)(self->ACCESS_OBJECT) \
|
||||
cdebug_log(20,0) << #PY_SELF_TYPE"_DeAlloc(" << (void*)self << ") " \
|
||||
<< (void*)(self->ACCESS_OBJECT) \
|
||||
<< ":" << self->ACCESS_OBJECT << endl; \
|
||||
\
|
||||
if ( self->ACCESS_OBJECT ) { \
|
||||
cdebug_log(20,0) << "C++ object := " << hex \
|
||||
cdebug_log(20,0) << "C++ object := " \
|
||||
<< &(self->ACCESS_OBJECT) << endl; \
|
||||
delete self->ACCESS_OBJECT; \
|
||||
} \
|
||||
|
@ -705,7 +705,7 @@ extern "C" {
|
|||
#define PlugDeleteMethod(PY_FUNC_NAME,PY_SELF_TYPE) \
|
||||
static void PY_FUNC_NAME ( PY_SELF_TYPE *self ) \
|
||||
{ \
|
||||
cdebug_log(20,0) << "PyHObject_DeAlloc(" << hex << self << ") " \
|
||||
cdebug_log(20,0) << "PyHObject_DeAlloc(" << (void*)self << ") " \
|
||||
<< self->ACCESS_OBJECT << endl; \
|
||||
\
|
||||
PyObject_DEL ( self ); \
|
||||
|
@ -974,7 +974,7 @@ extern "C" {
|
|||
return ( PyString_FromString("<PyObject invalid dynamic-cast>") ); \
|
||||
\
|
||||
ostringstream repr; \
|
||||
repr << "[" << hex << self << "<->" << (void*)object << " " << getString(object) << "]"; \
|
||||
repr << "[" << (void*)self << "<->" << (void*)object << " " << getString(object) << "]"; \
|
||||
\
|
||||
return ( PyString_FromString(repr.str().c_str()) ); \
|
||||
}
|
||||
|
@ -1040,8 +1040,8 @@ extern "C" {
|
|||
if (pyObject == NULL) { return NULL; } \
|
||||
\
|
||||
pyObject->ACCESS_OBJECT = object; \
|
||||
cdebug_log(20,0) << "Py" #SELF_TYPE "_Link(" << hex << pyObject << ") " \
|
||||
<< hex << (void*)object << ":" << object << endl; \
|
||||
cdebug_log(20,0) << "Py" #SELF_TYPE "_Link(" << (void*)pyObject << ") " \
|
||||
<< (void*)object << ":" << object << endl; \
|
||||
HCATCH \
|
||||
\
|
||||
return ( (PyObject*)pyObject ); \
|
||||
|
@ -1102,8 +1102,8 @@ extern "C" {
|
|||
pyObject = (Py##SELF_TYPE*)proxy->getShadow (); \
|
||||
Py_INCREF ( ACCESS_CLASS(pyObject) ); \
|
||||
} \
|
||||
cdebug_log(20,0) << "PyDbo" #SELF_TYPE "_Link(" << hex << pyObject << ") " \
|
||||
<< hex << (void*)object << ":" << object << endl; \
|
||||
cdebug_log(20,0) << "PyDbo" #SELF_TYPE "_Link(" << (void*)pyObject << ") " \
|
||||
<< (void*)object << ":" << object << endl; \
|
||||
HCATCH \
|
||||
\
|
||||
return ( (PyObject*)pyObject ); \
|
||||
|
@ -1115,8 +1115,8 @@ extern "C" {
|
|||
# define DBoDeleteMethod(SELF_TYPE) \
|
||||
static void Py##SELF_TYPE##_DeAlloc ( Py##SELF_TYPE *self ) \
|
||||
{ \
|
||||
cdebug_log(20,0) << "PyDbObject_DeAlloc(" << hex << self << ") " \
|
||||
<< hex << (void*)(self->ACCESS_OBJECT) << ":" << self->ACCESS_OBJECT << endl; \
|
||||
cdebug_log(20,0) << "PyDbObject_DeAlloc(" << (void*)self << ") " \
|
||||
<< (void*)(self->ACCESS_OBJECT) << ":" << self->ACCESS_OBJECT << endl; \
|
||||
\
|
||||
if ( self->ACCESS_OBJECT != NULL ) { \
|
||||
ProxyProperty* proxy = static_cast<ProxyProperty*> \
|
||||
|
@ -1140,8 +1140,8 @@ extern "C" {
|
|||
# define PythonOnlyDeleteMethod(SELF_TYPE) \
|
||||
static void Py##SELF_TYPE##_DeAlloc ( Py##SELF_TYPE *self ) \
|
||||
{ \
|
||||
cdebug_log(20,0) << "PythonOnlyObject_DeAlloc(" << hex << self << ") " \
|
||||
<< hex << (void*)(self->ACCESS_OBJECT) \
|
||||
cdebug_log(20,0) << "PythonOnlyObject_DeAlloc(" << (void*)self << ") " \
|
||||
<< (void*)(self->ACCESS_OBJECT) \
|
||||
<< ":" << self->ACCESS_OBJECT << endl; \
|
||||
PyObject_DEL ( self ); \
|
||||
}
|
||||
|
@ -1155,7 +1155,7 @@ extern "C" {
|
|||
# define NoObjectDeleteMethod(SELF_TYPE) \
|
||||
static void Py##SELF_TYPE##_DeAlloc ( Py##SELF_TYPE *self ) \
|
||||
{ \
|
||||
cdebug_log(20,0) << "PythonOnlyObject_DeAlloc(" << hex << self << ") " \
|
||||
cdebug_log(20,0) << "PythonOnlyObject_DeAlloc(" << (void*)self << ") " \
|
||||
<< "[no object]" << endl; \
|
||||
PyObject_DEL ( self ); \
|
||||
}
|
||||
|
@ -1449,7 +1449,7 @@ extern "C" {
|
|||
PyErr_Warn ( HurricaneWarning, const_cast<char*>(message.c_str()) ); \
|
||||
} \
|
||||
catch ( const Error& e ) { \
|
||||
std::string message = "\n" + getString(e); \
|
||||
std::string message = "\n" + getString(e) + "\n" + e.where(); \
|
||||
PyErr_SetString ( HurricaneError, message.c_str() ); \
|
||||
return NULL; \
|
||||
} \
|
||||
|
|
Loading…
Reference in New Issue