aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/feature_select.cpp
Commit message (Collapse)AuthorAgeFilesLines
* limited api: Remove PyTuple_GET_ITEM, PyTuple_SET_ITEM, and PyTuple_GET_SIZE ↵Cristián Maureira-Fredes2024-11-081-4/+4
| | | | | | | | | | | macros Removing old macros for compatibility with the limited api, and refactoring some of their usages Change-Id: I33954199d2ef9884c64b963863b97aed851c440f Pick-to: 6.8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* libpyside: Fix static analysis warningsFriedemann Kleint2024-06-241-11/+12
| | | | | | | | | | | | | | | | - Initialize variables - Use auto * - Remove repeated return types - Fix else after return - Fix some invocations of static methods - Make functions const/static where appropriate - Fix some int types to avoid lossy conversions - Use Py_RETURN_NONE where appropriate - Minor cleanups - Remove some macros Change-Id: I7fa7a29e7b3dc47037027978001824e0709d001f Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* Feature: Prepare feature and signature modules to stand lazy initChristian Tismer2024-03-051-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | When lazy initialization is used, unexpected situations are coming up. The feature switching may call into signature init without knowledge that feature dicts are already switched. Fix this by - disabling feature switching during lazy init of a class - allow this disabling from PySide and Shiboken - Create a way to find the unchanged type dict of features UPDATE: Switching speed is now as high as before. This check-in was extracted after the fact, although it claims to exist beforehand which would have been better. This was quite a painful experience. Change-Id: I6639b7a3c22d21d3b9dd0627e2880a7b7a03d134 Task-number: PYSIDE-1019 Task-number: PYSIDE-2404 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* shiboken: Get rid of tp_dict in generalChristian Tismer2023-10-091-17/+23
| | | | | | | | | | | | | | It is a long due task to finally remove the direct access to type object fields. With Python 3.12, direct access to tp_dict became problematic. We use that as a reason to start removing the direct access in favor of function calls. Task-number: PYSIDE-2230 Change-Id: I6f8a7479ab0afdbef14d4661f66c3588f3a578aa Pick-to: 6.2 6.5 6.6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Support running PySide on Python 3.12Christian Tismer2023-10-091-4/+6
| | | | | | | | | | | | | | | | | | Builtin types no longer have tp_dict set. We need to use PyType_GetDict, instead. This works without Limited API at the moment. With some great cheating, this works with Limited API, too. We emulate PyType_GetDict by tp_dict if that is not 0. Otherwise we create an empty dict. Some small changes to Exception handling and longer warm-up in leaking tests were found, too. Pick-to: 6.6 6.5 6.2 Task-number: PYSIDE-2230 Change-Id: I8a56de6208ec00979255b39b5784dfc9b4b92def Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Replace typedef by usingFriedemann Kleint2023-09-201-3/+3
| | | | | | | Pick-to: 6.6 6.5 Change-Id: I23d8ea03ec578a897352c2627417a706ca71ef82 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* libshiboken/libpyside: Fix some static analysis warningsFriedemann Kleint2023-09-201-2/+2
| | | | | | | | | | | | - nullptr - narrowing integer conversions - else after return - Use auto - Missing move special functions Pick-to: 6.6 6.5 Change-Id: Ib872481a46c8bb17592cdc1778ab3c4d9598c753 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* Fix namespacesFriedemann Kleint2023-09-201-3/+2
| | | | | | | | | | | - Use nested namespaces instead repetitive namespace declaration - Remove anonymous namespaces that contain only static functions. "static" is sufficient here, the anonymous namespace only increases compilation time. Pick-to: 6.6 6.5 Change-Id: I6cd1b63da79eaf40a1b7ae031def97fa22903e99 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* libpyside: Rename the static stringsFriedemann Kleint2022-12-161-4/+4
| | | | | | | | | | | | Shiboken::Py(Magic)Name needs to be disambiguated from PySide::Py(Magic)Name as otherwise using namespace Shiboken; using namespace PySide; leads to ambiguities in jumbo builds. Task-number: PYSIDE-2155 Change-Id: I7ffd1c9325f9c9a83be8ef797aebb096cc15f593 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* __feature__: Simplify and make more PyPy compatibleChristian Tismer2022-11-301-60/+72
| | | | | | | | | | | | | | | | | | The fast_id_array does not make sense anymore and can be be replaced by integers. This not only simplifies debugging, but also makes it easier to support switching with PyPy, since PyPy does not guarantee unique numbers < 256. Feature selection can be almost completely offloaded from shiboken. This simplifies even more and can be beneficial when inlining. [ChangeLog][PySide6] The __feature__ switch has been simplified in preparation for eventual PyPy support. Task-number: PYSIDE-2029 Change-Id: I6060b5d81bfcde4fb4a9460e57e290f5690fe11d Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: Add some simple but very effective cachingChristian Tismer2022-11-301-9/+14
| | | | | | | | | | | | | | | | | | | | | | The caching problem has been studied a while and multiple schemes have been considered which are not really cheap, partially since a lot of extra knowledge would need to be recorded. While testing, it turned out that very often the same type gets accessed multiple times, which allows for a very efficient cache without the chance of errors: Simply save multiple selection with the same type and select id. [ChangeLog][PySide6] A new efficient optimization was implemented for __feature__ switching. Task-number: PYSIDE-2029 Change-Id: I76d4dc81f7a038ff47af13f0a77981844764f3a1 Pick-to: 6.4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: Remove the no longer efficient reserved_bits structureChristian Tismer2022-11-291-15/+0
| | | | | | | | | | | | | | | The reserved_bits structure is no longer an optimization after moving to PyPy. Accessing any extra field involves always a dict lookup. - remove the reserved_bits field - re-order SbkObjectTypePrivate - replace access functions by currentSelectId() Task-number: PSYIDE-2029 Change-Id: I08642eace9a6399649c039bcc358ce678bbd4fd3 Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: heavily rework the context switchingChristian Tismer2022-11-291-32/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The example of the issue shows the qasync.py module which fails miserably when using snake_case. The reason: ----------- Reason is the way how feature switching is implemented. Modules like qasync get a default switching of "ignore". This ignores that the qasync module itself imports QtCore, and feature switching is of course relevant, suggesting a default setting of "normal" (explicitly no features). The real problem: ----------------- Testing the simple approach showed a serious problem with feature switching: The functions get switched when a certain function (getattr etc.) is called. But the switching is sometimes not done due to a caching problem. This fix removes caching that was wrong. Optimization will be done in a different step with a different approach. This Change was not qasync specific, but happens with PySide imports. Actions done: - adjust the inline structure - implement a feature_imported callback - identify Python functions that use PySide during import [ChangeLog][PySide6] __feature__ switching now works even with recursive imports like in the qasync module. Fixes: PYSIDE-2029 Change-Id: I3340f54f293083a09fb509383688f73bbd9b60ae Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: Cleanup before reworking the context switchingChristian Tismer2022-11-291-10/+11
| | | | | | | | | | | | | Some small changes: - Reserved bits are now signed - old comments were no more true - SelectFeatureSet simplified Task-number: PYSIDE-2029 Change-Id: Id8d83de4278bd4e618f5c601f9fa3c25ac172d53 Pick-to: 6.4 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: Fix true_property inheritanceChristian Tismer2022-11-231-4/+26
| | | | | | | | | | | | | | | | | | The wrapping process creates wrapper functions for all C functions, also for those which are meant as virtual functions promoting an inherited function. Because properties appear as such additional functions, we need to convert not only according to the property strings, but also use the mro to reach the extra functions indirectly. [ChangeLog][PySide6] true_property was fixed to work with inherited properties as well. Change-Id: I176a30df77f550504f3aaf71e0c20de3e0707792 Fixes: PYSIDE-2042 Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* __feature__: Cleanup and optimize before changing true_propertyChristian Tismer2022-11-231-13/+13
| | | | | | | | | | Casing and naming was adjusted, minor correction, replaced QString(List)? with QByteArray(List)?. Change-Id: I0dae86fbd8dd27d5460ecb7f44f81134c69acb5d Pick-to: 6.4 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Fix warnings about unused parameters in codeFriedemann Kleint2022-09-261-2/+2
| | | | | | Pick-to: 6.3 6.2 Change-Id: Ie120284b290d22f2786591955465e0334555e658 Reviewed-by: Christian Tismer <tismer@stackless.com>
* Use SPDX license identifiersLucie Gérard2022-05-271-38/+2
| | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: I065150015bdb84a3096b5b39c061cf0a20ab637d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Migrate from QLatin1Char to UTF-16 char literalsFriedemann Kleint2022-04-251-1/+1
| | | | | | | | | Preparing for the deprecation of QLatin1Char in 6.4. Task-number: QTBUG-98434 Pick-to: 6.3 6.2 Change-Id: I8bc92aa9f4e6dbfcb12d2025c5a1e760ab4f0d7f Reviewed-by: Christian Tismer <tismer@stackless.com>
* __feature__: Fix snake_case handling on user defined classesChristian Tismer2022-02-101-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | The snake case feature filters candidate methods and turns them into snake case. This works fine for built-in classes. The assumption is that all methods come from the tp_methods list. This assumption is not correct when applied to user defined classes. The methods have no static source in this case. To distinguish here, we inspect the tp_methods list. If it is empty, we assume a user defined class and do nothing. A forgotten initialization in feature.py was added, too. As a note: RHEL has such an old Python version that does not have MethodDescriptorType in the types module. [ChangeLog][PySide6] snake_case handling now does explicitly not touch user defined classes. Fixes: PYSIDE-1702 Pick-to: 6.2 Change-Id: Idfa16cdc50cb7234c1d2f473dfae3a568887547e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* PyPySide: Rename interface functions and classes to simplify debuggingChristian Tismer2022-02-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | The names of certain interface functions are not always following a simple scheme. Especially it is not easy to see immediately if we are dealing with a method of SbkObjectType or SbkObject Do a few renamings to simplify debugging and make the code easier to understand. When a function is used in a type spec and there is no other important reason, it should be named like {Py_<tpname>: reinterpret_cast<void *>(<TypeName>_<tpname>)}, Rename also all type functions ending on "TypeF()" to end in "_TypeF()". This is not always the case. Examples: SbkObjectTpNew -> SbkObject_tp_new SbkObjecttypeTpNew -> SbkObjectType_tp_new PyClassPropertyTypeF -> PyClassProperty_TypeF Task-number: PYSIDE-535 Change-Id: Icbd118852f2ee732b55d944ed57c7a8ef7d26139 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* libpyside: Split up the pyside.h headerFriedemann Kleint2021-11-261-1/+4
| | | | | | | | | | | | | | | | Changing something in pyside.h caused excessive recompiling of all wrappers. Try to amend the situation by splitting up the header and include only what is needed. pyside.h remains as a header including the others which will be emptied out by further changes splitting out QML functionality. [ChangeLog][PySide6] The header pyside.h has been split into smaller headers. Task-number: PYSIDE-1709 Change-Id: I89ff3d9d9bc486f194ad3ec62ed372ff0be960f2 Reviewed-by: Christian Tismer <tismer@stackless.com>
* __feature__: handle properties with function overloadsChristian Tismer2021-10-281-0/+32
| | | | | | | | | | | | | | | | | | | | This is the implementation, see the conclusion of the issue. [ChangeLog][PySide6] When a property would override an existing function with multiple arity or parameters, append an underscore to the property name. REMARK: The current implementation is very correct. It uses introspection via the signature module. But that adds a constant overhead to the true_property feature. Actually, there are only 2 known cases where this overlap happens. It might be considered to simplify things by checking the string names of these two functions? Fixes: PYSIDE-1670 Pick-to: 6.2 Change-Id: I14927995698726957ba8c515dddf5e37c21910ce Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* py3.10-prep: reset the type cache after feature switchingChristian Tismer2021-08-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][PySide6] Feature switching needs to reset the internal type cache. This was an omittion that becomes relevant in Python 3.10 . When using feature switching in Python 3.10, there were funny effects where switched and un-switched versions appeared to co-exist. It turned out that we were hit by function caching that is now implemented for the LOAD_ATTR opcode. It was not known that caching would happen at all for PySide classes because we don't use Py_TPFLAGS_VALID_VERSION_TAG. But actually, this flag is used internally by Python to do some optimizations, and we just have to notify the interpreter of type changes by PyType_Modified(). Task-number: PYSIDE-1436 Change-Id: Ie8a73f62bd6e9b8156b8ea23626fabd44700158b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Shiboken: Remove cheating macrosChristian Tismer2021-08-061-6/+6
| | | | | | | | | | | | | | | There are a number of cheating macros that allow to use the same code in Python 2 and 3. Because Python 2 is gone, remove these macros. This conversion was partially difficult since certain types collapsed in the XML files and generated functions contained substrings of the macros. This is actually the fourth attempt. Task-number: PYSIDE-1019 Pick-to: 6.1 Change-Id: I116877afc8aa36f4710a40df1769f600b6b750ea Reviewed-by: Christian Tismer <tismer@stackless.com>
* feature: move getFeatureSelectId to Shiboken and refactorChristian Tismer2021-08-051-31/+2
| | | | | | | | | | | | | | | | | | | This function caused problems when extending the signature module: For class methods, the signature module must become able to distinguish class methods in properties (true_property) which are static methods without a feature. That means: The signature module must know the full info about feature switching. Moving getFeatureSelectId into Shiboken simplifies matters quite a lot. The main feature switching code remains in PySide. Task-number: PYSIDE-1019 Pick-to: 6.1 Change-Id: I99116eefc0faf24a6eb9a16d79b21a5cc7ae299e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* feature: fix the UIC switching problemChristian Tismer2021-07-281-0/+3
| | | | | | | | | | | | | | | | | | | | | The BindingManager::getOverride function computes the current switch state from information of a type object. But the type object must first be updated in case a switch has happened. The solution was an extra update call at the beginning of the function. This solution _always_ works, with or without inheritance, for Python >= 3.7. [ChangeLog][shiboken6] Coexistence of different feature selections works now, especially for UIC files and inheritance. Fixes: PYSIDE-1626 Pick-to: 6.1 Pick-to: 5.15 Change-Id: I577331cfb2d7511110d1e16e729bed80985340a0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* PySide6/features: Fix compiler warningFriedemann Kleint2021-06-231-0/+2
| | | | | | | | | | | Assign isStdWrite in parseFields(), fixing: libpyside/feature_select.cpp: In function bool PySide::Feature::feature_02_true_property(PyTypeObject*, PyObject*, int): libpyside/feature_select.cpp:689:59: warning: ‘isStdWrite’ may be used uninitialized in this function [-Wmaybe-uninitialized] Pick-to: 6.1 Change-Id: I4527444a67ee3ca6e886802a76aa4508c8ca3a7c Reviewed-by: Christian Tismer <tismer@stackless.com>
* PyClassProperty: Correct the decorator and publish the classChristian Tismer2021-06-101-1/+0
| | | | | | | | | | | | | | PyClassProperty is now correctly published as a QtCore class and existing as an import. As a side effect, a bug was fixed where a syntax error occurred because of a missing signature count. Task-number: PYSIDE-1019 Fixes: PYSIDE-1593 Change-Id: Iae733280d9f9c23244e83a356011104bf527c329 Pick-to: 6.1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* feature: delete setter after creating property only if standardChristian Tismer2021-01-291-5/+9
| | | | | | | | | | | | | | | | | | | | Some features like QWidget.size are defined by Qt with a non-standard setter name. For size, the standard setter name would be setSize, and in the property creation process this setter would be deleted. We changed rules in this way: If a setter name is non-standard (like resize), the setter will not be removed but still can be used. Actually it would make more sense if "size" was a read-only property. Task-number: PYSIDE-1019 Change-Id: I9ded7e9c1dbd2932aa4c5616385b90ed673bfaee Pick-to: 5.15 Pick-to: 6.0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Clean up some warnings produced by Qt Creator's clang/clazy code checkersFriedemann Kleint2021-01-211-3/+2
| | | | | | | | | | - Remove unused variables - Remove assignments that do not have any effect - Fix mixing const/non-const iterators - Fix for loops, use const ref and/or qAsConst() Change-Id: I4b52f11030493c440026b194f18ec0151a3ea710 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* feature: Disable selection while creating a typeChristian Tismer2021-01-061-1/+9
| | | | | | | | | | | | | | | | | | | PySide 6 suddenly has problems with feature switching during subtype initialization. We introduce an enable function that can temporarily suppress switching. This problem is solved so far. It is the question whether this will break again in another constellation. It might be considerable for the future to have something like Python's PyType_Ready function. Right now this is too much effort. Change-Id: If0ed786d4761cf2356f01f7478e4a0d750e88d3c Fixes: PYSIDE-1463 Pick-to: 6.0 Pick-to: 5.15 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Fix warnings about unused functions and variablesFriedemann Kleint2020-11-121-2/+0
| | | | | Change-Id: I7949defbd3f55b0ca231a21b0f9b8747024f8097 Reviewed-by: Christian Tismer <tismer@stackless.com>
* __feature__: provide useful error message when feature is activeChristian Tismer2020-11-111-5/+15
| | | | | | | | | | | | | | | | Features seem to work quite good so far, but they clearly need much more testing. One of the problems is that error messages are produced, but the function name is not found and we get an ugly default error message. This is an efficient implementation that does all name mangling in the C code. A helper dict avoids linear search for properties. Task-number: PYSIDE-1019 Change-Id: Ic87c4a6e7dc2b2a251e809d6df0eb7fb9ca8021c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Rename PySide2 to PySide6Friedemann Kleint2020-11-021-0/+766
Adapt CMake files, build scripts, tests and examples. Task-number: PYSIDE-904 Change-Id: I845f7b006e9ad274fed5444ec4c1f9dbe176ff88 Reviewed-by: Christian Tismer <tismer@stackless.com>