aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-08 14:21:19 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-08 14:21:19 +0200
commit00fa3966dbed373e341710f1145fd23a88f1bdb0 (patch)
tree331be762988f22221b40ed93486b9b05b657f0bd /sources
parente801fdab20ad4f5f47deaf49600af0d5f02ecc51 (diff)
parent2ed45ce8991408de91d7e02a2b80a09a2d9e5083 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp19
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp2
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.h22
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp33
-rw-r--r--sources/shiboken2/generator/generator.cpp3
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp27
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.cpp8
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp5
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp22
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py4
10 files changed, 90 insertions, 55 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index d06a338a3..70cccebcd 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -175,12 +175,12 @@ void AbstractMetaBuilderPrivate::checkFunctionModifications()
const TypeEntry *entry = it.value();
if (!entry)
continue;
- if (!entry->isComplex() || entry->codeGeneration() == TypeEntry::GenerateNothing)
+ if (!entry->isComplex() || !entry->generateCode())
continue;
auto centry = static_cast<const ComplexTypeEntry *>(entry);
- if (!(centry->codeGeneration() & TypeEntry::GenerateTargetLang))
+ if (!centry->generateCode())
continue;
FunctionModificationList modifications = centry->functionModifications();
@@ -290,7 +290,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte
if (arguments.size() == 1) {
unaryOperator = true;
} else if (!baseoperandClass
- || !(baseoperandClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang)) {
+ || !baseoperandClass->typeEntry()->generateCode()) {
baseoperandClass = argumentToClass(arguments.at(1), currentClass);
firstArgumentIsSelf = false;
} else {
@@ -551,7 +551,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
&& !types->shouldDropTypeEntry(entry->qualifiedCppName())
&& !entry->isContainer()
&& !entry->isCustom()
- && (entry->generateCode() & TypeEntry::GenerateTargetLang)
+ && entry->generateCode()
&& !AbstractMetaClass::findClass(m_metaClasses, entry)) {
qCWarning(lcShiboken, "%s", qPrintable(msgTypeNotDefined(entry)));
} else if (entry->generateCode() && entry->type() == TypeEntry::FunctionType) {
@@ -570,7 +570,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
qPrintable(msgGlobalFunctionNotDefined(fte, signature)));
}
}
- } else if (entry->isEnum() && (entry->generateCode() & TypeEntry::GenerateTargetLang)) {
+ } else if (entry->isEnum() && entry->generateCode()) {
auto enumEntry = static_cast<const EnumTypeEntry *>(entry);
const QString name = enumEntry->targetLangQualifier();
AbstractMetaClass *cls = AbstractMetaClass::findClass(m_metaClasses, name);
@@ -855,8 +855,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem &
return nullptr;
}
- const bool rejectionWarning = !enclosing
- || (enclosing->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang);
+ const bool rejectionWarning = !enclosing || enclosing->typeEntry()->generateCode();
if (!typeEntry) {
if (rejectionWarning)
@@ -1185,7 +1184,7 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel
if (!metaType) {
const QString type = TypeInfo::resolveType(fieldType, currentScope()).qualifiedName().join(colonColon());
- if (cls->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang) {
+ if (cls->typeEntry()->generateCode()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgSkippingField(field, cls->name(), type)));
}
@@ -1865,9 +1864,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
// unless the function is virtual (since the override in the
// wrapper can then not correctly be generated).
if (arg->defaultValue() && !functionItem->isVirtual()) {
- if (!currentClass
- || (currentClass->typeEntry()->codeGeneration()
- & TypeEntry::GenerateTargetLang)) {
+ if (!currentClass || currentClass->typeEntry()->generateCode()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgStrippingArgument(functionItem, i, originalQualifiedSignatureWithReturn, arg)));
}
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index 87f5c49df..0d5a8cba7 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.cpp
+++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp
@@ -432,7 +432,7 @@ ConstantValueTypeEntry *
const TypeEntry *parent)
{
auto result = new ConstantValueTypeEntry(value, parent);
- result->setCodeGeneration(0);
+ result->setCodeGeneration(TypeEntry::GenerateNothing);
addType(result);
return result;
}
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h
index 00f56c51e..d3ef2c629 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.h
+++ b/sources/shiboken2/ApiExtractor/typesystem.h
@@ -598,13 +598,10 @@ public:
Q_ENUM(Type)
enum CodeGeneration {
- GenerateTargetLang = 0x0001,
- GenerateCpp = 0x0002,
- GenerateForSubclass = 0x0004,
-
- GenerateNothing = 0,
- GenerateAll = 0xffff,
- GenerateCode = GenerateTargetLang | GenerateCpp
+ GenerateNothing, // Rejection, private type, ConstantValueTypeEntry or similar
+ GenerationDisabled, // generate='no' in type system
+ GenerateCode, // Generate code
+ GenerateForSubclass, // Inherited from a loaded dependent type system.
};
Q_ENUM(CodeGeneration)
@@ -703,11 +700,11 @@ public:
// Name as specified in XML
QString entryName() const { return m_entryName; }
- uint codeGeneration() const
+ CodeGeneration codeGeneration() const
{
return m_codeGeneration;
}
- void setCodeGeneration(uint cg)
+ void setCodeGeneration(CodeGeneration cg)
{
m_codeGeneration = cg;
}
@@ -719,8 +716,7 @@ public:
// on 'load-typesystem' tag
inline bool generateCode() const
{
- return m_codeGeneration != TypeEntry::GenerateForSubclass
- && m_codeGeneration != TypeEntry::GenerateNothing;
+ return m_codeGeneration == GenerateCode;
}
int revision() const { return m_revision; }
@@ -804,7 +800,7 @@ public:
return m_docModifications;
}
- IncludeList extraIncludes() const
+ const IncludeList &extraIncludes() const
{
return m_extraIncludes;
}
@@ -903,7 +899,7 @@ private:
QVersionNumber m_version;
CustomConversion *m_customConversion = nullptr;
SourceLocation m_sourceLocation; // XML file
- uint m_codeGeneration = GenerateAll;
+ CodeGeneration m_codeGeneration = GenerateCode;
TypeEntry *m_viewOn = nullptr;
int m_revision = 0;
int m_sbkIndex = 0;
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index 7323e01f6..9ad9322b2 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -505,7 +505,7 @@ QString TypeSystemEntityResolver::resolveUndeclaredEntity(const QString &name)
TypeSystemParser::TypeSystemParser(TypeDatabase *database, bool generate) :
m_database(database),
- m_generate(generate ? TypeEntry::GenerateAll : TypeEntry::GenerateForSubclass)
+ m_generate(generate ? TypeEntry::GenerateCode : TypeEntry::GenerateForSubclass)
{
}
@@ -775,7 +775,7 @@ bool TypeSystemParser::endElement(QStringView localName)
switch (m_current->type) {
case StackElement::Root:
- if (m_generate == TypeEntry::GenerateAll) {
+ if (m_generate == TypeEntry::GenerateCode) {
TypeDatabase::instance()->addGlobalUserFunctions(m_contextStack.top()->addedFunctions);
TypeDatabase::instance()->addGlobalUserFunctionModifications(m_contextStack.top()->functionMods);
for (CustomConversion *customConversion : qAsConst(customConversionsForReview)) {
@@ -790,13 +790,26 @@ bool TypeSystemParser::endElement(QStringView localName)
case StackElement::InterfaceTypeEntry:
case StackElement::NamespaceTypeEntry: {
auto *centry = static_cast<ComplexTypeEntry *>(m_current->entry);
- centry->setAddedFunctions(m_contextStack.top()->addedFunctions);
- centry->setFunctionModifications(m_contextStack.top()->functionMods);
- centry->setFieldModifications(m_contextStack.top()->fieldMods);
- centry->setCodeSnips(m_contextStack.top()->codeSnips);
- centry->setDocModification(m_contextStack.top()->docModifications);
+ auto top = m_contextStack.top();
+ centry->setAddedFunctions(top->addedFunctions);
+ centry->setFunctionModifications(top->functionMods);
+ centry->setFieldModifications(top->fieldMods);
+ centry->setCodeSnips(top->codeSnips);
+ centry->setDocModification(top->docModifications);
}
break;
+
+ case StackElement::TypedefTypeEntry: {
+ auto *centry = static_cast<TypedefEntry *>(m_current->entry)->target();
+ auto top = m_contextStack.top();
+ centry->setAddedFunctions(centry->addedFunctions() + top->addedFunctions);
+ centry->setFunctionModifications(centry->functionModifications() + top->functionMods);
+ centry->setFieldModifications(centry->fieldModifications() + top->fieldMods);
+ centry->setCodeSnips(centry->codeSnips() + top->codeSnips);
+ centry->setDocModification(centry->docModifications() + top->docModifications);
+ }
+ break;
+
case StackElement::AddFunction: {
// Leaving add-function: Assign all modifications to the added function
StackElementContext *top = m_contextStack.top();
@@ -1576,7 +1589,7 @@ void TypeSystemParser::applyComplexTypeAttributes(const QXmlStreamReader &reader
if (generate)
ctype->setCodeGeneration(m_generate);
else
- ctype->setCodeGeneration(TypeEntry::GenerateForSubclass);
+ ctype->setCodeGeneration(TypeEntry::GenerationDisabled);
}
bool TypeSystemParser::parseRenameFunction(const QXmlStreamReader &,
@@ -1760,7 +1773,7 @@ bool TypeSystemParser::loadTypesystem(const QXmlStreamReader &,
}
const bool result =
m_database->parseFile(typeSystemName, m_currentPath, generateChild
- && m_generate == TypeEntry::GenerateAll);
+ && m_generate == TypeEntry::GenerateCode);
if (!result)
m_error = QStringLiteral("Failed to parse: '%1'").arg(typeSystemName);
return result;
@@ -2779,7 +2792,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
auto *element = new StackElement(m_current);
element->type = elementType;
- if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateAll)
+ if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateCode)
customConversionsForReview.clear();
if (element->type == StackElement::CustomMetaConstructor
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 487715a3c..445743a74 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -502,8 +502,7 @@ bool Generator::generate()
bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) const
{
- return (type->codeGeneration() & TypeEntry::GenerateTargetLang)
- && NamespaceTypeEntry::isVisibleScope(type);
+ return type->generateCode() && NamespaceTypeEntry::isVisibleScope(type);
}
bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 18137a985..a6e9a00b6 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -393,14 +393,18 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo
metaClass->getEnumsFromInvisibleNamespacesToBeGenerated(&classEnums);
//Extra includes
- s << "\n// Extra includes\n";
- QVector<Include> includes = metaClass->typeEntry()->extraIncludes();
+ QVector<Include> includes;
+ if (!classContext.useWrapper())
+ includes += metaClass->typeEntry()->extraIncludes();
for (AbstractMetaEnum *cppEnum : qAsConst(classEnums))
includes.append(cppEnum->typeEntry()->extraIncludes());
- std::sort(includes.begin(), includes.end());
- for (const Include &inc : qAsConst(includes))
- s << inc.toString() << Qt::endl;
- s << Qt::endl;
+ if (!includes.isEmpty()) {
+ s << "\n// Extra includes\n";
+ std::sort(includes.begin(), includes.end());
+ for (const Include &inc : qAsConst(includes))
+ s << inc.toString() << Qt::endl;
+ s << '\n';
+ }
s << "\n#include <cctype>\n#include <cstring>\n";
@@ -5234,9 +5238,16 @@ void CppGenerator::writeClassRegister(QTextStream &s,
s << "0,\n";
}
- // 6:baseType
- const auto base = metaClass->isNamespace()
+ // 6:baseType: Find a type that is not disabled.
+ auto base = metaClass->isNamespace()
? metaClass->extendedNamespace() : metaClass->baseClass();
+ if (!metaClass->isNamespace()) {
+ for (; base != nullptr; base = base->baseClass()) {
+ const auto ct = base->typeEntry()->codeGeneration();
+ if (ct == TypeEntry::GenerateCode || ct == TypeEntry::GenerateForSubclass)
+ break;
+ }
+ }
if (base) {
s << INDENT << "reinterpret_cast<SbkObjectType *>("
<< cpythonTypeNameExt(base->typeEntry()) << "),\n";
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
index 1d3a20447..1ba846d87 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
@@ -119,7 +119,13 @@ void HeaderGenerator::generateClass(QTextStream &s, const GeneratorContext &clas
s << "#define protected public\n\n";
//Includes
- s << metaClass->typeEntry()->include() << Qt::endl;
+ auto typeEntry = metaClass->typeEntry();
+ s << typeEntry->include() << '\n';
+ if (classContext.useWrapper() && !typeEntry->extraIncludes().isEmpty()) {
+ s << "\n// Extra includes\n";
+ for (const Include &inc : typeEntry->extraIncludes())
+ s << inc.toString() << '\n';
+ }
if (classContext.useWrapper() && usePySideExtensions() && metaClass->isQObject())
s << "namespace PySide { class DynamicQMetaObject; }\n\n";
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index a6a175999..7b8f2c7e4 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -929,7 +929,7 @@ QString ShibokenGenerator::fixedCppTypeName(const TypeEntry *type, QString typeN
{
if (typeName.isEmpty())
typeName = type->qualifiedCppName();
- if (!(type->codeGeneration() & TypeEntry::GenerateTargetLang)) {
+ if (!type->generateCode()) {
typeName.prepend(QLatin1Char('_'));
typeName.prepend(type->targetLangPackage());
}
@@ -1609,8 +1609,7 @@ ShibokenGenerator::ExtendedConverterData ShibokenGenerator::getExtendedConverter
// Get only the conversion operators that return a type from another module,
// that are value-types and were not removed in the type system.
const TypeEntry *convType = convOp->type()->typeEntry();
- if ((convType->codeGeneration() & TypeEntry::GenerateTargetLang)
- || !convType->isValue()
+ if (convType->generateCode() || !convType->isValue()
|| convOp->isModifiedRemoved())
continue;
extConvs[convType].append(convOp->ownerClass());
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index fff9d05ec..ca32f5919 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -42,6 +42,7 @@
#include "autodecref.h"
#include <vector>
+#include <unordered_set>
namespace Shiboken
{
@@ -183,7 +184,7 @@ Py_ssize_t len(PyObject *str)
// PyObject *attr = PyObject_GetAttr(obj, name());
//
-using StaticStrings = std::vector<PyObject *>;
+using StaticStrings = std::unordered_set<PyObject *>;
static void finalizeStaticStrings(); // forward
@@ -195,10 +196,12 @@ static StaticStrings &staticStrings()
static void finalizeStaticStrings()
{
- auto &list = staticStrings();
- for (PyObject *ob : list)
+ auto &set = staticStrings();
+ for (PyObject *ob : set) {
+ Py_REFCNT(ob) = 1;
Py_DECREF(ob);
- list.clear();
+ }
+ set.clear();
}
PyObject *createStaticString(const char *str)
@@ -218,7 +221,16 @@ PyObject *createStaticString(const char *str)
PyErr_Print();
Py_FatalError("unexpected error in createStaticString()");
}
- staticStrings().push_back(result);
+ auto it = staticStrings().find(result);
+ if (it == staticStrings().end())
+ staticStrings().insert(result);
+ /*
+ * Note: We always add one reference even if we have a new string.
+ * This makes the strings immortal, and we are safe if someone
+ * uses AutoDecRef, although the set cannot cope with deletions.
+ * The exit handler cleans that up, anyway.
+ */
+ Py_INCREF(result);
return result;
}
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py
index 64f654d30..ece3d2edb 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py
@@ -104,7 +104,9 @@ Note: This are two imports.
# XXX build an improved C version? I guess not.
def _import(name, *args, **kwargs):
# PYSIDE-1368: The `__name__` attribute does not need to exist in all modules.
- importing_module = sys._getframe(1).f_globals.get("__name__", "__main__")
+ # PYSIDE-1398: sys._getframe(1) may not exist when embedding.
+ calling_frame = _cf = sys._getframe().f_back
+ importing_module = _cf.f_globals.get("__name__", "__main__") if _cf else "__main__"
existing = pyside_feature_dict.get(importing_module, 0)
if name == "__feature__" and args[2]: