aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-10-19 09:27:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-10-31 19:12:20 +0100
commitfb00686b6df1cb7514c038e429c12c2c5f3302d6 (patch)
treeb1678b9a4f521d9bf8ebd9a87cb4226b22c76ca7 /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parentf9bdba5135f26ba5862793e84ba495a529a14639 (diff)
Fix crashes when not implementing abstract method
Ensure the PyErr_ methods are called with GIL held. Fixes: PYSIDE-2089 Pick-to: 6.4 Change-Id: Ibe3aa95e17875e3acc47094b1f9211dacf1b59c5 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 7aad78b65..5fe171c25 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1195,7 +1195,7 @@ void CppGenerator::writeVirtualMethodCppCall(TextStream &s,
const CodeSnipList &snips,
const AbstractMetaArgument *lastArg,
const TypeEntry *retType,
- const QString &returnStatement) const
+ const QString &returnStatement, bool hasGil) const
{
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning,
@@ -1203,12 +1203,17 @@ void CppGenerator::writeVirtualMethodCppCall(TextStream &s,
}
if (func->isAbstract()) {
+ if (!hasGil)
+ s << "Shiboken::GilState gil;\n";
s << "Shiboken::Errors::setPureVirtualMethodError(\""
<< func->ownerClass()->name() << '.' << funcName << "\");\n"
<< returnStatement << '\n';
return;
}
+ if (hasGil)
+ s << "gil.release();\n";
+
if (retType)
s << "return ";
s << "this->::" << func->implementingClass()->qualifiedCppName() << "::";
@@ -1421,7 +1426,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s,
s << "if (m_PyMethodCache[" << cacheIndex << "])" << (multi_line ? " {\n" : "\n")
<< indent;
writeVirtualMethodCppCall(s, func, funcName, snips, lastArg, retType,
- returnStatement);
+ returnStatement, false);
s << outdent;
if (multi_line)
s << "}\n";
@@ -1450,12 +1455,11 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s,
s << "static const char *funcName = \"" << propStr << funcName << "\";\n"
<< "Shiboken::AutoDecRef " << PYTHON_OVERRIDE_VAR
<< "(Shiboken::BindingManager::instance().getOverride(this, nameCache, funcName));\n"
- << "if (" << PYTHON_OVERRIDE_VAR << ".isNull()) {\n"
- << indent << "gil.release();\n";
+ << "if (" << PYTHON_OVERRIDE_VAR << ".isNull()) {\n" << indent;
if (useOverrideCaching(func->ownerClass()))
s << "m_PyMethodCache[" << cacheIndex << "] = true;\n";
writeVirtualMethodCppCall(s, func, funcName, snips, lastArg, retType,
- returnStatement);
+ returnStatement, true);
s << outdent << "}\n\n"; //WS
writeConversionRule(s, func, TypeSystem::TargetLangCode, false);