aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-01-17 13:15:15 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-19 06:47:06 +0000
commit94a593baf32f9a2c38329834f66d2261164dd3b5 (patch)
treed3500f90a8cf45850522c751997d7617d153ad41
parent5b901c74180b75dc30f1c53442a4b6ff1e56a5e6 (diff)
shiboken6: Fix handling of value types with protected constructors
Value types with some protected constructors (like QOperatingSystemVersionBase in 6.3) caused compile errors on Windows where the protected hack is disabled since non-accessible constructors were used. The check for isValueTypeWithCopyConstructorOnly() needs to be fixed to exclude protected constructors in case AvoidProtectedHack is set. Similarly, the visibility of the minimal default constructor needs to be checked. Add the AvoidProtectedHack setting to ApiExtractorResult for this purpose since it influences the API in a way. Change-Id: Ifeab320b9391aa21c5b1de4d21d2d8276fe44d3f Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit ef2223f3d712e5f66c4654f7bce2011869ef958a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp4
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.cpp6
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.h3
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.cpp1
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractorresult.h6
-rw-r--r--sources/shiboken6/generator/generator.cpp1
6 files changed, 17 insertions, 4 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
index 6b9ea6a0f..5e521b745 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
@@ -536,7 +536,9 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom,
if (cls->canAddDefaultCopyConstructor())
cls->addDefaultCopyConstructor();
- const bool vco = AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(cls);
+ const bool avoidProtectedHack = flags.testFlag(ApiExtractorFlag::AvoidProtectedHack);
+ const bool vco =
+ AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(cls, avoidProtectedHack);
cls->setValueTypeWithCopyConstructorOnly(vco);
cls->typeEntry()->setValueTypeWithCopyConstructorOnly(vco);
}
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
index 2e824fff7..1f957ea30 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
@@ -1797,7 +1797,8 @@ void AbstractMetaClass::setValueTypeWithCopyConstructorOnly(bool v)
d->m_valueTypeWithCopyConstructorOnly = v;
}
-bool AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c)
+bool AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c,
+ bool avoidProtectedHack)
{
if (!c->typeEntry()->isValue())
@@ -1809,7 +1810,8 @@ bool AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(const Abstract
for (const auto &ctor : ctors) {
switch (ctor->functionType()) {
case AbstractMetaFunction::ConstructorFunction:
- return false;
+ if (!ctor->isPrivate() && (ctor->isPublic() || !avoidProtectedHack))
+ return false;
case AbstractMetaFunction::CopyConstructorFunction:
copyConstructorFound = true;
break;
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h
index 555b7158f..df978f598 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h
@@ -349,7 +349,8 @@ public:
bool isCopyable() const;
bool isValueTypeWithCopyConstructorOnly() const;
void setValueTypeWithCopyConstructorOnly(bool v);
- static bool determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c);
+ static bool determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c,
+ bool avoidProtectedHack);
static AbstractMetaClass *findClass(const AbstractMetaClassList &classes,
const QString &name);
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp
index 2535b0746..6b171e5d5 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp
@@ -259,6 +259,7 @@ std::optional<ApiExtractorResult> ApiExtractor::run(ApiExtractorFlags flags)
result.m_globalFunctions = m_builder->globalFunctions();
result.m_globalEnums = m_builder->globalEnums();
result.m_enums = m_builder->typeEntryToEnumsHash();
+ result.m_flags = flags;
return result;
}
diff --git a/sources/shiboken6/ApiExtractor/apiextractorresult.h b/sources/shiboken6/ApiExtractor/apiextractorresult.h
index 18b07a1b7..c40dcb936 100644
--- a/sources/shiboken6/ApiExtractor/apiextractorresult.h
+++ b/sources/shiboken6/ApiExtractor/apiextractorresult.h
@@ -30,6 +30,7 @@
#define APIEXTRACTORRESULT_H
#include "abstractmetalang.h"
+#include "apiextractorflags.h"
#include "abstractmetaenum.h"
#include "abstractmetatype.h"
#include "typesystem_typedefs.h"
@@ -63,6 +64,9 @@ public:
AbstractMetaFunctionCList implicitConversions(const TypeEntry *type) const;
AbstractMetaFunctionCList implicitConversions(const AbstractMetaType &metaType) const;
+ ApiExtractorFlags flags() const { return m_flags; }
+ void setFlags(ApiExtractorFlags f) { m_flags = f; }
+
private:
AbstractMetaClassCList m_metaClasses;
AbstractMetaClassCList m_smartPointers;
@@ -70,6 +74,8 @@ private:
AbstractMetaEnumList m_globalEnums;
QHash<const TypeEntry *, AbstractMetaEnum> m_enums;
+
+ ApiExtractorFlags m_flags;
};
#endif // APIEXTRACTORRESULT_H
diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp
index 2eead95d1..c5d32c041 100644
--- a/sources/shiboken6/generator/generator.cpp
+++ b/sources/shiboken6/generator/generator.cpp
@@ -730,6 +730,7 @@ std::optional<DefaultValue>
const auto &constructors = metaClass->queryFunctions(FunctionQueryOption::Constructors);
for (const auto &ctor : constructors) {
if (!ctor->isUserAdded() && !ctor->isPrivate()
+ && (ctor->isPublic() || !api.flags().testFlag(ApiExtractorFlag::AvoidProtectedHack))
&& ctor->functionType() == AbstractMetaFunction::ConstructorFunction) {
// No arguments: Default constructible
const auto &arguments = ctor->arguments();