summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsharedpointer
Commit message (Collapse)AuthorAgeFilesLines
* Update contact URL in license headers.Jason McDonald2009-08-128-8/+8
| | | | Reviewed-by: Trust Me
* tst_QSharedPointer fixed for Windows CEJoerg Bornemann2009-08-101-0/+2
| | | | | | We cannot create too many threads on Windows CE. Reviewed-By: thartman
* tst_qsharedpointer compile fix for Windows CEJoerg Bornemann2009-08-061-0/+4
| | | | | | There's no time() on Windows CE. Reviewed-by: Daniel Molkentin
* Restore symmetry between QSharedPointer and QWeakPointer on QObjects.Thiago Macieira2009-08-051-0/+31
| | | | | | | | | | | | | | | | | | | | | | | With the previous commit, you could create a QWeakPointer from any QObject-derived object. It's possible because QObject now has a pointer to the QWeakPointer's d-pointer. However, if you did: QSharedPointer<QObject> obj(new QObject); QWeakPointer<QObject> weak1(obj); QWeakPointer<QObject> weak2(obj.data()); Then weak1 would shared d-pointers with QSharedPointer, but weak2 wouldn't. Also, weak1.toStrongRef() would work, but weak2.toStrongRef() wouldn't. This change makes QObject know where the d-pointer created by QSharedPointer is, so weak2 would get the same d-pointer. As a nice side-effect, you can check if a given QObject is shared by trying to promote its QWeakPointer to QSharedPointer. Reviewed-by: Bradley T. Hughes
* Add support for using QWeakPointer with QObject, replacing QPointer.Thiago Macieira2009-08-051-0/+110
| | | | | | | | | | | | | | | | | | | | | | | | | The problem with QPointer is that it's a simple QObject*. So the only way for QPointer to do what it's supposed to do is if the object it's pointing to clears all QPointers when getting deleted. That means the QObject must know each and every QPointer pointing to it. To make matters worse, QPointers can be deleted while the object they're pointing to also gets deleted. So deleting QObjects must do locking. The solution to the QPointer problem is that both QObject and the "QPointer" reference something outside the QObject. This way, QObject doesn't have to lock anything to destroy itself: it's simply setting a volatile integer to zero when it gets deleted. Since the integer is outside the QObject, the integer is also refcounted. It's also O(1), so there's no problem having as many "QPointer". The two-atomic-ints structure is exactly what QSharedPointer and QWeakPointer use internally. We just abuse this structure for QObject needs, setting the strong reference count to -1 to indicate that it's a QObject that cannot be managed by a QSharedPointer. But QWeakPointer can still work and replace QPointer neatly. Reviewed-by: Bradley T. Hughes Reviewed-by: Jarek Kobus
* Ensure that we never increase the strong reference count up from zero.Thiago Macieira2009-08-031-1/+124
| | | | | | Also add some thread stress tests to try and detect doing it wrong. Reviewed-By: Bradley T. Hughes
* Change the pointer-tracking code to work everywhere.Thiago Macieira2009-08-034-2/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, if you create a QSharedPointer in code with pointer-tracking, you must ensure it gets deleted in code with pointer-tracking, otherwise the internal safety tracker will be "leaking" objects. The pointers would never get removed. And if any new pointer happened to have the same pointer address (which happens quite often), the tracker code would promptly abort the application. With this change, the untracking of the pointer is scheduled by the same code that creates the tracking. This is done by "abusing" the custom deleter code: - for the QSharedPointer that used ExternalRefCountWithDestroyFn already, we intercept the call to the destroy function and call the untracking function - for a normal QSharedPointer, we use the "normalDeleter" function as custom deleter and chain up above Note: the autotest only *really* works in release mode. Otherwise functions don't get inlined and do get merged by the linker. Reviewed-By: Bradley T. Hughes
* Don't forget to delete the deleter object too in QSharedPointer.Thiago Macieira2009-08-031-0/+13
| | | | | | Destructors have to be run for the subobjects we initialise. Reviewed-By: Bradley T. Hughes
* Remove the need for internal API in QSharedPointer.Thiago Macieira2009-08-032-41/+55
| | | | | | | That way, this code can be compiled with an earlier version of Qt and should still work in new ones. Reviewed-by: Trust Me
* Autotest: add a way to ensure that there are no safety-check pointers leakingThiago Macieira2009-08-031-0/+42
| | | | | In the future, it would be nice to split the autotest in multiple functions at every check().
* Merge branch '4.5'Thiago Macieira2009-08-031-0/+2
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qsharedpointer.cpp src/corelib/tools/qsharedpointer_impl.h src/gui/dialogs/qcolordialog.cpp src/gui/painting/qwindowsurface_raster.cpp src/network/access/qnetworkaccessmanager.cpp tests/auto/qsharedpointer/externaltests.cpp
| * Autotest: disable the pointer-tracking tests in 4.5Thiago Macieira2009-08-031-0/+2
| | | | | | | | | | | | | | The functionality these tests tested was broken in 4.5 and has been disabled. Therefore, these tests simply cannot pass. It's fixed in 4.6.
| * Autotest: add a newline after the user program headers.Thiago Macieira2009-07-301-0/+1
| | | | | | | | | | | | | | | | If the user forgot to end their headers with a newline, the compilation would fail because the next line is #include <QtCore/QtCore>. Reviewed-by: Jesper Thomschütz
| * Fix a running external tests: user program headers must come first.Thiago Macieira2009-07-261-2/+2
| | | | | | | | | | | | No wonder QT_SHAREDPOINTER_TRACK_POINTERS was having no effect: there was an #include <QtCore/QtCore> before it. (cherry picked from commit 4c12010fac555bce0a6c8d69a267a56f4c15087f)
* | Disable the forwardDeclared1 test with SunCC: it doesn't workThiago Macieira2009-07-281-0/+4
| | | | | | | | | | | | | | | | | | I added this test because I thought that the compiler would find the forward-declarations due to the "one definition" rule. In hindsight, it's not a good idea. Sun CC warns about this, gcc doesn't. With Sun CC, the code leaks, with gcc it doesn't.
* | Fix a running external tests: user program headers must come first.Thiago Macieira2009-07-251-2/+2
| | | | | | | | | | No wonder QT_SHAREDPOINTER_TRACK_POINTERS was having no effect: there was an #include <QtCore/QtCore> before it.
* | Add support for debugging and valgrinding external testsThiago Macieira2009-07-251-10/+74
| | | | | | | | This requires modifying slightl QProcess on Unix to forward stdin too.
* | Revert "Revert "Add support for creating the object alongside the Data ↵Thiago Macieira2009-07-241-2/+100
| | | | | | | | | | | | | | structure in QSharedPointer"" This restores the original implementation of the creating function. The next commit will make it suitable for use.
* | Disable private unit tests when Qt is configured withoutRohan McGovern2009-07-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | -developer-build, part 2. Some autotests use private (unexported) code, either because they're testing private classes or because that's the easiest way to test the public classes. Configuring Qt with `-developer-build' is needed for these tests. This commit fixes the tests so configuring without `-developer-build' only builds the tests which strictly use public API.
* | Revert "Add support for creating the object alongside the Data structure in ↵Thiago Macieira2009-07-021-100/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QSharedPointer" This reverts commit fb51a10ee0451274a430227566ae26efb2ac4474. Sorry, it didn't work. I can fix the MSVC error, but the problem is that older GCC versions (4.2) fail with the following code: template<typename T> struct Buffer { char buffer[128] __attribute__((aligned(__alignof__(T)))); }; The same works fine in GCC 4.4.
* | Experimental: allow QSharedPointer to be used with forward declarations that ↵Thiago Macieira2009-07-028-12/+223
| | | | | | | | | | | | | | | | | | | | | | | | | | are declared in this file. The one-definition rule allows the forward declaration appearing below to apply to code that was earlier. Therefore, if the compiler finds out how to delete the object, we can allow a QSharedPointer of a forward- declared-type. This means the actual problem is just a warning with g++. To catch the error, we need a separate .cpp file and I'd rather run this as an external test.
* | Add support for creating the object alongside the Data structure inThiago Macieira2009-07-021-2/+100
| | | | | | | | | | | | | | | | | | one go. This avoids one memory allocation. Currently, we only support calling the default constructors. I will *NOT* implement argument passing for C++03. I will implement it with rvalue references for C++0x-capable compilers.
* | Add qobject_cast for QSharedPointer.Thiago Macieira2009-07-021-0/+123
| | | | | | | | | | | | | | | | | | This obviously only works for classes that derive from QObject. And you must remember that QSharedPointer controls the QObject's lifetime, not the QObject parent-child relationship. Reviewed-by: dt Reviewed-by: Bradley T. Hughes
* | Autotest: Fix a few test names and allow me to see the compilation errorsThiago Macieira2009-06-261-3/+10
|/ | | | Reviewed-by: TrustMe
* Change QSharedPointer to track (or not) pointers when the #define isThiago Macieira2009-06-251-1/+2
| | | | | | | | | enabled. This allows mixing of debug and non-debug code (possible on Unix systems) without causing assertion failures. Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Update license headers as requested by the marketing department.Jason McDonald2009-06-163-6/+6
| | | | Reviewed-by: Trust Me
* Fix handling of dynamic casts in QSharedPointer.Thiago Macieira2009-05-181-9/+128
| | | | | | | | | | | | It's wrong to assume that static_cast<> is allowed everywhere where dynamic_cast<> is allowed. For example, if class C derives from both A and B, then you can dynamic_cast<B *>(ptr_to_A), but you can't static_cast. So introduce a helper for dynamic casts that doesn't do static_cast. Reviewed-by: Olivier Goffart
* Long live Qt 4.5!Lars Knoll2009-03-236-0/+1735