summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-01-18 16:51:24 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2011-01-19 16:40:04 -0200
commit4721af29a2225389528ba5984c53ab551058e690 (patch)
treea7928adf9b909451d11583330f6b77b95e6a4ff4
parent3483a54e6b84210e101d905b55d00858070ab62d (diff)
downloadshiboken-4721af29a2225389528ba5984c53ab551058e690.tar.gz
shiboken-4721af29a2225389528ba5984c53ab551058e690.tar.xz
shiboken-4721af29a2225389528ba5984c53ab551058e690.zip
Add Shiboken::Object::isValid(SbkObject* pyObj, bool throwPyError = true) function to libshiboken.
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 <marcelo.lira@openbossa.org> Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--libshiboken/basewrapper.cpp8
-rw-r--r--libshiboken/basewrapper.h9
2 files changed, 16 insertions, 1 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 71892e42..2d82510e 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -785,6 +785,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 bab83a08..1abd43f4 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.