diff options
author | Christian Tismer <tismer@stackless.com> | 2024-01-30 11:59:03 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2024-01-31 09:38:22 +0100 |
commit | 7f69d4d562e1d19efd2c505dceea387a4a87dcfe (patch) | |
tree | 8111a54694f6f170ad2d5d892d0fee8151f9596f | |
parent | ac6c01d3d69af99da4bef66a4e20f07c9c15ffc6 (diff) |
LazyInit: Make imports computable from offset constants
The function cpythonTypeNameExt uses getTypeIndexVariableName
to compute the offset to a class variable.
For LazyInit we want to change this, creating an expression
that can compute the referenced types on demand when no
value is found at the offset. These types are hidden in the offset
expression.
By no longer using "toUpper" here, we can easily compute the
needed imports from the offset constant name.
We will keep both versions until PySide7.
[ChangeLog][PySide6] Type index constants are no longer in uppercase.
Uppercase is retained until deprecation in PySide7.
Task-number: PYSIDE-2404
Change-Id: I422ead0540a7bdcb4c7ac9905c8e6ab71b5b0634
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
5 files changed, 44 insertions, 18 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index 2d3d8e497..11369aaa5 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -389,10 +389,10 @@ PySide::Feature::init(); // @snippet qt-init-feature // @snippet qt-pysideinit -Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QSTRING_IDX], "unicode"); -Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QSTRING_IDX], "str"); -Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QTCORE_QLIST_QVARIANT_IDX], "QVariantList"); -Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QTCORE_QMAP_QSTRING_QVARIANT_IDX], "QVariantMap"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QString_IDX], "unicode"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QString_IDX], "str"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QtCore_QList_QVariant_IDX], "QVariantList"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QtCore_QMap_QString_QVariant_IDX], "QVariantMap"); PySide::registerInternalQtConf(); PySide::init(module); @@ -665,7 +665,7 @@ if (PyIndex_Check(_key)) { PyErr_SetString(PyExc_ValueError, "bytearray must be of size 1"); return -1; } - } else if (Py_TYPE(_value) == reinterpret_cast<PyTypeObject *>(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX])) { + } else if (Py_TYPE(_value) == reinterpret_cast<PyTypeObject *>(SbkPySide6_QtCoreTypes[SBK_QByteArray_IDX])) { if (PyObject_Length(_value) != 1) { PyErr_SetString(PyExc_ValueError, "QByteArray must be of size 1"); return -1; @@ -702,7 +702,7 @@ if (PySlice_GetIndicesEx(_key, %CPPSELF.size(), &start, &stop, &step, &sliceleng Py_ssize_t value_length = 0; if (_value != nullptr && _value != Py_None) { if (!(PyBytes_Check(_value) || PyByteArray_Check(_value) - || Py_TYPE(_value) == reinterpret_cast<PyTypeObject *>(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX]))) { + || Py_TYPE(_value) == reinterpret_cast<PyTypeObject *>(SbkPySide6_QtCoreTypes[SBK_QByteArray_IDX]))) { PyErr_Format(PyExc_TypeError, "bytes, bytearray or QByteArray is required, not %.200s", Py_TYPE(_value)->tp_name); return -1; @@ -1751,7 +1751,7 @@ if (dataChar == nullptr) { // @snippet qloggingcategory_to_cpp QLoggingCategory *category{nullptr}; - Shiboken::Conversions::pythonToCppPointer(SbkPySide6_QtCoreTypes[SBK_QLOGGINGCATEGORY_IDX], + Shiboken::Conversions::pythonToCppPointer(SbkPySide6_QtCoreTypes[SBK_QLoggingCategory_IDX], pyArgs[0], &(category)); // @snippet qloggingcategory_to_cpp diff --git a/sources/pyside6/PySide6/glue/qtwebenginecore.cpp b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp index a569e6c11..01a4ce764 100644 --- a/sources/pyside6/PySide6/glue/qtwebenginecore.cpp +++ b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp @@ -26,7 +26,7 @@ auto callback = [callable](std::unique_ptr<QWebEngineNotification> webEngineNoti Shiboken::AutoDecRef arglist(PyTuple_New(1)); PyTuple_SET_ITEM(arglist.object(), 0, Shiboken::Conversions::pointerToPython( - SbkPySide6_QtWebEngineCoreTypes[SBK_QWEBENGINENOTIFICATION_IDX], + SbkPySide6_QtWebEngineCoreTypes[SBK_QWebEngineNotification_IDX], webEngineNotification.release())); Py_INCREF(callable); PyObject_CallObject(callable, arglist); diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index 08bf58f80..d7fe3bc55 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -115,7 +115,7 @@ void HeaderGenerator::generateClass(TextStream &s, const GeneratorContext &class s << licenseComment(); QString wrapperName = classContext.effectiveClassName(); - QString outerHeaderGuard = getFilteredCppSignatureString(wrapperName).toUpper(); + QString outerHeaderGuard = getFilteredCppSignatureString(wrapperName); // Header s << "#ifndef SBK_" << outerHeaderGuard << "_H\n"; @@ -124,7 +124,7 @@ void HeaderGenerator::generateClass(TextStream &s, const GeneratorContext &class if (!avoidProtectedHack()) s << protectedHackDefine; - //Includes + // Includes s << metaClass->typeEntry()->include() << '\n'; for (auto &inst : metaClass->templateBaseClassInstantiations()) s << inst.typeEntry()->include(); @@ -609,7 +609,7 @@ HeaderGenerator::IndexValues const auto ptrName = smp.type.typeEntry()->entryName(); const auto pos = indexName.indexOf(ptrName, 0, Qt::CaseInsensitive); if (pos >= 0) { - indexName.insert(pos + ptrName.size() + 1, u"CONST"_s); + indexName.insert(pos + ptrName.size() + 1, u"const"_s); result.append({indexName, smartPointerCountIndex, "(const)"_L1}); } ++smartPointerCountIndex; @@ -646,6 +646,18 @@ HeaderGenerator::IndexValues HeaderGenerator::collectConverterIndexes() const return result; } +// PYSIDE-2404: Write the enums in unchanged case for reuse in type imports. +// For conpatibility, we create them in uppercase, too. +// FIXME: Remove in PySide 7. (See the note in `parser.py`) +// +static IndexValue typeIndexUpper(struct IndexValue const &ti) +{ + QString modi = ti.name.toUpper(); + if (modi == ti.name) + modi = u"// "_s + modi; + return {modi, ti.value, ti.comment}; +} + bool HeaderGenerator::finishGeneration() { // Generate the main header for this module. This header should be included @@ -660,7 +672,6 @@ bool HeaderGenerator::finishGeneration() TypeSystem::TargetLangCode); } - macrosStream << "// Type indices\nenum : int {\n"; auto classList = api().classes(); std::sort(classList.begin(), classList.end(), @@ -669,6 +680,13 @@ bool HeaderGenerator::finishGeneration() }); const auto typeIndexes = collectTypeIndexes(classList); + + macrosStream << "\n// Type indices\nenum [[deprecated]] : int {\n"; + for (const auto &ti : typeIndexes) + macrosStream << typeIndexUpper(ti); + macrosStream << "};\n"; + + macrosStream << "\n// Type indices\nenum : int {\n"; for (const auto &ti : typeIndexes) macrosStream << ti; macrosStream << "};\n"; @@ -683,6 +701,11 @@ bool HeaderGenerator::finishGeneration() // TODO-CONVERTER ------------------------------------------------------------------------------ // Using a counter would not do, a fix must be made to APIExtractor's getTypeIndex(). const auto converterIndexes = collectConverterIndexes(); + macrosStream << "// Converter indices\nenum [[deprecated]] : int {\n"; + for (const auto &ci : converterIndexes) + macrosStream << typeIndexUpper(ci); + macrosStream << "};\n\n"; + macrosStream << "// Converter indices\nenum : int {\n"; for (const auto &ci : converterIndexes) macrosStream << ci; @@ -714,7 +737,7 @@ bool HeaderGenerator::finishGeneration() if (!shouldGenerate(classType)) continue; - //Includes + // Includes const bool isPrivate = classType->isPrivate(); auto &par = isPrivate ? privateParameters : parameters; const auto classInclude = classType->include(); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 86c17c81c..17044bc40 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -2441,11 +2441,11 @@ QString ShibokenGenerator::convertersVariableName(const QString &moduleName) static QString processInstantiationsVariableName(const AbstractMetaType &type) { - QString res = u'_' + _fixedCppTypeName(type.typeEntry()->qualifiedCppName()).toUpper(); + QString res = u'_' + _fixedCppTypeName(type.typeEntry()->qualifiedCppName()); for (const auto &instantiation : type.instantiations()) { res += instantiation.isContainer() ? processInstantiationsVariableName(instantiation) - : u'_' + _fixedCppTypeName(instantiation.cppSignature()).toUpper(); + : u'_' + _fixedCppTypeName(instantiation.cppSignature()); } return res; } @@ -2463,7 +2463,7 @@ QString const auto templateBaseClass = metaClass->templateBaseClass(); Q_ASSERT(templateBaseClass); QString result = u"SBK_"_s - + _fixedCppTypeName(templateBaseClass->typeEntry()->qualifiedCppName()).toUpper(); + + _fixedCppTypeName(templateBaseClass->typeEntry()->qualifiedCppName()); for (const auto &instantiation : metaClass->templateBaseClassInstantiations()) result += processInstantiationsVariableName(instantiation); appendIndexSuffix(&result); @@ -2485,7 +2485,7 @@ QString ShibokenGenerator::getTypeIndexVariableName(TypeEntryCPtr type) const int dot = package.lastIndexOf(u'.'); result += QStringView{package}.right(package.size() - (dot + 1)); } - result += _fixedCppTypeName(type->qualifiedCppName()).toUpper(); + result += _fixedCppTypeName(type->qualifiedCppName()); appendIndexSuffix(&result); return result; } @@ -2493,7 +2493,7 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaType &type { QString result = u"SBK"_s; if (type.typeEntry()->isContainer()) - result += u'_' + moduleName().toUpper(); + result += u'_' + moduleName(); result += processInstantiationsVariableName(type); appendIndexSuffix(&result); return result; diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 794b3f122..9b48ab442 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -78,6 +78,9 @@ def _get_flag_enum_option(): # PYSIDE-1735: Emit a warning when we should maybe evict forgiveness mode if ver[:2] >= (7, 0): warnings.warn(f"{q} Please drop Enum forgiveness mode in `mangled_type_getattro` ***") + # PYSIDE-2404: Emit a warning when we should drop uppercase offset constants + if ver[:2] >= (7, 0): + warnings.warn(f"{q} Please drop uppercase type offsets in `copyOffsetEnumStream` ***") # normalize the sys attribute setattr(sys, sysname, flag) os.environ[envname] = str(flag) |