From c3342a72cfe682f9a9731a8fc12e117282e30d42 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sat, 20 Jul 2019 15:49:53 +0200 Subject: shiboken: fix a signature bug in __doc__ handling of global functions The signature module was extended to allow automatic creation of __doc__ attributes by taking str of the signature. This function has to figure out when it should not touch an object that does not come from PySide. The check asked the type that was returned by GetClassOfFunc, but in case of a global function, the module of the function is returned. In order to prevent such mistakes, the function has been renamed to GetClassOrModOf. Change-Id: I055f1f0483674553f9300d642aa516cec607e66c Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Keith Kyzivat --- sources/shiboken2/libshiboken/signature.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'sources') diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index e62f861a2..2f080edad 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -187,8 +187,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); @@ -202,7 +206,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; } @@ -227,7 +231,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()); } @@ -267,7 +271,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) @@ -364,7 +368,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; @@ -674,10 +678,16 @@ handle_doc(PyObject *ob, PyObject *old_descr) { init_module_1(); init_module_2(); - Shiboken::AutoDecRef ob_type(GetClassOfFunc(ob)); - auto *type = reinterpret_cast(ob_type.object()); - if (handle_doc_in_progress || strncmp(type->tp_name, "PySide2.", 8) != 0) - return PyObject_CallMethod(old_descr, const_cast("__get__"), const_cast("(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(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("__get__"), + const_cast("(O)"), ob); handle_doc_in_progress++; PyObject *res = PyObject_CallFunction( pyside_globals->make_helptext_func, -- cgit v1.2.3 From 5f72e0414f024822b5fe072e55f2a15a28332846 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 11 Jul 2019 11:29:38 +0200 Subject: shiboken: Allow for "auto" as target of type for CONVERTTOCPP in injected code Task-number: PYSIDE-1037 Change-Id: Idfc70fe571e4058d0c82db1bd0afea54436fe27c Reviewed-by: Christian Tismer --- sources/pyside2/PySide2/glue/qtcore.cpp | 5 ++--- sources/shiboken2/doc/typesystemvariables.rst | 2 ++ sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'sources') 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(Shiboken::SbkType())->tp_new(Shiboken::SbkType(), emptyTuple, 0); reinterpret_cast(Shiboken::SbkType())->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(%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/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/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); -- cgit v1.2.3 From 68b2245519570314a983baa7cda850ace13f7f81 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 25 Jul 2019 15:30:47 +0200 Subject: correct QtPrintSupport dependency QtPrintSupport was missing the XML entry QtWidgets in typesystem_widgets_common.xml, which resulted in follow-up errors in generate_pyi . With this addition, the following pointer-types patch will create a correct signature def getPageMargins(self, unit: PySide2.QtPrintSupport.QPrinter.Unit) -> typing.Tuple[float, float, float, float]: ... Task-number: PYSIDE-951 Change-Id: I0b87cc31c3b39e727aec0a433687a131f1dc1aa6 Reviewed-by: Friedemann Kleint --- sources/pyside2/PySide2/QtPrintSupport/typesystem_printsupport.xml.in | 1 - .../pyside2/PySide2/QtPrintSupport/typesystem_printsupport_common.xml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'sources') 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 @@ ****************************************************************************/ --> - 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 @@ ****************************************************************************/ --> + -- cgit v1.2.3 From efc7ad5498ff03de8a444a8c1d880f949aaf4d43 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 31 Jul 2019 16:34:28 -0300 Subject: Fix crash when accessing a invalid property in the smart pointer Sbk_*_getattro receives an utf8 string and we need to convert it to ascii string before use it on PyErr_Format. Change-Id: Ie3cf5286c9eb6b01f86347b00d523837ca41de32 Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 2 +- sources/shiboken2/tests/samplebinding/objecttype_test.py | 8 ++++++++ sources/shiboken2/tests/smartbinding/smart_pointer_test.py | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'sources') diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index e36b6edc3..68bcfe508 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -5387,7 +5387,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/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() -- cgit v1.2.3 From 29ab4674dc90c216ab17c7a8022f529f9a46eef7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 12 Aug 2019 12:15:01 +0200 Subject: shiboken: Replace QStringViewLiteral by u"" Adapt to the deprecation of QStringViewLiteral introduced by qtbase/c58ca4256d881ffed865602fd3da8efb6ebc9d5f. Change-Id: I688fc9b54a4bde83b6fb2a66704ec51bdde6b264 Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/typesystemparser.cpp | 252 ++++++++++----------- 1 file changed, 126 insertions(+), 126 deletions(-) (limited to 'sources') 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; -- cgit v1.2.3 From 95d71006c3218dde732a6c231ade29460b13a0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Wed, 14 Aug 2019 15:19:41 +0200 Subject: Documentation: update QInputDialog snippets Adapting the code, since we return a tuple (retval, ok) instead of the Qt/C++ approach of having the boolean ok as a parameter. Task-number: PYSIDE-1059 Change-Id: Ied9f99048b95c034850111135ba47ff3aad34917 Reviewed-by: Friedemann Kleint --- .../examples/dialogs/standarddialogs/dialog.cpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'sources') 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] -- cgit v1.2.3 From c6f6b4ef3318ab55b53384856b948d428a24f313 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Mon, 12 Aug 2019 18:12:20 +0200 Subject: Make signatures even more writable When implementing QtCore.Slot.__signature__, the following extension to writable signatures became useful: Signatures were corrected to be writable if they were not set by the signature module at all. But we should also allow assignment when the signature was set to None. This feature is only used for exploration; the correct way to implement a new signature is to integrate it into the normal generation process, as being done for QtCore.Slot.__signature__. Change-Id: I010e505a376993f27c46bd1c14e327e44d375abd Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/signature.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sources') diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 2f080edad..2cade65e0 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -730,7 +730,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); -- cgit v1.2.3 From 51325167e374d44520a723e586058b4a7d7feeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simo=20F=C3=A4lt?= Date: Wed, 14 Aug 2019 14:35:53 +0300 Subject: Bump version to 5.13.1 Change-Id: I88699b3231707d77014b0ee2fb1e8a710484f66e Reviewed-by: Friedemann Kleint --- sources/pyside2/pyside_version.py | 2 +- sources/shiboken2/shiboken_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'sources') diff --git a/sources/pyside2/pyside_version.py b/sources/pyside2/pyside_version.py index d2dd4960d..835f1be4c 100644 --- a/sources/pyside2/pyside_version.py +++ b/sources/pyside2/pyside_version.py @@ -39,7 +39,7 @@ major_version = "5" minor_version = "13" -patch_version = "0" +patch_version = "1" # For example: "a", "b", "rc" # (which means "alpha", "beta", "release candidate"). diff --git a/sources/shiboken2/shiboken_version.py b/sources/shiboken2/shiboken_version.py index d2dd4960d..835f1be4c 100644 --- a/sources/shiboken2/shiboken_version.py +++ b/sources/shiboken2/shiboken_version.py @@ -39,7 +39,7 @@ major_version = "5" minor_version = "13" -patch_version = "0" +patch_version = "1" # For example: "a", "b", "rc" # (which means "alpha", "beta", "release candidate"). -- cgit v1.2.3 From 2fdc5a867ee5e3080166fe383a1fe358abe4cd66 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 15 Aug 2019 08:27:22 +0200 Subject: Update pyside2-tools submodule Task-number: PYSIDE-1035 Change-Id: Ifbd5b2c586901573f466ba0016bc80b0534595df Reviewed-by: Alexandru Croitor --- sources/pyside2-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sources') diff --git a/sources/pyside2-tools b/sources/pyside2-tools index 1d4add192..93c81f131 160000 --- a/sources/pyside2-tools +++ b/sources/pyside2-tools @@ -1 +1 @@ -Subproject commit 1d4add1920c9c1b08ebb20333c15d6f5ed6b9ab5 +Subproject commit 93c81f1315546ba7519bd5b37b160ab012bfaade -- cgit v1.2.3 From a153826d0520b7772d459af80d05d31f9c1a9872 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 15 Aug 2019 10:55:14 +0200 Subject: simplify the qslot_object_test to use the qApp macro The qslot_object_test needed an adjustment, because it uses the name "qApp" without being aware that a qApp builtin variable exists for exactly that purpose. Change-Id: Ic3df95ee33ece5de573b2dcc6ec2d6e2a1ffee73 Reviewed-by: Friedemann Kleint --- sources/pyside2/tests/QtCore/qslot_object_test.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'sources') 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() -- cgit v1.2.3