From 39748d5e133fb860f3dfdac34d319b09553be7a9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 18 May 2022 12:55:11 +0200 Subject: shiboken6: Skip Q_ENUM helper functions when PySide extensions are enabled The helper functions qt_getEnumMetaObject() and qt_getEnumName() defined by Q_ENUM had to be rejected in the typesystem files in each namespace. Pass the ApiExtractor flags to the meta builder to cleanly detect all Qt special functions and automatically reject them when PySide extensions are enabled. [ChangeLog][shiboken6] The Q_ENUM helper functions qt_getEnumMetaObject() and qt_getEnumName() are now automatically rejected when PySide extensions are enabled. Fixes: PYSIDE-1932 Change-Id: Iceb5f0c3175ecaef657ae71adf6a5b8bf48af740 Reviewed-by: Qt CI Bot Reviewed-by: Christian Tismer (cherry picked from commit 14c6809ec52ea0583e310825c158fe0e0ab68883) Reviewed-by: Qt Cherry-pick Bot --- .../PySide6/QtCore/typesystem_core_common.xml | 2 -- .../shiboken6/ApiExtractor/abstractmetabuilder.cpp | 32 ++++++++++++++++------ .../shiboken6/ApiExtractor/abstractmetabuilder.h | 2 ++ .../shiboken6/ApiExtractor/abstractmetabuilder_p.h | 1 + sources/shiboken6/ApiExtractor/apiextractor.cpp | 1 + 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 7ac0e95ca..086de7e69 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -520,8 +520,6 @@ - - diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 5fd6ce51e..995e1f316 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -1899,18 +1899,27 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; } const QString &functionName = functionItem->name(); - QString className; - if (currentClass) { + const QString className = currentClass != nullptr ? + currentClass->typeEntry()->qualifiedCppName() : QString{}; + + if (m_apiExtractorFlags.testFlag(ApiExtractorFlag::UsePySideExtensions)) { + // Skip enum helpers generated by Q_ENUM + if ((currentClass == nullptr || currentClass->isNamespace()) + && (functionName == u"qt_getEnumMetaObject" || functionName == u"qt_getEnumName")) { + return nullptr; + } + // Clang: Skip qt_metacast(), qt_metacall(), expanded from Q_OBJECT // and overridden metaObject(), QGADGET helpers - if (functionName == u"qt_check_for_QGADGET_macro" - || functionName.startsWith(u"qt_meta")) { - return nullptr; + if (currentClass != nullptr) { + if (functionName == u"qt_check_for_QGADGET_macro" + || functionName.startsWith(u"qt_meta")) { + return nullptr; + } + if (functionName == u"metaObject" && className != u"QObject") + return nullptr; } - className = currentClass->typeEntry()->qualifiedCppName(); - if (functionName == u"metaObject" && className != u"QObject") - return nullptr; - } + } // PySide extensions // Store original signature with unresolved typedefs for message/log purposes const QString originalQualifiedSignatureWithReturn = @@ -3389,6 +3398,11 @@ void AbstractMetaBuilder::setSkipDeprecated(bool value) d->m_skipDeprecated = value; } +void AbstractMetaBuilder::setApiExtractorFlags(ApiExtractorFlags flags) +{ + d->m_apiExtractorFlags = flags; +} + // PYSIDE-975: When receiving an absolute path name from the code model, try // to resolve it against the include paths set on shiboken in order to recreate // relative paths like #include . diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h index afbba9e86..ebdfce1c7 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h @@ -95,6 +95,8 @@ public: void setSkipDeprecated(bool value); + void setApiExtractorFlags(ApiExtractorFlags flags); + enum TranslateTypeFlag { DontResolveType = 0x1 }; diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h index 18de68047..34f590945 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h @@ -241,6 +241,7 @@ public: QStringList m_headerPaths; mutable QHash m_resolveIncludeHash; QList m_typeSystemTypeDefs; // look up metatype->class for type system typedefs + ApiExtractorFlags m_apiExtractorFlags; bool m_skipDeprecated = false; static bool m_useGlobalHeader; static bool m_codeModelTestMode; diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp index d0265c16a..4a06c1320 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.cpp +++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp @@ -265,6 +265,7 @@ bool ApiExtractorPrivate::runHelper(ApiExtractorFlags flags) m_builder->setGlobalHeaders(m_cppFileNames); m_builder->setSkipDeprecated(m_skipDeprecated); m_builder->setHeaderPaths(m_includePaths); + m_builder->setApiExtractorFlags(flags); QByteArrayList arguments; const auto clangOptionsSize = m_clangOptions.size(); -- cgit v1.2.3