summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qsharedpointer_impl.h
Commit message (Collapse)AuthorAgeFilesLines
* Make QSharedPointer without custom deleters call the correct destructorThiago Macieira2016-04-281-3/+3
| | | | | | | | | | | | | | | | | Where "correct" is defined by what std::shared_ptr does as well as what happens when an intermediate QSharedPointer of the exact type of the constructor behaves That is, QSharedPointer<X> ptr(new Y); Behaves like QSharedPointer<X> ptr; { QSharedPointer<Y> tmp(new Y); ptr = tmp; } Change-Id: Id75834dab9ed466e94c7ffff14455d445f72592b Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Add support for initializing QSharedPointer from nullptrThiago Macieira2016-04-191-4/+10
| | | | | | | | | | std::shared_ptr supports it. To resolve an ambiguous overload when a literal 0 is passed as a parameter, the normal constructors needed to be made a template, like std::shared_ptr. Task-number: QTBUG-52569 Change-Id: Id75834dab9ed466e94c7ffff14451417892d2148 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-02-181-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also reverts commit 018e670a26ff5a61b949100ae080f5e654e7bee8. The change was introduced in 5.6. After the refactoring, 14960f52, in 5.7 branch and a merge, it is not needed any more. Conflicts: .qmake.conf src/corelib/io/qstandardpaths_mac.mm src/corelib/tools/qsharedpointer_impl.h tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp Change-Id: If4fdff0ebf2b9b5df9f9db93ea0022d5ee3da2a4
| * Fix QT_DEPRECATED_SINCE usageJędrzej Nowacki2016-02-021-1/+1
| | | | | | | | | | | | | | | | The deprecation was introduced in 5.6 Change-Id: Ief6b749b40ec75c3c9f904caed8447bfb5ef5439 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Add Intel copyright to files that Intel has had non-trivial contributionThiago Macieira2016-01-211-0/+1
| | | | | | | | | | | | | | | | | | I wrote a script to help find the files, but I reviewed the contributions manually to be sure I wasn't claiming copyright for search & replace, adding Q_DECL_NOTHROW or adding "We mean it" headers. Change-Id: I7a9e11d7b64a4cc78e24ffff142b506368fc8842 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | | | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.6' into devLiang Qi2015-12-181-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/gui/painting/painting.pri src/plugins/platforms/xcb/qxcbconnection.cpp tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro tests/auto/corelib/tools/qlocale/test/test.pro tests/auto/gui/kernel/qwindow/tst_qwindow.cpp tools/configure/environment.cpp Change-Id: I9c40f458b89b2c206de2d2c24e90b5f679c93495
| * Fix constructing a QSharedPointer<const> of a QEnableSharedFromThis typeThiago Macieira2015-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | It should compile, since the std::shared_ptr does. [ChangeLog][QtCore][QSharedPointer] Fixed a problem that would cause a compilation error when constructing a QSharedPointer of a const type when the type derives from QEnableSharedFromThis. Task-number: QTBUG-49748 Change-Id: I8de47ed6c7be4847b99bffff141c84f5e0b6bea8 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | QWeakPointer: enable move semanticsMarc Mutz2015-10-071-0/+10
| | | | | | | | | | | | | | | | Also add some tests for QSharedPointer move semantics, too. Change-Id: I1bdd1fe140acafabe5bc6bff8af49a053ec1f4d5 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QWeakPointer: mark as nothrow {default,copy} {constructible,assignable}Marc Mutz2015-09-131-5/+6
| | | | | | | | | | Change-Id: I6757a775c72f15c210004dc25d962ec5d3b88012 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QSharedPointer: mark as nothrow {default,move,copy}{constructible,assignable}Marc Mutz2015-09-131-5/+5
| | | | | | | | | | Change-Id: Ieae2c5ff6db1a475269034f0bd9cbd903dd3c72a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Implement QDebug support for QSharedPointerGiuseppe D'Angelo2015-09-031-0/+11
|/ | | | | | | | | | | | ... otherwise the type goes through operator bool() and prints "true" or "false" (!). [ChangeLog][QtCore][QSharedPointer] Added support for debug printing via QDebug. Change-Id: Ic3ef9b9feee8d6ca08f1dd69f20f421fea20ca00 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer: make copy assignment from compatible shared pointer use ↵Marc Mutz2015-07-211-14/+2
| | | | | | | | | | | copy-swap ... like all other assignment operators. Removes the last user of internalCopy(). Removed. Change-Id: I15f2cb3b7b26988dd3bc2f4475bc316480476993 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer: add move construction, assignment from compatible shared ↵Marc Mutz2015-07-191-0/+17
| | | | | | | pointers Change-Id: I772c568055c9bed6eb627ad35dba300925fc0fde Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer: mark some internal API nothrowMarc Mutz2015-07-191-4/+4
| | | | | Change-Id: I871c86406b2c25df9a7834a997caf8a792d353a0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: Use Q_NULLPTR instead of 0 in smart pointer headersMarc Mutz2015-07-181-16/+16
| | | | | | | | | | | This is in preparation of adding -Wzero-as-null-pointer-constant (or similar) to the headers check. Not caught by the headersclean check, because they are in template code. Task-number: QTBUG-45291 Change-Id: I7294404225a19a1c58f91e6e47a9d650179ea83c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QWeakPointer: remove misleading Q_DECL_CONSTEXPRMarc Mutz2015-06-281-1/+1
| | | | | | | | | | Adding constexpr there is allowed, because QWeakPointer is a class template. But in 100% of cases, it will be dropped, because the destructor is not trivial. So, don't mislead users and devs to think that any or even all QWeakPointers could ever be constexpr. Change-Id: Ia50aad4d6c4fb724254308150124c666e82ef817 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QSharedPointer: destroy LHS on move assignmentMarc Mutz2015-06-271-1/+2
| | | | | | | | | | | | | | | | | Howard Hinnant is right: just swapping may keep a resource alive too long. The problem with replacing swap(other) was that the naïve approach: clear(); swap(other); is not safe for self-assignment. Taking a cue from the default std::swap() implementation, and the copy-swap idiom, a self-assignment-safe version is QSharedPointer moved(std::move(other)); swap(moved); which is to what I changed the implementation now. Change-Id: I589fdae50ae22b95350db8250b02d983dc8487a6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace <qhash.h> with <qhashfunctions.h> where applicableMarc Mutz2015-04-201-1/+4
| | | | | | | | To avoid source-incompatibilites, wrap in QT_DEPRECATED_SINCE(5, 5) in public headers. Change-Id: Ic3398f4f330e15a3b55065858add26b90fd70e6c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Silence bogus MSVC warning about variable not usedThiago Macieira2015-03-071-0/+1
| | | | | | | | | | | | The compiler is wrong: the variable was used in the previous line. However, the line had no effect for a type T that has a trivial destructor, so the optimizer must have discarded the line and the reference to the variable before the checker for used variables. qsharedpointer_impl.h(247) : warning C4189: 'that' : local variable is initialized but not referenced Change-Id: Ia0aac2f09e9245339951ffff13c8bde02bb46816 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Fix QSharedPointer::create and QEnableSharedFromThisThiago Macieira2015-01-211-0/+2
| | | | | | | | We forgot to initialize the tracker if create() was used. Task-number: QTBUG-43696 Change-Id: Ic5d393bfd36e48a193fcffff13b740931ff2204b Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Add QEnableSharedFromThis classRoman Pasechnik2014-06-291-0/+41
| | | | | | | | | It enables you to get a valid QSharedPointer instance to 'this', when all you have is 'this'. Task-number: QTBUG-7287 Change-Id: I3ed1c9c4d6b110fe02302312cc3c4a75e9d95a0c Reviewed-by: Richard J. Moore <rich@kde.org>
* Make QWeakPointer's ctor constexprGiuseppe D'Angelo2014-05-291-1/+1
| | | | | Change-Id: Ia23406ee80e83071a129606b76f78e2b6d0cf32e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer: allow one create() argument in C++98, tooMarc Mutz2014-04-071-0/+21
| | | | | | | | | | Survey says that most uses of QSharedPointer(T*) in Qt that could benefit from variadic create() pass only a single argument. In order to prevent all such uses from #ifdef'ing on the complex condition that enables the variadic version, provide a single-argument version (for lvalues only, obviously) for C++98, too. Change-Id: I22ad251a20bbf80867cc31eaa3bcec677bde4359 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QWeakPointer: add member-swapMarc Mutz2014-04-031-0/+6
| | | | | | | | [ChangeLog][QtCore][QWeakPointer] Added member-swap function. Change-Id: Ide3672dc74a9d8153e5f930290d938e8c23993b5 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QWeakPointer: add lock() for std::weak_ptr compatibilityMarc Mutz2014-04-031-0/+2
| | | | | | | [ChangeLog][QtCore][QWeakPointer] Added lock() method for std::weak_ptr compatibility. Change-Id: I0851d91c51f5a4f04a855a1d8082234ce38396b4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer/QWeakPointer: clean up class definitionMarc Mutz2014-02-281-15/+15
| | | | | | | | | Remove superfluous class template arguments (<T>). Qualify one member function call with this-> instead of QSharedPointer<T>::. Change-Id: I5cbe8776fc914138b7ceb4747a08c6475227197b Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSharedPointer: implement move ctorMarc Mutz2014-02-281-0/+6
| | | | | | Change-Id: I46974aa1d056be797db959b547a1516157b598ca Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove use of 'register' from Qt.Stephen Kelly2013-06-171-5/+5
| | | | | | | | | | It is deprecated and clang is starting to warn about it. Patch mostly generated by clang itself, with some careful grep and sed for the platform-specific parts. Change-Id: I8058e6db0f1b41b33a9e8f17a712739159982450 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark all qtbase headers that aren't cleanThiago Macieira2013-03-031-0/+5
| | | | | | | | | | | | | | | | QtCore has a few headers that, though public, aren't meant to be included directly. Those are the atomic headers, the three _impl.h headers and qt_windows.h. QtGui includes two OpenGL headers that don't compile on their own. Other libraries should not have headers like that (but they do, something we need to fix eventually). Change-Id: I55e4eb057748f47df927ee618f9409acbc189cc1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make it possible to use QPointer<const T>Stephen Kelly2013-02-131-1/+1
| | | | | | | | | | | | | This is possible with QWeakPointer, so allow it for migrating code too. In the process, replace the QPointerBase with a member variable for simplicity. The functionality of the QPointerBase is replaced by a TypeSelector template. Change-Id: I3b4c77bdeda2b863cc33e84a3da8a25bae928c8c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Remove QT_{BEGIN,END}_HEADER macro usageSergio Ahumada2013-01-291-6/+0
| | | | | | | | | | | The macro was made empty in ba3dc5f3b56d1fab6fe37fe7ae08096d7dc68bcb and is no longer necessary or used. Discussed-on: http://lists.qt-project.org/pipermail/development/2013-January/009284.html Change-Id: Id2bb2e2cabde059305d4af5f12593344ba30f001 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
* Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-01-221-1/+1
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qsavefile_p.h src/corelib/tools/qregularexpression.cpp src/gui/util/qvalidator.cpp src/gui/util/qvalidator.h Change-Id: I58fdf0358bd86e2fad5d9ad0556f3d3f1f535825
| * Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | | | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Merge branch 'stable' into devFrederik Gladhorn2013-01-071-0/+2
|\| | | | | | | | | | | | | Conflicts: tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp Change-Id: I6b8d505fc22f052c307ca27f58f7d16f98965f47
| * Don't increase the reference count if dynamic_cast failedThiago Macieira2013-01-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | If the dynamic_cast failed in QSharedPointer::dynamicCast or qSharedPointerDynamicCast, we should avoid creating the QSharedPointer that shares the weak and strong reference counts. In Qt 5, this does not imply a leak since the original pointer is stored internally for deletion. In Qt 4 it implies a leak under certain circumstances, which this change fixes. Task-number: QTBUG-28924 Change-Id: Id2de140de4cf676461e14b201ad250c53666b79d Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* | Add support for multiple arguments to QSharedPointer::create()Thiago Macieira2012-12-231-0/+27
|/ | | | | | | | Requires C++11 rvalue references and variadic templates so we can implement perfect forwarding. Change-Id: I62e47d1ffd0c61e8386f9f246aa79031b7430b46 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Quieten warning about uninitialized use of d pointerTobias Hunger2012-10-241-1/+1
| | | | | | | | | | We had this issue in Qt 4 before: Clang considers the use of d uninitialized in the initializer list for d. This might or might not be legal, the clang devs are divided on that topic. Let's just use a more common form and ignore the issue language lawyers. Change-Id: I3324255963a6d0f4a9057fe0d1d9ae868d3efef7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Optimise the deletion of a QSharedPointer with no custom deleterThiago Macieira2012-10-101-18/+33
| | | | | | | | | | | | | | | | When QSharedPointer is created with no user-specified custom deleter, instead of storing a pointer in ExternalRefCount::destroyer to a static function which, in turn, calls normalDeleter<T> indirectly (via another function pointer), specialise the CustomDeleter class and make it not store the pointer, but instead do the deleting directly. The benefits are: - the QSharedPointer's private data is smaller - there is no double-indirection via indirect jumps to the actual deleter Change-Id: Ice5653c144912efb1226e432267a047b9799aaca Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* QSharedPointer: make QT_SHAREDPOINTER_TRACK_POINTERS work with QObjectsGiuseppe D'Angelo2012-08-281-2/+2
| | | | | | | | | | | | | | | | If setQObjectShared crashes because a QObject is tracked by two different QSharedPointers, we lose the debug feature offered by #defining QT_SHAREDPOINTER_TRACK_POINTERS, as the check done by this define happens after the setQObjectShared call. Therefore, move setQObjectShared after the internalSafetyCheckAdd call. This is actually a noop change in 5.0, as setQObjectShared does nothing. However it prevents a bug in case the Qt 4 behaviour is brought back in some later version. Change-Id: I71340d0f878828354537762d01c46d441efc918c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Wrap QObject usage in qsharedpointer_impl.h with ifndef QT_NO_QOBJECTThiago Macieira2012-06-241-0/+2
| | | | | | | | Otherwise, bootstrapped tools like qmake and moc won't compile, unless QObject is forward-declared (which it isn't anymore). Change-Id: If67ca1cd8fdb7b29628f9dc4b454595d26a715d0 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
* Add some internal API for extracting a QSharedPointer<T> from QVariant.Stephen Kelly2012-06-201-1/+19
| | | | | | | | | | | | | The T must be derived from QObject, or it will fail to compile. This will allow scripting or other 'wrapping' and runtime environments like QtDeclarative to handle QSharedPointers to types derived from QObject properly. A QSharedPointer<T> can be inserted into a QVariant, and where T derives from QObject, a QSharedPointer<QObject> can be extracted from the QVariant, and its properties are then accessible. Change-Id: I68d6d89aceceb019267bd7301baa2047f9c09b90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix access to uninitialized pointerTobias Hunger2012-06-201-1/+1
| | | | | | | | | | The C++ standard says in 9.4..2 that the object expression is evaluated, so any compliant compiler may access d. So this syntax is a bug in this place. Change-Id: I37d2c4ea54febd40410ca473c906bcb1c66c4974 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
* Keep the #ifdef for tracking shared pointers in a single functionThiago Macieira2012-06-121-23/+26
| | | | | | | | | | | | | | | If we have it in different functions, then different out-of-line implementations could be selected for each object file, resulting in invalid states. The error I caught was when wrapper.cpp was compiled without tracking and, therefore, did not place a call to internalSafetyCheckAdd. However, it called an out-of-line copy of QtSharedPointer::ExternalRefCountWithCustomDeleter::create, which did set the deleter to remove the safety check. Therefore, keep everything in one function. Change-Id: Ib2c6a606699db49d102704bccdd331ec22a8bd78 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Simple optimisation for the construction of a QSharedPointerThiago Macieira2012-06-121-9/+3
| | | | | | | | | | Let the constructor initialise the "value" member. In the case of create(), which already initialised "value", simply merge the two functions for more readability. Change-Id: I5638b3d42af3d0f5988f815e0f91d591fa1897a8 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Use the copy & swap trick to simplify some code in QSharedPointerThiago Macieira2012-06-121-3/+4
| | | | | Change-Id: I5fa2fae19126bea60b9682ed7765681dd6da8c15 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Now merge the QtShared::ExternalRefCount class into QSharedPointerThiago Macieira2012-06-121-157/+133
| | | | | | | | | Completing the work of the previous commit: we don't need separate classes. Merge into the main class's body. Change-Id: I2f89b34cb6b7f5f9e8d8b809bebd86656f458644 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>