From fb00686b6df1cb7514c038e429c12c2c5f3302d6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 19 Oct 2022 09:27:10 +0200 Subject: 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 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Adrian Herrmann --- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp') 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); -- cgit v1.2.3