aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/libpyside/dynamicqmetaobject.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Rename PySide2 to PySide6Friedemann Kleint2020-11-021-588/+0
| | | | | | | | Adapt CMake files, build scripts, tests and examples. Task-number: PYSIDE-904 Change-Id: I845f7b006e9ad274fed5444ec4c1f9dbe176ff88 Reviewed-by: Christian Tismer <tismer@stackless.com>
* remove traces of Python2 from C codeChristian Tismer2020-10-271-1/+1
| | | | | | | | | | | | It will be assumed that Python is always Python 3. All checks for Python 2 are removed. This is the second part of cleaning up the C code from references to Python 2. Task-number: PYSIDE-904 Change-Id: I3006412c2a5bb65402101b0aac5a5f2fc79ce2f8 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Add compatibility with NuitkaChristian Tismer2020-09-041-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This patch is based upon the old PYSIDE-198 proposal. It worked with a few changes on Python 3 with limited API disabled. When enabling the Limited API, there were a lot of crashes. This was due to the way we need to get around access to certain implementations. This showed that the original patch was wrong in the expression of bindingmanager.cpp bool isCompiled = !isMethod && Py_TYPE(method)->tp_call != nullptr; After fixing this expression with bool isCompiled = !isMethod && Py_TYPE(method) != &PyCFunction_Type && Py_TYPE(method)->tp_call != nullptr; everything worked fine with the Limited API, too. Fixes: PYSIDE-198 Task-number: PYSIDE-829 Change-Id: I4f887c639628041682052e90ba4c72aa98284e9e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Implement the QEnum/QFlag decorator, V2Christian Tismer2020-06-151-6/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implementation allows module-level and scoped QEnums which are Python enum types. Scoped types are registered in Qt's meta object system. Usage of QEnum/QFlag with decorator or function call: from enum import Enum, Flag, auto from PySide2.QtCore import QEnum, QFlag, QObject class Compass(QObject): @QEnum class Orientation(Enum): North, East, South, West = range(4) class Color(Flag): RED = auto() BLUE = auto() GREEN = auto() WHITE = RED | BLUE | GREEN QFlag(Color) Fixes: PYSIDE-957 Change-Id: Ie15f45cbd932c816b50724a96eee0c14ae1fdee8 Task-number: PYSIDE-487 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Fix alloc-dealloc-mismatch in MetaObjectBuilderMilian Wolff2020-04-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QMetaObjectBuilder::toMetaObject uses malloc to allocate the space for the returned QMetaObject. As such, we need to use free instead of delete, otherwise ASAN will report an error: ``` 39: ==1537629==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x61200006cf40 39: #0 0x7f7952f00960 in operator delete(void*) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cc:165 39: #1 0x7f7930c4d8d4 in void qDeleteAll<__gnu_cxx::__normal_iterator<QMetaObject const* const*, std::vector<QMetaObject const*, std::allocator<QMetaObject const*> > > >(__gnu_cxx::__normal_iterator<QMetaObject const* const*, std::vector<QMetaObject const*, std::allocator<QMetaObject const*> > >, __gnu_cxx::__normal_iterator<QMetaObject const* const*, std::vector<QMetaObject const*, std::allocator<QMetaObject const*> > >) /usr/include/qt/QtCore/qalgorithms.h:320 39: #2 0x7f7930c4cf98 in void qDeleteAll<std::vector<QMetaObject const*, std::allocator<QMetaObject const*> > >(std::vector<QMetaObject const*, std::allocator<QMetaObject const*> > const&) /usr/include/qt/QtCore/qalgorithms.h:328 39: #3 0x7f7930c4a847 in PySide::MetaObjectBuilder::~MetaObjectBuilder() ../3rdParty/PySide2/sources/pyside2/libpyside/dynamicqmetaobject.cpp:143 39: #4 0x7f7930c54c8f in PySide::GlobalReceiverV2::~GlobalReceiverV2() ../3rdParty/PySide2/sources/pyside2/libpyside/globalreceiverv2.cpp:208 39: #5 0x7f7930c54ccf in PySide::GlobalReceiverV2::~GlobalReceiverV2() ../3rdParty/PySide2/sources/pyside2/libpyside/globalreceiverv2.cpp:223 39: #6 0x7f7930c54f63 in PySide::GlobalReceiverV2::decRef(QObject const*) ../3rdParty/PySide2/sources/pyside2/libpyside/globalreceiverv2.cpp:271 39: #7 0x7f7930c553fc in PySide::GlobalReceiverV2::qt_metacall(QMetaObject::Call, int, void**) ../3rdParty/PySide2/sources/pyside2/libpyside/globalreceiverv2.cpp:338 39: #8 0x7f7941d2e251 (/usr/lib/libQt5Core.so.5+0x2db251) 39: #9 0x7f7941d28bef in QObject::destroyed(QObject*) (/usr/lib/libQt5Core.so.5+0x2d5bef) 39: #10 0x7f7941d2c8d6 in QObject::~QObject() (/usr/lib/libQt5Core.so.5+0x2d98d6) 39: 39: 0x61200006cf40 is located 0 bytes inside of 264-byte region [0x61200006cf40,0x61200006d048) 39: allocated by thread T0 here: 39: #0 0x7f7952efdd48 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:153 39: #1 0x7f7941d1d742 in QMetaObjectBuilder::toMetaObject() const (/usr/lib/libQt5Core.so.5+0x2ca742) 39: #2 0x7f7930c4bb88 in PySide::MetaObjectBuilder::update() ../3rdParty/PySide2/sources/pyside2/libpyside/dynamicqmetaobject.cpp:425 39: #3 0x7f7930c54a85 in PySide::GlobalReceiverV2::GlobalReceiverV2(_object*, QSharedPointer<QMap<QByteArray, PySide::GlobalReceiverV2*> >) ../3rdParty/PySide2/sources/pyside2/libpyside/globalreceiverv2.cpp:195 39: #4 0x7f7930c50a70 in PySide::SignalManager::globalReceiver(QObject*, _object*) ../3rdParty/PySide2/sources/pyside2/libpyside/signalmanager.cpp:313 39: #5 0x7f792ec3b257 in getReceiver 3rdParty/PySide2/sources/pyside2/PySide2/QtCore/PySide2/QtCore/qobject_wrapper.cpp:155 39: #6 0x7f792ec3b67f in qobjectConnectCallback 3rdParty/PySide2/sources/pyside2/PySide2/QtCore/PySide2/QtCore/qobject_wrapper.cpp:205 39: #7 0x7f792ec3e5b9 in Sbk_QObjectFunc_connect 3rdParty/PySide2/sources/pyside2/PySide2/QtCore/PySide2/QtCore/qobject_wrapper.cpp:944 39: #8 0x7f7943a66250 in PyObject_Call (/usr/lib/libpython3.8.so.1.0+0x13c250) ``` Change-Id: I8c5a745fab9785425c0844129731c7c8a17b8d21 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Avoid the GIL in SignalManager::retrieveMetaObjectChristian Tismer2020-03-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After massive GIL savings in the generated code, there still exists a place where a lot of repeated GIL acquirements are done. It was observed that up to 24 consecutive calls to retrieveMetaObject(self) were made, all with the same value for 'self'. The code in question was: (1) Shiboken::GilState gil; (2) MetaObjectBuilder *builder = metaBuilderFromDict( \ reinterpret_cast<SbkObject *>(self)->ob_dict); (3) if (!builder) (4) builder = &(retrieveTypeUserData(self)->mo); (5) (6) return builder->update(); An exact analysis of the code showed that the GIL usage (1) could be moved out of the function into a deeper function that does updates in a branch (6). Function retrieveTypeUserData does not involve the Python interpreter at all (4). It took some time until it was proven that access to some special Python dictionary cannot reach the Python interpreter and therefore does not need the GIL as well (2). This replaces the abandoned effort to write a "Lazy GIL". It worked great for the example program, but had problems with some never finishing tests. After all, this solution is much simpler and works perfectly well. More effort seems not to be necessary to handle the GIL. Task-number: PYSIDE-803 Change-Id: I439009ff933fc6f498beb0c7f1523b6f985afda8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* libpyside: Set default signal name only if previously assignedCristián Maureira-Fredes2020-01-271-1/+2
| | | | | | | | | | Just before registering the signal to the meta-object, the signalName was overwritten instead of checking if it had some content. Fixes: PYSIDE-1192 Change-Id: I5fc85bf22ae08bce6969b9381662288a99aee616 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Add support for parameterNames in SignalsCristian Maureira-Fredes2019-07-041-2/+11
| | | | | | | | | | | | | | | | | | | | | | There were many uses cases when a proper interaction between Python and Qml was needed, one of them was the case to emit signals from Python an get those values via an argument name in QML. A simple example describing this situation can be found in PYSIDE-634: Python: sumResult = Signal(int, arguments=["sum"]) sumResult.emit(42) Qml: onSumResult: console.log(sum) // will print 42 A test case based on the same example was added. Change-Id: I0908f97d88eaadc0c02d81bc4daca936f72f6c6a Fixes: PYSIDE-634 Reviewed-by: Christian Tismer <tismer@stackless.com>
* Port property/signal/slot handling of libpyside to use QByteArrayFriedemann Kleint2019-05-061-10/+3
| | | | | | | | | | Introduce C++ structs with QByteArray to be used for signal and slot names and signatures, removing a lot of code dealing with char * pointers, strdup() and reallocating. Change-Id: I28acf727bc6cf468285b153c85b0a342fd79f7d8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
* Propagate Property attributes to the MetaObjectCristian Maureira-Fredes2019-02-071-0/+11
| | | | | | | | | | | | | | | The attributes were ignored when a new Property was being add to the MetaObject. The addProperty method was only creating a new QProperty with the name and default values. The way of setting the attributes comes from: src/corelib/kernel/qmetaobjectbuilder.cpp specifically QMetaObjectBuilder::addProperty. Change-Id: Id81a274b3c2ae9d6b3413ebd54c776cefa392a38 Fixes: PYSIDE-924 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* libpyside: Refactor MetaObjectBuilderPrivate::parsePythonType()Friedemann Kleint2018-11-291-33/+26
| | | | | | | | | | | | | | - Use std::vector to collect the base types. Append the type first to avoid reshuffling when prepending. - Add properties immediately instead of storing in the 2nd loop as signals are already added. - Clang tidy: Use range based for, auto, nullptr Task-number: PYSIDE-784 Change-Id: I765beb2d09600e78abd314cbb394cd106ec22f03 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* libpyside: Port DynamicQMetaObject to QMetaObjectBuilderFriedemann Kleint2018-10-221-632/+276
| | | | | | | | | | | | | | | | | | | | Qt 5 introduces a new class QMetaObjectBuilder for generating dynamic meta objects for use cases like QML. It provides an API to add methods, properties and info and a factory method toMetaObject() to obtain a QMetaObject snapshot reflecting the changes. Replace the DynamicQMetaObject aggregated by TypeUserData by a class MetaObjectBuilder wrapping a QMetaObjectBuilder with dirty-handling. The code to create the binary data of the QMetaObject can then be removed. For plain Qt objects, the wrapped base meta object will be returned (which fixes the bug). Task-number: PYSIDE-784 Change-Id: Id8a54570aff36c75fe0f3bf2d297a12d02cd773a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* libpyside: Replace foreach by range-based forFriedemann Kleint2018-10-021-1/+1
| | | | | Change-Id: I577ca66e0bd92cfedd060b46f4946963eb91f991 Reviewed-by: Christian Tismer <tismer@stackless.com>
* libpyside: Clean up #include directivesFriedemann Kleint2018-10-021-8/+6
| | | | | | | | | | Remove unused #include directives, group by libpyside, libshiboken, Qt, C++ and sort alphabetically with the exception of sbkpython.h which sanitizes the "slot" defines and needs to go to the top when used). Add the module to the Qt classes. Change-Id: I33d912135bad928d3073a1ddeb487de237d6a45e Reviewed-by: Christian Tismer <tismer@stackless.com>
* libpyside: Replace QLinkedList<QByteArray> by QByteArrayList in MetaObjectFriedemann Kleint2018-09-041-44/+27
| | | | | | | | Remove unused list parameter from DynamicQMetaObject::createMetaData(), adapt signatures, make const where applicable and streamline code. Change-Id: I0733382b2a6a35579d3e69280d674ad8a8f1bbc6 Reviewed-by: Christian Tismer <tismer@stackless.com>
* libpyside: Fix clang-tidy warnings about class definitionsFriedemann Kleint2018-08-311-10/+7
| | | | | | | | | | | | | | - Add override - Use = default for trivial constructors/destructors - Add Q_DISABLE_COPY where applicable - Use member initialization and remove constructors from simple structs - Use explicit where applicable (which requires adapting code snippets constructing a QVariant from PyObjectWrapper) - Fix some parameter to take a const ref or pass by value and use std::move in constructors Change-Id: I5e0d2c4ef92d20397a7daba2f8a64b507e678510 Reviewed-by: Christian Tismer <tismer@stackless.com>
* libpyside: Fix remaining clang-tidy warningsFriedemann Kleint2018-08-301-9/+7
| | | | | | | | | | | - Remove else after return/continue/break; unindent code or simplify return conditions - Use isEmpty() to check for empty containers - Fix C-style casts - Pass std::size_t by value instead of const ref Change-Id: Ic997d7c39720c1cd3698c4d750e9cfc1f1654788 Reviewed-by: Christian Tismer <tismer@stackless.com>
* Pep 384 Final Cut: Remove PepTypeChristian Tismer2018-07-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | While trying to document the Limited API Project, it suddenly struck me: We can make the patch much much simpler and implement it without the necessity to have an extra PepType! Now I am happy to continue the documentation, because it is now no more improvable. This version will last as long as the layout of PyTypeObject does not change substantially. When that happens, then we need to rewrite stuff with the according PyType_GetSlot() access functions. These access functions will until then be complete enough so that we can live without the tricks like inventing a reduced PyTypeObject as was done in the current implementation. Task-number: PYSIDE-560 Change-Id: I49849cc377baa6794a5b53292691e21d6e2853ab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* PEP 384-squash: Implement PEP 384Christian Tismer2018-05-301-5/+5
| | | | | | | | | | This is the condensed checkin of 18 commits which created the implementation of PEP 384. Task-number: PYSIDE-560 Change-Id: I834c659af4c2b55b268f8e8dc4cfa53f02502409 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Change license from all the filesCristian Maureira-Fredes2018-05-031-1/+1
| | | | | | | | | | | | | | | | | Removing the word 'project' from all the headers, and changing the PySide reference from the examples to Qt for Python: The following line was used inside the source/ and build_scripts/ directory: for i in $(grep -r "the Qt for Python project" * |grep -v "pyside2-tools" | awk '{print $1}' | sed 's/:.*//g');do sed -i 's/the\ Qt\ for\ Python\ project/Qt\ for\ Python/g' $i;done and the following line was used inside the examples/ directory: for i in $(grep -r "of the PySide" * |grep -v "pyside2-tools" | awk '{print $1}' | sed 's/:.*//g');do sed -i 's/of\ the\ PySide/of\ the\ Qt\ for\ Python/g' $i;done Change-Id: Ic480714686ad62ac4d81c670f87f1c2033d4ffa1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Rename PySide references to Qt for PythonCristian Maureira-Fredes2018-04-271-1/+1
| | | | | | | | | When referring to the project one should use "Qt for Python" and for the module "PySide2" Change-Id: I36497df245c9f6dd60d6e160e2fc805e48cefcae Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* move everying into sources/pyside2 (5.9 edition)Oswald Buddenhagen2017-05-221-0/+901
in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it.