diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-25 20:04:02 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-30 11:43:50 -0300 |
commit | 669a4c45eb61d769bc46c976e2b0c50aed25e80e (patch) | |
tree | b57f28ef0d0d9f59498f41162ccf23e01394e9e7 /libshiboken/sbkdbg.h | |
parent | 42276efa04d94d79b0b98d070550e95f67870ae3 (diff) |
Add std::ostream& operator<<(std::ostream& out, PyObject* obj) to create better and easier debug messages.
Diffstat (limited to 'libshiboken/sbkdbg.h')
-rw-r--r-- | libshiboken/sbkdbg.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libshiboken/sbkdbg.h b/libshiboken/sbkdbg.h index 62dacb8a6..b3db0227a 100644 --- a/libshiboken/sbkdbg.h +++ b/libshiboken/sbkdbg.h @@ -35,6 +35,7 @@ #ifndef SBKDBG_H #define SBKDBG_H +#include <Python.h> #include <iostream> #ifndef NOCOLOR @@ -77,6 +78,18 @@ private: const char* m_context; }; +inline std::ostream& operator<<(std::ostream& out, PyObject* obj) +{ + PyObject* repr = PyObject_Repr(obj); + if (repr) { + out << PyString_AS_STRING(repr); + Py_DECREF(repr); + } else { + out << reinterpret_cast<void*>(obj); + } + return out; +} + class _SbkDbg : public BaseLogger { public: |