aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-23 09:25:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-25 00:02:59 +0200
commitb35740b35f4ce98c424780d1ceb70e105d495346 (patch)
tree735944e8e07d979c711ff6e8ddd481b89ea2a134
parentb40aa266275898d983592d89158e77f9d38dd40b (diff)
Move more warnings and errors into libshiboken
Comments e1ebbb6527454dda652363795e47aa52a40bd3dd. Task-number: PYSIDE-661 Change-Id: Ia0adc931792532e56e97520c86127cbacb06359c Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp24
-rw-r--r--sources/shiboken6/libshiboken/sbkerrors.cpp17
-rw-r--r--sources/shiboken6/libshiboken/sbkerrors.h9
3 files changed, 37 insertions, 13 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 10817a3cc..025e03580 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1359,11 +1359,10 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s,
<< cpythonIsConvertibleFunction(func->type())
<< PYTHON_RETURN_VAR << ");\n" << outdent
<< "if (!" << PYTHON_TO_CPP_VAR << ") {\n" << indent
- << "Shiboken::warning(PyExc_RuntimeWarning, 2,\n" << indent
- << "\"Invalid return value in function %s, expected %s, got %s.\",\n"
- << "\"" << func->ownerClass()->name() << '.' << funcName << "\",\n"
- << getVirtualFunctionReturnTypeName(func) << ",\n"
- << "Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n" << outdent
+ << "Shiboken::Warnings::warnInvalidReturnValue(\""
+ << func->ownerClass()->name() << "\", \"" << funcName << "\", "
+ << getVirtualFunctionReturnTypeName(func) << ", "
+ << "Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n"
<< returnStatement << '\n' << outdent
<< "}\n";
@@ -1382,11 +1381,10 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s,
if (func->type().isPointerToWrapperType())
s << " && " << PYTHON_RETURN_VAR << " != Py_None";
s << ") {\n" << indent
- << "Shiboken::warning(PyExc_RuntimeWarning, 2,\n" << indent
- << "\"Invalid return value in function %s, expected %s, got %s.\",\n"
- << "\"" << func->ownerClass()->name() << '.' << funcName << "\",\n"
- << getVirtualFunctionReturnTypeName(func) << ",\n"
- << "Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n" << outdent
+ << "Shiboken::Warnings::warnInvalidReturnValue(\""
+ << func->ownerClass()->name() << "\", \"" << funcName << "\", "
+ << getVirtualFunctionReturnTypeName(func) << ", "
+ << "Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n"
<< returnStatement << '\n' << outdent
<< "}\n";
@@ -3189,9 +3187,9 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s,
}
if (func->functionType() == AbstractMetaFunction::EmptyFunction) {
- s << "PyErr_Format(PyExc_TypeError, \"%s is a private method.\", \""
- << func->signature().replace(u"::"_s, u"."_s)
- << "\");\n" << errorReturn;
+ s << "Shiboken::Errors::setPrivateMethod(\""
+ << func->signature().replace(u"::"_s, u"."_s) << "\");\n"
+ << errorReturn;
return;
}
diff --git a/sources/shiboken6/libshiboken/sbkerrors.cpp b/sources/shiboken6/libshiboken/sbkerrors.cpp
index 414334386..f6e7e2e66 100644
--- a/sources/shiboken6/libshiboken/sbkerrors.cpp
+++ b/sources/shiboken6/libshiboken/sbkerrors.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "sbkerrors.h"
+#include "helper.h"
namespace Shiboken
{
@@ -72,6 +73,10 @@ void setPureVirtualMethodError(const char *name)
PyErr_Format(PyExc_NotImplementedError, "pure virtual method '%s' not implemented.", name);
}
+void setPrivateMethod(const char *name)
+{
+ PyErr_Format(PyExc_TypeError, "%s is a private method.\", ", name);
+}
void setReverseOperatorNotImplemented()
{
@@ -98,4 +103,16 @@ void setWrongContainerType()
}
} // namespace Errors
+
+namespace Warnings
+{
+void warnInvalidReturnValue(const char *className, const char *functionName,
+ const char *expectedType, const char *actualType)
+{
+ Shiboken::warning(PyExc_RuntimeWarning, 2,
+ "Invalid return value in function '%s.%s', expected %s, got %s.",
+ className, functionName, expectedType, actualType);
+}
+
+} // namespace Warnings
} // namespace Shiboken
diff --git a/sources/shiboken6/libshiboken/sbkerrors.h b/sources/shiboken6/libshiboken/sbkerrors.h
index baf4da803..8822a9197 100644
--- a/sources/shiboken6/libshiboken/sbkerrors.h
+++ b/sources/shiboken6/libshiboken/sbkerrors.h
@@ -53,12 +53,21 @@ LIBSHIBOKEN_API void setInstantiateAbstractClassDisabledWrapper(const char *name
LIBSHIBOKEN_API void setInvalidTypeDeletion(const char *name);
LIBSHIBOKEN_API void setOperatorNotImplemented();
LIBSHIBOKEN_API void setPureVirtualMethodError(const char *name);
+LIBSHIBOKEN_API void setPrivateMethod(const char *name);
LIBSHIBOKEN_API void setReverseOperatorNotImplemented();
LIBSHIBOKEN_API void setSequenceTypeError(const char *expectedType);
LIBSHIBOKEN_API void setSetterTypeError(const char *name, const char *expectedType);
LIBSHIBOKEN_API void setWrongContainerType();
} // namespace Errors
+
+namespace Warnings
+{
+/// Warn about invalid return value of overwritten virtual
+LIBSHIBOKEN_API void warnInvalidReturnValue(const char *className, const char *functionName,
+ const char *expectedType, const char *actualType);
+} // namespace Warnings
+
} // namespace Shiboken
#endif // SBKERRORS_H