aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-04-29 08:31:38 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-04-30 07:32:16 +0200
commit538f897fb5829b670f42c8e45e291f85d969c5e8 (patch)
tree880ec6522ddf8bd3b79fd2c2577328ab642ad15a /sources/shiboken2/generator
parent656bf562baa88d3410947177477c86f339591770 (diff)
Add an option for diagnostic output for wrappers
Print which wrappers are instantiated and what the methd cache entry contains for the virtual methods. Task-number: PYSIDE-1255 Change-Id: Ib5fd92a78a4ff1b53e373b82ade8f67b95c0dd26 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp22
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.h2
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp7
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.h3
4 files changed, 31 insertions, 3 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 71c46e6c0..aef9fc33e 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -330,6 +330,9 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
if (metaClass->generateExceptionHandling())
s << "#include <exception>\n";
+ if (wrapperDiagnostics())
+ s << "#include <helper.h>\n#include <iostream>\n";
+
s << "\n// module include\n" << "#include \"" << getModuleHeaderFileName() << "\"\n";
QString headerfile = fileNameForContext(classContext);
@@ -708,6 +711,8 @@ void CppGenerator::writeConstructorNative(QTextStream &s, const AbstractMetaFunc
s << " : ";
writeFunctionCall(s, func);
s << "\n{\n";
+ if (wrapperDiagnostics())
+ s << INDENT << R"(std::cerr << __FUNCTION__ << ' ' << this << '\n';)" << '\n';
const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast();
s << INDENT << "resetPyMethodCache();\n";
writeCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, func, lastArg);
@@ -720,6 +725,8 @@ void CppGenerator::writeDestructorNative(QTextStream &s, const AbstractMetaClass
{
Indentation indentation(INDENT);
s << wrapperName(metaClass) << "::~" << wrapperName(metaClass) << "()\n{\n";
+ if (wrapperDiagnostics())
+ s << INDENT << R"(std::cerr << __FUNCTION__ << ' ' << this << '\n';)" << '\n';
// kill pyobject
s << INDENT << "SbkObject *wrapper = Shiboken::BindingManager::instance().retrieveWrapper(this);\n";
s << INDENT << "Shiboken::Object::destroy(wrapper, this);\n";
@@ -848,6 +855,15 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
// PYSIDE-803: Build a boolean cache for unused overrides.
bool multi_line = retType == nullptr; // set to true when using instrumentation
+ if (wrapperDiagnostics()) {
+ s << INDENT << "std::cerr << ";
+#ifndef Q_CC_MSVC // g++ outputs __FUNCTION__ unqualified
+ s << '"' << prefix << R"(" << )";
+#endif
+ s << R"(__FUNCTION__ << ' ' << this << " m_PyMethodCache[" << )"
+ << cacheIndex << R"( << "]=" << m_PyMethodCache[)" << cacheIndex
+ << R"(] << '\n';)" << '\n';
+ }
s << INDENT << "if (m_PyMethodCache[" << cacheIndex << "])" << (multi_line ? " {\n" : "\n");
{
Indentation indentation(INDENT);
@@ -5254,10 +5270,14 @@ QString CppGenerator::writeSmartPointerGetterCast()
+ QLatin1String(SMART_POINTER_GETTER) + QLatin1Char(')');
}
-void CppGenerator::writeSetattroDefinition(QTextStream &s, const AbstractMetaClass *metaClass)
+void CppGenerator::writeSetattroDefinition(QTextStream &s, const AbstractMetaClass *metaClass) const
{
s << "static int " << ShibokenGenerator::cpythonSetattroFunctionName(metaClass)
<< "(PyObject *self, PyObject *name, PyObject *value)\n{\n";
+ if (wrapperDiagnostics()) {
+ s << INDENT << R"(std::cerr << __FUNCTION__ << ' ' << Shiboken::debugPyObject(name)
+ << ' ' << Shiboken::debugPyObject(value) << '\n';)" << '\n';
+ }
}
inline void CppGenerator::writeSetattroDefaultReturn(QTextStream &s) const
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h
index aee1fb7d4..2f0219bfa 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.h
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h
@@ -106,7 +106,7 @@ private:
void writeTypeDiscoveryFunction(QTextStream &s, const AbstractMetaClass *metaClass);
- static void writeSetattroDefinition(QTextStream &s, const AbstractMetaClass *metaClass);
+ void writeSetattroDefinition(QTextStream &s, const AbstractMetaClass *metaClass) const;
void writeSetattroDefaultReturn(QTextStream &s) const;
void writeSmartPointerSetattroFunction(QTextStream &s, GeneratorContext &context);
void writeSetattroFunction(QTextStream &s, AttroCheck attroCheck, GeneratorContext &context);
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 8876bcf83..90ae4299d 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -47,6 +47,7 @@ static const char RETURN_VALUE_HEURISTIC[] = "enable-return-value-heuristic";
static const char ENABLE_PYSIDE_EXTENSIONS[] = "enable-pyside-extensions";
static const char DISABLE_VERBOSE_ERROR_MESSAGES[] = "disable-verbose-error-messages";
static const char USE_ISNULL_AS_NB_NONZERO[] = "use-isnull-as-nb_nonzero";
+static const char WRAPPER_DIAGNOSTICS[] = "wrapper-diagnostics";
const char *CPP_ARG = "cppArg";
const char *CPP_ARG_REMOVED = "removed_cppArg";
@@ -2503,7 +2504,9 @@ Generator::OptionDescriptions ShibokenGenerator::options() const
"(USE WITH CAUTION!)"))
<< qMakePair(QLatin1String(USE_ISNULL_AS_NB_NONZERO),
QLatin1String("If a class have an isNull() const method, it will be used to compute\n"
- "the value of boolean casts"));
+ "the value of boolean casts"))
+ << qMakePair(QLatin1String(WRAPPER_DIAGNOSTICS),
+ QLatin1String("Generate diagnostic code around wrappers"));
}
bool ShibokenGenerator::handleOption(const QString &key, const QString & /* value */)
@@ -2520,6 +2523,8 @@ bool ShibokenGenerator::handleOption(const QString &key, const QString & /* valu
return (m_useIsNullAsNbNonZero = true);
if (key == QLatin1String(AVOID_PROTECTED_HACK))
return (m_avoidProtectedHack = true);
+ if (key == QLatin1String(WRAPPER_DIAGNOSTICS))
+ return (m_wrapperDiagnostics = true);
return false;
}
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
index d0e9073c8..2ad5ffbdf 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
@@ -227,6 +227,8 @@ protected:
QString fullPythonClassName(const AbstractMetaClass *metaClass);
QString fullPythonFunctionName(const AbstractMetaFunction *func);
+ bool wrapperDiagnostics() const { return m_wrapperDiagnostics; }
+
static QString protectedEnumSurrogateName(const AbstractMetaEnum *metaEnum);
static QString protectedFieldGetterName(const AbstractMetaField *field);
static QString protectedFieldSetterName(const AbstractMetaField *field);
@@ -548,6 +550,7 @@ private:
bool m_verboseErrorMessagesDisabled = false;
bool m_useIsNullAsNbNonZero = false;
bool m_avoidProtectedHack = false;
+ bool m_wrapperDiagnostics = false;
using AbstractMetaTypeCache = QHash<QString, AbstractMetaType *>;
AbstractMetaTypeCache m_metaTypeFromStringCache;