diff options
13 files changed, 194 insertions, 164 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py index 5375e9f8a..dc90d99b7 100644 --- a/build_scripts/utils.py +++ b/build_scripts/utils.py @@ -1141,7 +1141,8 @@ def run_instruction(instruction, error, initial_env=None): def acceptCITestConfiguration(hostOS, hostOSVer, targetArch, compiler): # Disable unsupported CI configs for now # NOTE: String must match with QT CI's storagestruct thrift - if hostOSVer in ["WinRT_10", "WebAssembly", "Ubuntu_18_04"]: + if hostOSVer in ["WinRT_10", "WebAssembly", "Ubuntu_18_04"] \ + or hostOSVer.startswith("SLES_"): print("Disabled " + hostOSVer + " from Coin configuration") return False # With 5.11 CI will create two sets of release binaries, one with msvc 2015 and one with msvc 2017 diff --git a/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport.xml.in b/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport.xml.in index 7949b2daa..ff078d19a 100644 --- a/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport.xml.in +++ b/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport.xml.in @@ -40,7 +40,6 @@ ****************************************************************************/ --> <typesystem package="PySide2.QtPrintSupport"> - <load-typesystem name="QtGui/typesystem_gui.xml" generate="no"/> <load-typesystem name="QtWidgets/typesystem_widgets.xml" generate="no"/> <load-typesystem name="QtPrintSupport/typesystem_printsupport_common.xml" generate="yes"/> </typesystem> diff --git a/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport_common.xml b/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport_common.xml index c11a6e046..487103875 100644 --- a/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport_common.xml +++ b/sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport_common.xml @@ -40,6 +40,7 @@ ****************************************************************************/ --> <typesystem package="PySide2.QtPrintSupport"> + <load-typesystem name="QtWidgets/typesystem_widgets.xml" generate="no"/> <object-type name="QPageSetupDialog"> <modify-function signature="exec()" rename="exec_" allow-thread="yes"/> diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 3e1bab97b..93f7321aa 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1289,7 +1289,7 @@ Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); PyObject *pyTimer = reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); -QTimer * timer = %CONVERTTOCPP[QTimer *](pyTimer); +auto timer = %CONVERTTOCPP[QTimer *](pyTimer); //XXX /|\ omitting this space crashes shiboken! Shiboken::AutoDecRef result( PyObject_CallMethod(pyTimer, @@ -1484,8 +1484,7 @@ if (PySide::SignalManager::registerMetaMethod(%1, signalName.mid(1).toLatin1().d if (!PyObject_TypeCheck(%1, PySideSignalInstanceTypeF())) goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError; PySideSignalInstance *signalInstance = reinterpret_cast<PySideSignalInstance *>(%1); -QObject * sender = %CONVERTTOCPP[QObject *](PySide::Signal::getObject(signalInstance)); -//XXX /|\ omitting this space crashes shiboken! +auto sender = %CONVERTTOCPP[QObject *](PySide::Signal::getObject(signalInstance)); QSignalTransition *%0 = %CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance),%2); %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition *](%0); // @snippet qstate-addtransition-2 diff --git a/sources/pyside2/doc/codesnippets/examples/dialogs/standarddialogs/dialog.cpp b/sources/pyside2/doc/codesnippets/examples/dialogs/standarddialogs/dialog.cpp index d4dde36bc..db11e22f8 100644 --- a/sources/pyside2/doc/codesnippets/examples/dialogs/standarddialogs/dialog.cpp +++ b/sources/pyside2/doc/codesnippets/examples/dialogs/standarddialogs/dialog.cpp @@ -49,32 +49,32 @@ ****************************************************************************/ //! [0] - i = QInputDialog().getInteger(self, self.tr("QInputDialog().getInteger()"), - self.tr("Percentage:"), 25, 0, 100, 1, ok) + i, ok = QInputDialog().getInteger(self, "QInputDialog().getInteger()", + "Percentage:", 25, 0, 100, 1) if ok: - self.integerLabel.setText(self.tr("%1%").arg(i)) + self.integerLabel.setText("{}%".format(i)) //! [0] //! [1] - d = QInputDialog().getDouble(self, self.tr("QInputDialog().getDouble()"), - self.tr("Amount:"), 37.56, -10000, 10000, 2, ok) + d, ok = QInputDialog().getDouble(self, "QInputDialog().getDouble()", + "Amount:", 37.56, -10000, 10000, 2) if ok: - doubleLabel.setText(QString("$%1").arg(d)) + doubleLabel.setText("${}".format()) //! [1] //! [2] - items = [self.tr("Spring"), self.tr("Summer"), self.tr("Fall"), self.tr("Winter")] + items = ["Spring", "Summer", "Fall", "Winter"] - item = QInputDialog().getItem(self, self.tr("QInputDialog().getItem()"), - selftr("Season:"), items, 0, False, ok) + item, ok = QInputDialog().getItem(self, "QInputDialog().getItem()", + "Season:", items, 0, False) if ok and not item.isEmpty(): itemLabel.setText(item) //! [2] //! [3] - text = QInputDialog::getText(self, self.tr("QInputDialog().getText()"), - self.tr("User name:"), QLineEdit.Normal, - QDir().home().dirName(), ok) + text, ok = QInputDialog().getText(self, "QInputDialog().getText()", + "User name:", QLineEdit.Normal, + QDir().home().dirName()) if ok and text: textLabel.setText(text) //! [3] diff --git a/sources/pyside2/tests/QtCore/qslot_object_test.py b/sources/pyside2/tests/QtCore/qslot_object_test.py index b8d5513ff..7a2691a06 100644 --- a/sources/pyside2/tests/QtCore/qslot_object_test.py +++ b/sources/pyside2/tests/QtCore/qslot_object_test.py @@ -31,7 +31,10 @@ import unittest from PySide2 import QtCore -global qApp +""" +This is a simple slot test that was updated to use the qApp "macro". +It is implicitly in builtins and does not need an import. +""" class objTest(QtCore.QObject): @@ -41,21 +44,15 @@ class objTest(QtCore.QObject): self.ok = False def slot(self): - global qApp - self.ok = True qApp.quit() - class slotTest(unittest.TestCase): def quit_app(self): - global qApp - qApp.quit() def testBasic(self): - global qApp timer = QtCore.QTimer() timer.setInterval(100) @@ -71,6 +68,5 @@ class slotTest(unittest.TestCase): if __name__ == '__main__': - global qApp - qApp = QtCore.QCoreApplication([]) + QtCore.QCoreApplication() unittest.main() diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index 57ceb357f..5440de5c0 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -191,200 +191,200 @@ static EnumType functionName(QStringView needle, EnumType defaultValue = default ENUM_LOOKUP_BEGIN(TypeSystem::AllowThread, Qt::CaseInsensitive, allowThreadFromAttribute, TypeSystem::AllowThread::Unspecified) { - {QStringViewLiteral("yes"), TypeSystem::AllowThread::Allow}, - {QStringViewLiteral("true"), TypeSystem::AllowThread::Allow}, - {QStringViewLiteral("auto"), TypeSystem::AllowThread::Auto}, - {QStringViewLiteral("no"), TypeSystem::AllowThread::Disallow}, - {QStringViewLiteral("false"), TypeSystem::AllowThread::Disallow}, + {u"yes", TypeSystem::AllowThread::Allow}, + {u"true", TypeSystem::AllowThread::Allow}, + {u"auto", TypeSystem::AllowThread::Auto}, + {u"no", TypeSystem::AllowThread::Disallow}, + {u"false", TypeSystem::AllowThread::Disallow}, }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::Language, Qt::CaseInsensitive, languageFromAttribute, TypeSystem::NoLanguage) { - {QStringViewLiteral("all"), TypeSystem::All}, // sorted! - {QStringViewLiteral("constructors"), TypeSystem::Constructors}, - {QStringViewLiteral("destructor-function"), TypeSystem::DestructorFunction}, - {QStringViewLiteral("interface"), TypeSystem::Interface}, - {QStringViewLiteral("library-initializer"), TypeSystem::PackageInitializer}, - {QStringViewLiteral("native"), TypeSystem::NativeCode}, // em algum lugar do cpp - {QStringViewLiteral("shell"), TypeSystem::ShellCode}, // coloca no header, mas antes da declaracao da classe - {QStringViewLiteral("shell-declaration"), TypeSystem::ShellDeclaration}, - {QStringViewLiteral("target"), TypeSystem::TargetLangCode} // em algum lugar do cpp + {u"all", TypeSystem::All}, // sorted! + {u"constructors", TypeSystem::Constructors}, + {u"destructor-function", TypeSystem::DestructorFunction}, + {u"interface", TypeSystem::Interface}, + {u"library-initializer", TypeSystem::PackageInitializer}, + {u"native", TypeSystem::NativeCode}, // em algum lugar do cpp + {u"shell", TypeSystem::ShellCode}, // coloca no header, mas antes da declaracao da classe + {u"shell-declaration", TypeSystem::ShellDeclaration}, + {u"target", TypeSystem::TargetLangCode} // em algum lugar do cpp }; ENUM_LOOKUP_BINARY_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::Ownership, Qt::CaseInsensitive, ownershipFromFromAttribute, TypeSystem::InvalidOwnership) { - {QStringViewLiteral("target"), TypeSystem::TargetLangOwnership}, - {QStringViewLiteral("c++"), TypeSystem::CppOwnership}, - {QStringViewLiteral("default"), TypeSystem::DefaultOwnership} + {u"target", TypeSystem::TargetLangOwnership}, + {u"c++", TypeSystem::CppOwnership}, + {u"default", TypeSystem::DefaultOwnership} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(AddedFunction::Access, Qt::CaseInsensitive, addedFunctionAccessFromAttribute, AddedFunction::InvalidAccess) { - {QStringViewLiteral("public"), AddedFunction::Public}, - {QStringViewLiteral("protected"), AddedFunction::Protected}, + {u"public", AddedFunction::Public}, + {u"protected", AddedFunction::Protected}, }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(Modification::Modifiers, Qt::CaseSensitive, modifierFromAttribute, Modification::InvalidModifier) { - {QStringViewLiteral("private"), Modification::Private}, - {QStringViewLiteral("public"), Modification::Public}, - {QStringViewLiteral("protected"), Modification::Protected}, - {QStringViewLiteral("friendly"), Modification::Friendly}, - {QStringViewLiteral("rename"), Modification::Rename}, - {QStringViewLiteral("final"), Modification::Final}, - {QStringViewLiteral("non-final"), Modification::NonFinal} + {u"private", Modification::Private}, + {u"public", Modification::Public}, + {u"protected", Modification::Protected}, + {u"friendly", Modification::Friendly}, + {u"rename", Modification::Rename}, + {u"final", Modification::Final}, + {u"non-final", Modification::NonFinal} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(ReferenceCount::Action, Qt::CaseInsensitive, referenceCountFromAttribute, ReferenceCount::Invalid) { - {QStringViewLiteral("add"), ReferenceCount::Add}, - {QStringViewLiteral("add-all"), ReferenceCount::AddAll}, - {QStringViewLiteral("remove"), ReferenceCount::Remove}, - {QStringViewLiteral("set"), ReferenceCount::Set}, - {QStringViewLiteral("ignore"), ReferenceCount::Ignore} + {u"add", ReferenceCount::Add}, + {u"add-all", ReferenceCount::AddAll}, + {u"remove", ReferenceCount::Remove}, + {u"set", ReferenceCount::Set}, + {u"ignore", ReferenceCount::Ignore} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(ArgumentOwner::Action, Qt::CaseInsensitive, argumentOwnerActionFromAttribute, ArgumentOwner::Invalid) { - {QStringViewLiteral("add"), ArgumentOwner::Add}, - {QStringViewLiteral("remove"), ArgumentOwner::Remove} + {u"add", ArgumentOwner::Add}, + {u"remove", ArgumentOwner::Remove} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::CodeSnipPosition, Qt::CaseInsensitive, codeSnipPositionFromAttribute, TypeSystem::CodeSnipPositionInvalid) { - {QStringViewLiteral("beginning"), TypeSystem::CodeSnipPositionBeginning}, - {QStringViewLiteral("end"), TypeSystem::CodeSnipPositionEnd}, - {QStringViewLiteral("declaration"), TypeSystem::CodeSnipPositionDeclaration}, - {QStringViewLiteral("prototype-initialization"), TypeSystem::CodeSnipPositionPrototypeInitialization}, - {QStringViewLiteral("constructor-initialization"), TypeSystem::CodeSnipPositionConstructorInitialization}, - {QStringViewLiteral("constructor"), TypeSystem::CodeSnipPositionConstructor} + {u"beginning", TypeSystem::CodeSnipPositionBeginning}, + {u"end", TypeSystem::CodeSnipPositionEnd}, + {u"declaration", TypeSystem::CodeSnipPositionDeclaration}, + {u"prototype-initialization", TypeSystem::CodeSnipPositionPrototypeInitialization}, + {u"constructor-initialization", TypeSystem::CodeSnipPositionConstructorInitialization}, + {u"constructor", TypeSystem::CodeSnipPositionConstructor} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(Include::IncludeType, Qt::CaseInsensitive, locationFromAttribute, Include::InvalidInclude) { - {QStringViewLiteral("global"), Include::IncludePath}, - {QStringViewLiteral("local"), Include::LocalPath}, - {QStringViewLiteral("target"), Include::TargetLangImport} + {u"global", Include::IncludePath}, + {u"local", Include::LocalPath}, + {u"target", Include::TargetLangImport} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::DocModificationMode, Qt::CaseInsensitive, docModificationFromAttribute, TypeSystem::DocModificationInvalid) { - {QStringViewLiteral("append"), TypeSystem::DocModificationAppend}, - {QStringViewLiteral("prepend"), TypeSystem::DocModificationPrepend}, - {QStringViewLiteral("replace"), TypeSystem::DocModificationReplace} + {u"append", TypeSystem::DocModificationAppend}, + {u"prepend", TypeSystem::DocModificationPrepend}, + {u"replace", TypeSystem::DocModificationReplace} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(ContainerTypeEntry::Type, Qt::CaseSensitive, containerTypeFromAttribute, ContainerTypeEntry::NoContainer) { - {QStringViewLiteral("list"), ContainerTypeEntry::ListContainer}, - {QStringViewLiteral("string-list"), ContainerTypeEntry::StringListContainer}, - {QStringViewLiteral("linked-list"), ContainerTypeEntry::LinkedListContainer}, - {QStringViewLiteral("vector"), ContainerTypeEntry::VectorContainer}, - {QStringViewLiteral("stack"), ContainerTypeEntry::StackContainer}, - {QStringViewLiteral("queue"), ContainerTypeEntry::QueueContainer}, - {QStringViewLiteral("set"), ContainerTypeEntry::SetContainer}, - {QStringViewLiteral("map"), ContainerTypeEntry::MapContainer}, - {QStringViewLiteral("multi-map"), ContainerTypeEntry::MultiMapContainer}, - {QStringViewLiteral("hash"), ContainerTypeEntry::HashContainer}, - {QStringViewLiteral("multi-hash"), ContainerTypeEntry::MultiHashContainer}, - {QStringViewLiteral("pair"), ContainerTypeEntry::PairContainer} + {u"list", ContainerTypeEntry::ListContainer}, + {u"string-list", ContainerTypeEntry::StringListContainer}, + {u"linked-list", ContainerTypeEntry::LinkedListContainer}, + {u"vector", ContainerTypeEntry::VectorContainer}, + {u"stack", ContainerTypeEntry::StackContainer}, + {u"queue", ContainerTypeEntry::QueueContainer}, + {u"set", ContainerTypeEntry::SetContainer}, + {u"map", ContainerTypeEntry::MapContainer}, + {u"multi-map", ContainerTypeEntry::MultiMapContainer}, + {u"hash", ContainerTypeEntry::HashContainer}, + {u"multi-hash", ContainerTypeEntry::MultiHashContainer}, + {u"pair", ContainerTypeEntry::PairContainer} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeRejection::MatchType, Qt::CaseSensitive, typeRejectionFromAttribute, TypeRejection::Invalid) { - {QStringViewLiteral("class"), TypeRejection::ExcludeClass}, - {QStringViewLiteral("function-name"), TypeRejection::Function}, - {QStringViewLiteral("field-name"), TypeRejection::Field}, - {QStringViewLiteral("enum-name"), TypeRejection::Enum }, - {QStringViewLiteral("argument-type"), TypeRejection::ArgumentType}, - {QStringViewLiteral("return-type"), TypeRejection::ReturnType} + {u"class", TypeRejection::ExcludeClass}, + {u"function-name", TypeRejection::Function}, + {u"field-name", TypeRejection::Field}, + {u"enum-name", TypeRejection::Enum }, + {u"argument-type", TypeRejection::ArgumentType}, + {u"return-type", TypeRejection::ReturnType} }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::ExceptionHandling, Qt::CaseSensitive, exceptionHandlingFromAttribute, TypeSystem::ExceptionHandling::Unspecified) { - {QStringViewLiteral("no"), TypeSystem::ExceptionHandling::Off}, - {QStringViewLiteral("false"), TypeSystem::ExceptionHandling::Off}, - {QStringViewLiteral("auto-off"), TypeSystem::ExceptionHandling::AutoDefaultToOff}, - {QStringViewLiteral("auto-on"), TypeSystem::ExceptionHandling::AutoDefaultToOn}, - {QStringViewLiteral("yes"), TypeSystem::ExceptionHandling::On}, - {QStringViewLiteral("true"), TypeSystem::ExceptionHandling::On}, + {u"no", TypeSystem::ExceptionHandling::Off}, + {u"false", TypeSystem::ExceptionHandling::Off}, + {u"auto-off", TypeSystem::ExceptionHandling::AutoDefaultToOff}, + {u"auto-on", TypeSystem::ExceptionHandling::AutoDefaultToOn}, + {u"yes", TypeSystem::ExceptionHandling::On}, + {u"true", TypeSystem::ExceptionHandling::On}, }; ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive, elementFromTag, StackElement::None) { - {QStringViewLiteral("access"), StackElement::Access}, // sorted! - {QStringViewLiteral("add-conversion"), StackElement::AddConversion}, - {QStringViewLiteral("add-function"), StackElement::AddFunction}, - {QStringViewLiteral("argument-map"), StackElement::ArgumentMap}, - {QStringViewLiteral("array"), StackElement::Array}, - {QStringViewLiteral("container-type"), StackElement::ContainerTypeEntry}, - {QStringViewLiteral("conversion-rule"), StackElement::ConversionRule}, - {QStringViewLiteral("custom-constructor"), StackElement::CustomMetaConstructor}, - {QStringViewLiteral("custom-destructor"), StackElement::CustomMetaDestructor}, - {QStringViewLiteral("custom-type"), StackElement::CustomTypeEntry}, - {QStringViewLiteral("define-ownership"), StackElement::DefineOwnership}, - {QStringViewLiteral("enum-type"), StackElement::EnumTypeEntry}, - {QStringViewLiteral("extra-includes"), StackElement::ExtraIncludes}, - {QStringViewLiteral("function"), StackElement::FunctionTypeEntry}, - {QStringViewLiteral("include"), StackElement::Include}, - {QStringViewLiteral("inject-code"), StackElement::InjectCode}, - {QStringViewLiteral("inject-documentation"), StackElement::InjectDocumentation}, - {QStringViewLiteral("insert-template"), StackElement::TemplateInstanceEnum}, - {QStringViewLiteral("interface-type"), StackElement::InterfaceTypeEntry}, - {QStringViewLiteral("load-typesystem"), StackElement::LoadTypesystem}, - {QStringViewLiteral("modify-argument"), StackElement::ModifyArgument}, - {QStringViewLiteral("modify-documentation"), StackElement::ModifyDocumentation}, - {QStringViewLiteral("modify-field"), StackElement::ModifyField}, - {QStringViewLiteral("modify-function"), StackElement::ModifyFunction}, - {QStringViewLiteral("namespace-type"), StackElement::NamespaceTypeEntry}, - {QStringViewLiteral("native-to-target"), StackElement::NativeToTarget}, - {QStringViewLiteral("no-null-pointer"), StackElement::NoNullPointers}, - {QStringViewLiteral("object-type"), StackElement::ObjectTypeEntry}, - {QStringViewLiteral("parent"), StackElement::ParentOwner}, - {QStringViewLiteral("primitive-type"), StackElement::PrimitiveTypeEntry}, - {QStringViewLiteral("reference-count"), StackElement::ReferenceCount}, - {QStringViewLiteral("reject-enum-value"), StackElement::RejectEnumValue}, - {QStringViewLiteral("rejection"), StackElement::Rejection}, - {QStringViewLiteral("remove"), StackElement::Removal}, - {QStringViewLiteral("remove-argument"), StackElement::RemoveArgument}, - {QStringViewLiteral("remove-default-expression"), StackElement::RemoveDefaultExpression}, - {QStringViewLiteral("rename"), StackElement::Rename}, - {QStringViewLiteral("replace"), StackElement::Replace}, - {QStringViewLiteral("replace-default-expression"), StackElement::ReplaceDefaultExpression}, - {QStringViewLiteral("replace-type"), StackElement::ReplaceType}, - {QStringViewLiteral("smart-pointer-type"), StackElement::SmartPointerTypeEntry}, - {QStringViewLiteral("suppress-warning"), StackElement::SuppressedWarning}, - {QStringViewLiteral("target-to-native"), StackElement::TargetToNative}, - {QStringViewLiteral("template"), StackElement::Template}, - {QStringViewLiteral("typedef-type"), StackElement::TypedefTypeEntry}, - {QStringViewLiteral("typesystem"), StackElement::Root}, - {QStringViewLiteral("value-type"), StackElement::ValueTypeEntry}, + {u"access", StackElement::Access}, // sorted! + {u"add-conversion", StackElement::AddConversion}, + {u"add-function", StackElement::AddFunction}, + {u"argument-map", StackElement::ArgumentMap}, + {u"array", StackElement::Array}, + {u"container-type", StackElement::ContainerTypeEntry}, + {u"conversion-rule", StackElement::ConversionRule}, + {u"custom-constructor", StackElement::CustomMetaConstructor}, + {u"custom-destructor", StackElement::CustomMetaDestructor}, + {u"custom-type", StackElement::CustomTypeEntry}, + {u"define-ownership", StackElement::DefineOwnership}, + {u"enum-type", StackElement::EnumTypeEntry}, + {u"extra-includes", StackElement::ExtraIncludes}, + {u"function", StackElement::FunctionTypeEntry}, + {u"include", StackElement::Include}, + {u"inject-code", StackElement::InjectCode}, + {u"inject-documentation", StackElement::InjectDocumentation}, + {u"insert-template", StackElement::TemplateInstanceEnum}, + {u"interface-type", StackElement::InterfaceTypeEntry}, + {u"load-typesystem", StackElement::LoadTypesystem}, + {u"modify-argument", StackElement::ModifyArgument}, + {u"modify-documentation", StackElement::ModifyDocumentation}, + {u"modify-field", StackElement::ModifyField}, + {u"modify-function", StackElement::ModifyFunction}, + {u"namespace-type", StackElement::NamespaceTypeEntry}, + {u"native-to-target", StackElement::NativeToTarget}, + {u"no-null-pointer", StackElement::NoNullPointers}, + {u"object-type", StackElement::ObjectTypeEntry}, + {u"parent", StackElement::ParentOwner}, + {u"primitive-type", StackElement::PrimitiveTypeEntry}, + {u"reference-count", StackElement::ReferenceCount}, + {u"reject-enum-value", StackElement::RejectEnumValue}, + {u"rejection", StackElement::Rejection}, + {u"remove", StackElement::Removal}, + {u"remove-argument", StackElement::RemoveArgument}, + {u"remove-default-expression", StackElement::RemoveDefaultExpression}, + {u"rename", StackElement::Rename}, + {u"replace", StackElement::Replace}, + {u"replace-default-expression", StackElement::ReplaceDefaultExpression}, + {u"replace-type", StackElement::ReplaceType}, + {u"smart-pointer-type", StackElement::SmartPointerTypeEntry}, + {u"suppress-warning", StackElement::SuppressedWarning}, + {u"target-to-native", StackElement::TargetToNative}, + {u"template", StackElement::Template}, + {u"typedef-type", StackElement::TypedefTypeEntry}, + {u"typesystem", StackElement::Root}, + {u"value-type", StackElement::ValueTypeEntry}, }; ENUM_LOOKUP_BINARY_SEARCH() @@ -991,17 +991,17 @@ static bool convertRemovalAttribute(QStringView remove, Modification& mod, QStri if (remove.isEmpty()) return true; #ifdef QTBUG_69389_FIXED - if (remove.compare(QStringViewLiteral("all"), Qt::CaseInsensitive) == 0) { + if (remove.compare(u"all", Qt::CaseInsensitive) == 0) { #else - if (QtPrivate::compareStrings(remove, QStringViewLiteral("all"), Qt::CaseInsensitive) == 0) { + if (QtPrivate::compareStrings(remove, u"all", Qt::CaseInsensitive) == 0) { #endif mod.removal = TypeSystem::All; return true; } #ifdef QTBUG_69389_FIXED - if (remove.compare(QStringViewLiteral("target"), Qt::CaseInsensitive) == 0) { + if (remove.compare(u"target", Qt::CaseInsensitive) == 0) { #else - if (QtPrivate::compareStrings(remove, QStringViewLiteral("target"), Qt::CaseInsensitive) == 0) { + if (QtPrivate::compareStrings(remove, u"target", Qt::CaseInsensitive) == 0) { #endif mod.removal = TypeSystem::TargetLangAndNativeCode; return true; @@ -1044,7 +1044,7 @@ void TypeSystemParser::applyCommonAttributes(TypeEntry *type, QXmlStreamAttribut { type->setCodeGeneration(m_generate); const int revisionIndex = - indexOfAttribute(*attributes, QStringViewLiteral("revision")); + indexOfAttribute(*attributes, u"revision"); if (revisionIndex != -1) type->setRevision(attributes->takeAt(revisionIndex).value().toInt()); } @@ -1084,7 +1084,7 @@ FlagsTypeEntry * m_database->addType(ftype); const int revisionIndex = - indexOfAttribute(*attributes, QStringViewLiteral("flags-revision")); + indexOfAttribute(*attributes, u"flags-revision"); ftype->setRevision(revisionIndex != -1 ? attributes->takeAt(revisionIndex).value().toInt() : enumEntry->revision()); @@ -1181,7 +1181,7 @@ ContainerTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - const int typeIndex = indexOfAttribute(*attributes, QStringViewLiteral("type")); + const int typeIndex = indexOfAttribute(*attributes, u"type"); if (typeIndex == -1) { m_error = QLatin1String("no 'type' attribute specified"); return nullptr; @@ -1323,7 +1323,7 @@ ValueTypeEntry * auto *typeEntry = new ValueTypeEntry(name, since); applyCommonAttributes(typeEntry, attributes); const int defaultCtIndex = - indexOfAttribute(*attributes, QStringViewLiteral("default-constructor")); + indexOfAttribute(*attributes, u"default-constructor"); if (defaultCtIndex != -1) typeEntry->setDefaultConstructor(attributes->takeAt(defaultCtIndex).value().toString()); return typeEntry; @@ -1887,7 +1887,7 @@ bool TypeSystemParser::parseNoNullPointer(const QXmlStreamReader &reader, lastArgMod.noNullPointers = true; const int defaultValueIndex = - indexOfAttribute(*attributes, QStringViewLiteral("default-value")); + indexOfAttribute(*attributes, u"default-value"); if (defaultValueIndex != -1) { const QXmlStreamAttribute attribute = attributes->takeAt(defaultValueIndex); qCWarning(lcShiboken, "%s", @@ -2266,7 +2266,7 @@ bool TypeSystemParser::parseReplaceDefaultExpression(const QXmlStreamReader &, m_error = QLatin1String("Replace default expression only allowed as child of argument modification"); return false; } - const int withIndex = indexOfAttribute(*attributes, QStringViewLiteral("with")); + const int withIndex = indexOfAttribute(*attributes, u"with"); if (withIndex == -1 || attributes->at(withIndex).value().isEmpty()) { m_error = QLatin1String("Default expression replaced with empty string. Use remove-default-expression instead."); return false; diff --git a/sources/shiboken2/doc/typesystemvariables.rst b/sources/shiboken2/doc/typesystemvariables.rst index b1b9bbfe6..73d4dd12c 100644 --- a/sources/shiboken2/doc/typesystemvariables.rst +++ b/sources/shiboken2/doc/typesystemvariables.rst @@ -150,6 +150,8 @@ Variables since it otherwise would be indistinguishable from the pointer assignment above. + It is possible to use "auto" as type. + .. _converttopython: **%CONVERTTOPYTHON[CPPTYPE]** diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index b86a5eb46..5a4aa8eba 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -5362,7 +5362,7 @@ void CppGenerator::writeGetattroFunction(QTextStream &s, GeneratorContext &conte s << INDENT << "PyTypeObject *tp = Py_TYPE(self);" << endl; s << INDENT << "PyErr_Format(PyExc_AttributeError," << endl; s << INDENT << " \"'%.50s' object has no attribute '%.400s'\"," << endl; - s << INDENT << " tp->tp_name, PyBytes_AS_STRING(name));" << endl; + s << INDENT << " tp->tp_name, Shiboken::String::toCString(name));" << endl; s << INDENT << "return nullptr;" << endl; } s << INDENT << "} else {" << endl; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index e41c91716..34e43a4c7 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2047,7 +2047,7 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa QString varName = list.at(1).trimmed(); if (!varType.isEmpty()) { const QString conversionSignature = conversionType->cppSignature(); - if (varType != conversionSignature) + if (varType != QLatin1String("auto") && varType != conversionSignature) qFatal("%s", qPrintable(msgConversionTypesDiffer(varType, conversionSignature))); c << getFullTypeName(conversionType) << ' ' << varName; writeMinimalConstructorExpression(c, conversionType); diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 7eaf35e1c..07ef366ba 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -188,8 +188,12 @@ _get_class_of_descr(PyObject *ob) } static PyObject * -GetClassOfFunc(PyObject *ob) +GetClassOrModOf(PyObject *ob) { + /* + * Return the type or module of a function or type. + * The purpose is finally to use the name of the object. + */ if (PyType_Check(ob)) { // PySide-928: The type case must do refcounting like the others as well. Py_INCREF(ob); @@ -203,7 +207,7 @@ GetClassOfFunc(PyObject *ob) return _get_class_of_descr(ob); if (Py_TYPE(ob) == &PyWrapperDescr_Type) return _get_class_of_descr(ob); - Py_FatalError("unexpected type in GetClassOfFunc"); + Py_FatalError("unexpected type in GetClassOrModOf"); return nullptr; } @@ -228,7 +232,7 @@ compute_name_key(PyObject *ob) if (PyType_Check(ob)) return GetTypeKey(ob); Shiboken::AutoDecRef func_name(get_funcname(ob)); - Shiboken::AutoDecRef type_key(GetTypeKey(GetClassOfFunc(ob))); + Shiboken::AutoDecRef type_key(GetTypeKey(GetClassOrModOf(ob))); return Py_BuildValue("(OO)", type_key.object(), func_name.object()); } @@ -268,7 +272,7 @@ name_key_to_func(PyObject *ob) PyObject *ret = PyDict_GetItem(pyside_globals->map_dict, name_key); if (ret == nullptr) { // do a lazy initialization - Shiboken::AutoDecRef type_key(GetTypeKey(GetClassOfFunc(ob))); + Shiboken::AutoDecRef type_key(GetTypeKey(GetClassOrModOf(ob))); PyObject *type = PyDict_GetItem(pyside_globals->map_dict, type_key); if (type == nullptr) @@ -365,7 +369,7 @@ GetSignature_Function(PyObject *obfunc, const char *modifier) // make sure that we look into PyCFunction, only... if (Py_TYPE(obfunc) == PepFunction_TypePtr) Py_RETURN_NONE; - Shiboken::AutoDecRef obtype_mod(GetClassOfFunc(obfunc)); + Shiboken::AutoDecRef obtype_mod(GetClassOrModOf(obfunc)); Shiboken::AutoDecRef type_key(GetTypeKey(obtype_mod)); if (type_key.isNull()) Py_RETURN_NONE; @@ -682,10 +686,16 @@ handle_doc(PyObject *ob, PyObject *old_descr) { init_module_1(); init_module_2(); - Shiboken::AutoDecRef ob_type(GetClassOfFunc(ob)); - auto *type = reinterpret_cast<PyTypeObject *>(ob_type.object()); - if (handle_doc_in_progress || strncmp(type->tp_name, "PySide2.", 8) != 0) - return PyObject_CallMethod(old_descr, const_cast<char *>("__get__"), const_cast<char *>("(O)"), ob); + Shiboken::AutoDecRef ob_type_mod(GetClassOrModOf(ob)); + const char *name; + if (PyModule_Check(ob_type_mod)) + name = PyModule_GetName(ob_type_mod); + else + name = reinterpret_cast<PyTypeObject *>(ob_type_mod.object())->tp_name; + if (handle_doc_in_progress || name == nullptr + || strncmp(name, "PySide2.", 8) != 0) + return PyObject_CallMethod(old_descr, const_cast<char *>("__get__"), + const_cast<char *>("(O)"), ob); handle_doc_in_progress++; PyObject *res = PyObject_CallFunction( pyside_globals->make_helptext_func, @@ -728,7 +738,9 @@ static int pyside_set___signature__(PyObject *op, PyObject *value) { // By this additional check, this function refuses write access. - if (get_signature_intern(op, nullptr)) { + // We consider both nullptr and Py_None as not been written. + Shiboken::AutoDecRef has_val(get_signature_intern(op, nullptr)); + if (!(has_val.isNull() || has_val == Py_None)) { PyErr_Format(PyExc_AttributeError, "Attribute '__signature__' of '%.50s' object is not writable", Py_TYPE(op)->tp_name); diff --git a/sources/shiboken2/tests/samplebinding/objecttype_test.py b/sources/shiboken2/tests/samplebinding/objecttype_test.py index bda14c69c..f1a06c2b1 100644 --- a/sources/shiboken2/tests/samplebinding/objecttype_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttype_test.py @@ -118,5 +118,13 @@ class ObjectTypeTest(unittest.TestCase): self.assertLess(abs(before - after), 5) + def testInvalidProperty(self): + o = ObjectType() + try: + o.typo + self.assertFail() + except AttributeError as error: + self.assertEqual(error.args[0], "'sample.ObjectType' object has no attribute 'typo'") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py index e07856e61..e1883c7cc 100644 --- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py @@ -175,5 +175,17 @@ class SmartPointerTests(unittest.TestCase): self.assertEqual(len(ptrToObjList), 0) self.assertEqual(objCount(), 1) + def testInvalidParameter(self): + # Create Obj. + o = Obj() + # Create a shared pointer to an Obj together with an Obj. + ptrToObj = o.giveSharedPtrToObj() + try: + ptrToObj.typo + self.assertFail() + except AttributeError as error: + self.assertEqual(error.args[0], "'smart.SharedPtr_Obj' object has no attribute 'typo'") + + if __name__ == '__main__': unittest.main() |