aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken/sbkdbg.h
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-03-25 20:04:02 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-03-30 11:43:50 -0300
commit669a4c45eb61d769bc46c976e2b0c50aed25e80e (patch)
treeb57f28ef0d0d9f59498f41162ccf23e01394e9e7 /libshiboken/sbkdbg.h
parent42276efa04d94d79b0b98d070550e95f67870ae3 (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.h13
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: