aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-05-10 14:41:03 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:22 -0300
commitce1d707bef6426a1f18f92ab729dc4d89fbe63e4 (patch)
tree7be0f9f2cfe39545d009806d1ce6ac300c915e5f /libshiboken
parent7327989fb85595d1795c1dbd013428b8909b2f0a (diff)
Improved the SbkDbg to avoid throwing exceptions when showing an object.
Also added a new Shiboken::Object::isValid signature to help. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Lauro Moura <lauro.neto@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp11
-rw-r--r--libshiboken/basewrapper.h7
-rw-r--r--libshiboken/sbkdbg.h3
3 files changed, 19 insertions, 2 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 6c8c3fb3c..a34ef1fef 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -848,6 +848,15 @@ bool isValid(SbkObject* pyObj, bool throwPyError)
return true;
}
+bool isValid(PyObject* pyObj, bool throwPyError)
+{
+ if (!pyObj || pyObj == Py_None ||
+ !PyType_IsSubtype(pyObj->ob_type, reinterpret_cast<PyTypeObject*>(&SbkObject_Type))) {
+ return true;
+ }
+ return isValid(reinterpret_cast<SbkObject*>(pyObj), throwPyError);
+}
+
PyObject* newObject(SbkObjectType* instanceType,
void* cptr,
bool hasOwnership,
@@ -1091,7 +1100,7 @@ void clearReferences(SbkObject* self)
self->d->referredObjects = 0;
}
-} // namespace Wrapper
+} // namespace Object
} // namespace Shiboken
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index 1abd43f48..bca252c72 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -263,6 +263,13 @@ LIBSHIBOKEN_API bool isValid(PyObject* pyObj);
LIBSHIBOKEN_API bool isValid(SbkObject* pyObj, bool throwPyError = true);
/**
+ * Returns false if the Python wrapper is not marked as valid.
+ * \param pyObj the object.
+ * \param throwPyError sets a Python RuntimeError when the object isn't valid.
+ */
+LIBSHIBOKEN_API bool isValid(PyObject* pyObj, bool throwPyError);
+
+/**
* Set the parent of \p child to \p parent.
* When an object dies, all their children, grandchildren, etc, are tagged as invalid.
* \param parent the parent object, if null, the child will have no parents.
diff --git a/libshiboken/sbkdbg.h b/libshiboken/sbkdbg.h
index 863ce6de1..7c2bd6030 100644
--- a/libshiboken/sbkdbg.h
+++ b/libshiboken/sbkdbg.h
@@ -24,6 +24,7 @@
#define SBKDBG_H
#include <Python.h>
+#include "basewrapper.h"
#include <iostream>
#ifndef NOCOLOR
@@ -68,7 +69,7 @@ private:
inline std::ostream& operator<<(std::ostream& out, PyObject* obj)
{
- PyObject* repr = PyObject_Repr(obj);
+ PyObject* repr = Shiboken::Object::isValid(obj, false) ? PyObject_Repr(obj) : 0;
if (repr) {
out << PyString_AS_STRING(repr);
Py_DECREF(repr);