aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generator/cppgenerator.cpp10
-rw-r--r--libshiboken/basewrapper.cpp21
-rw-r--r--libshiboken/basewrapper.h7
3 files changed, 19 insertions, 19 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index d7b8afd02..6ff3e88b6 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -1420,7 +1420,7 @@ void CppGenerator::writeErrorSection(QTextStream& s, OverloadData& overloadData)
void CppGenerator::writeInvalidCppObjectCheck(QTextStream& s, QString pyArgName, const TypeEntry* type)
{
- s << INDENT << "if (Shiboken::cppObjectIsInvalid(" << pyArgName << "))" << endl;
+ s << INDENT << "if (!Shiboken::Wrapper::isValid(" << pyArgName << "))" << endl;
Indentation indent(INDENT);
s << INDENT << "return " << m_currentErrorCode << ';' << endl;
}
@@ -2652,7 +2652,7 @@ void CppGenerator::writeCopyFunction(QTextStream& s, const AbstractMetaClass *me
s << "static PyObject *" << className << "___copy__(PyObject *self)" << endl;
s << "{" << endl;
s << INDENT << metaClass->qualifiedCppName() << "* " CPP_SELF_VAR " = 0;" << endl;
- s << INDENT << "if (Shiboken::cppObjectIsInvalid(self))" << endl;
+ s << INDENT << "if (!Shiboken::Wrapper::isValid(self))" << endl;
{
Indentation indent(INDENT);
s << INDENT << "return 0;" << endl;
@@ -3860,7 +3860,7 @@ void CppGenerator::writeStdListWrapperMethods(QTextStream& s, const AbstractMeta
{
//len
s << "Py_ssize_t " << cpythonBaseName(metaClass->typeEntry()) << "__len__" << "(PyObject* self)" << endl << '{' << endl;
- s << INDENT << "if (Shiboken::cppObjectIsInvalid(self))" << endl;
+ s << INDENT << "if (!Shiboken::Wrapper::isValid(self))" << endl;
s << INDENT << INDENT << "return 0;" << endl << endl;
s << INDENT << metaClass->qualifiedCppName() << " &cppSelf = Shiboken::Converter<" << metaClass->qualifiedCppName() <<"& >::toCpp(self);" << endl;
s << INDENT << "return cppSelf.size();" << endl;
@@ -3868,7 +3868,7 @@ void CppGenerator::writeStdListWrapperMethods(QTextStream& s, const AbstractMeta
//getitem
s << "PyObject* " << cpythonBaseName(metaClass->typeEntry()) << "__getitem__" << "(PyObject* self, Py_ssize_t _i)" << endl << '{' << endl;
- s << INDENT << "if (Shiboken::cppObjectIsInvalid(self))" << endl;
+ s << INDENT << "if (!Shiboken::Wrapper::isValid(self))" << endl;
s << INDENT << INDENT << "return 0;" << endl << endl;
s << INDENT << metaClass->qualifiedCppName() << " &cppSelf = Shiboken::Converter<" << metaClass->qualifiedCppName() <<"& >::toCpp(self);" << endl;
s << INDENT << "if (_i < 0 || _i >= (Py_ssize_t) cppSelf.size()) {" << endl;
@@ -3881,7 +3881,7 @@ void CppGenerator::writeStdListWrapperMethods(QTextStream& s, const AbstractMeta
//setitem
s << "int " << cpythonBaseName(metaClass->typeEntry()) << "__setitem__" << "(PyObject* self, Py_ssize_t _i, PyObject* _value)" << endl << '{' << endl;
- s << INDENT << "if (Shiboken::cppObjectIsInvalid(self))" << endl;
+ s << INDENT << "if (!Shiboken::Wrapper::isValid(self))" << endl;
s << INDENT << INDENT << "return -1;" << endl;
s << INDENT << metaClass->qualifiedCppName() << " &cppSelf = Shiboken::Converter<" << metaClass->qualifiedCppName() <<"& >::toCpp(self);" << endl;
s << INDENT << "if (_i < 0 || _i >= (Py_ssize_t) cppSelf.size()) {" << endl;
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 255bee329..7aa5ed0ec 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -333,17 +333,6 @@ PyObject* SbkBaseWrapper_TpNew(PyTypeObject* subtype, PyObject*, PyObject*)
return reinterpret_cast<PyObject*>(self);
}
-bool cppObjectIsInvalid(PyObject* wrapper)
-{
- if (!wrapper || wrapper == Py_None
- || wrapper->ob_type->ob_type != &Shiboken::SbkBaseWrapperType_Type
- || ((SbkObject*)wrapper)->d->validCppObject) {
- return false;
- }
- PyErr_SetString(PyExc_RuntimeError, "Internal C++ object already deleted.");
- return true;
-}
-
void setTypeUserData(SbkObject* wrapper, void *user_data, DeleteUserDataFunc d_func)
{
SbkBaseWrapperType* ob_type = reinterpret_cast<SbkBaseWrapperType*>(wrapper->ob_type);
@@ -728,6 +717,16 @@ bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr)
return !alreadyInitialized;
}
+bool isValid(PyObject* pyObj)
+{
+ if (!pyObj || pyObj == Py_None
+ || pyObj->ob_type->ob_type != &Shiboken::SbkBaseWrapperType_Type
+ || ((SbkObject*)pyObj)->d->validCppObject) {
+ return true;
+ }
+ PyErr_Format(PyExc_RuntimeError, "Internal C++ object (%s) already deleted.", pyObj->ob_type->tp_name);
+ return false;
+}
} // namespace Wrapper
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index bb76f7ba8..d8511dd82 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -189,9 +189,6 @@ SbkBaseWrapper_TpNew(PyTypeObject* subtype, PyObject*, PyObject*);
*/
LIBSHIBOKEN_API void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append=false);
-/// Returns true and sets a Python RuntimeError if the Python wrapper is not marked as valid.
-LIBSHIBOKEN_API bool cppObjectIsInvalid(PyObject* wrapper);
-
/// Dealloc the python object \p pyObj and the C++ object represented by it.
LIBSHIBOKEN_API void deallocWrapper(PyObject* pyObj);
@@ -227,6 +224,10 @@ LIBSHIBOKEN_API void* cppPointer(PyObject* pyObj, PyTypeObject* desiredType);
*/
LIBSHIBOKEN_API bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr);
+/// Returns false and sets a Python RuntimeError if the Python wrapper is not marked as valid.
+LIBSHIBOKEN_API bool isValid(PyObject* wrapper);
+
+
} // namespace Wrapper
} // namespace Shiboken