diff options
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/basewrapper.cpp | 11 | ||||
-rw-r--r-- | libshiboken/basewrapper.h | 7 | ||||
-rw-r--r-- | libshiboken/sbkdbg.h | 3 |
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); |