From 517800c3cd93c48d897ac868505e22e2e972aa22 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Tue, 18 Jan 2011 16:51:24 -0200 Subject: Add Shiboken::Object::isValid(SbkObject* pyObj, bool throwPyError = true) function to libshiboken. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function is needed to fix bug#552 when a libpyside code needs to check if a SbkObject is valid without set a Python error when it isn't. Reviewer: Marcelo Lira Renato Araújo --- libshiboken/basewrapper.cpp | 8 ++++++++ libshiboken/basewrapper.h | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'libshiboken') diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 737bfadc9..1a4a60f52 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -786,6 +786,14 @@ bool isValid(PyObject* pyObj) return false; } +bool isValid(SbkObject* pyObj, bool throwPyError) +{ + bool result = !pyObj || pyObj->d->validCppObject; + if (!result && throwPyError) + PyErr_Format(PyExc_RuntimeError, "Internal C++ object (%s) already deleted.", pyObj->ob_type->tp_name); + return result; +} + PyObject* newObject(SbkObjectType* instanceType, void* cptr, bool hasOwnership, diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index bab83a08f..1abd43f48 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -253,7 +253,14 @@ LIBSHIBOKEN_API bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desir /** * Returns false and sets a Python RuntimeError if the Python wrapper is not marked as valid. */ -LIBSHIBOKEN_API bool isValid(PyObject* wrapper); +LIBSHIBOKEN_API bool isValid(PyObject* pyObj); + +/** + * 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(SbkObject* pyObj, bool throwPyError = true); /** * Set the parent of \p child to \p parent. -- cgit v1.2.3