Commit Graph

54596 Commits

Author SHA1 Message Date
Volker Krause
7f54e113b9 Make QAbstractItemModel::insert|move|remove(Columns|Rows)[s]() invokable
Useful for example for calling those from QML.

Change-Id: I07fe32944c76b58cb074b6dd7eff17af1f0ae00f
Reviewed-by: David Faure <david.faure@kdab.com>
2021-12-21 08:04:17 +01:00
Zhang Hao
8678ab9354 Use qint64 to replace int while qt_transform_image_rasterize
When rotating a very large image(for example,the image size is
42000*24000),using QTransform will cause the the variable of the
qt_transform_image_rasterize function exceeds the range of int.
Fix this by Use qint64 to replace int.

Fixes: QTBUG-99163
Done-with: Eirik Aavitsland <eirik.aavitsland@qt.io>
Pick-to: 6.3 6.2 5.15
Change-Id: I11e2873fbb1f432953a1a8e07054f9478dd90fbd
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2021-12-21 09:24:56 +08:00
Igor Kushnir
047d8f36de QMimeDatabase::mimeTypeForFile: don't create QFileInfo on UNIX
When mode != MatchExtension is passed to
QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const
a QFileInfo object is always created and used to check
QFileInfo::isDir(). Replace this expensive approach with a very cheap
(bitmask) S_ISDIR check under Q_OS_UNIX. QT_STAT is already called for
other reasons, so we just reuse its result in the S_ISDIR check.

Extract almost all code from
QMimeDatabase::mimeTypeForFile(const QString &, MatchMode) const;
QMimeDatabase::mimeTypeForData(QIODevice *) const;
QMimeDatabase::mimeTypeForFile(const QFileInfo &, MatchMode) const
into
QMimeDatabasePrivate::mimeTypeForFileExtension(const QString &);
QMimeDatabasePrivate::mimeTypeForData(QIODevice *);
QMimeDatabasePrivate::mimeTypeForFile(const QString &, const QFileInfo *, QMimeDatabase::MatchMode)
respectively. This refactoring is a less convoluted and more efficient
alternative to adding more mutex-unlocking hacks. The existing
QMutexLocker::unlock() calls are thereby eliminated.

The following table contains the average results of the benchmark
tst_QMimeDatabase::benchMimeTypeForFile() on my GNU/Linux system before
and at this commit. The numbers denote milliseconds per iteration.
This commit does not measurably affect performance when
mode == MatchExtension, therefore the MatchExtension section contains a
single column with results common to both commits (it is interesting to
compare benchmark results across match modes).

        data row tag                        before  at
MatchDefault:
        archive                             0.012   0.010
        OpenDocument Text                   0.012   0.010
        existent archive with extension     0.022   0.018
        existent C with extension           0.016   0.012
        existent text file with extension   0.017   0.012
        existent C w/o extension            0.072   0.067
        existent patch w/o extension        0.10    0.10
        existent archive w/o extension      0.064   0.060
MatchExtension:
        archive                                 0.0081
        OpenDocument Text                       0.0076
        existent archive with extension         0.012
        existent C with extension               0.0075
        existent text file with extension       0.0076
        existent C w/o extension                0.0122
        existent patch w/o extension            0.0091
        existent archive w/o extension          0.0091
MatchContent:
        archive                             0.0098  0.0078
        OpenDocument Text                   0.0098  0.0078
        existent archive with extension     0.051   0.047
        existent C with extension           0.051   0.047
        existent text file with extension   0.053   0.049
        existent C w/o extension            0.058   0.054
        existent patch w/o extension        0.099   0.095
        existent archive w/o extension      0.054   0.050

Change-Id: I01b37c9645f0d8d35fd1a6ea1c7a99be2faeeb73
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: David Faure <david.faure@kdab.com>
2021-12-20 20:43:27 +02:00
Alexey Edelev
fe7fc3f23e Copy only files that belongs to QML module
Instead of copying all files that the QML module directory contains,
this approach only copies files that belong to the QML module
according to the qmlimportscanner output.

Pick-to: 6.3
Fixes: QTBUG-97834
Change-Id: I881a6fba28ca24be4f33de8693b41b6dfefe8d6b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-12-20 18:08:10 +01:00
Marc Mutz
620220413e CMake: don't treat Q_CORE_EXPORT special
Let CMake create a qtcoreexports.h just like for every other Qt
library, include it in a fitting place in qglobal.h. Currently, that's
in the middle of the file, but that will be cleaned up in subsequent
commits.

Task-number: QTBUG-99313
Change-Id: I3ea9f4772b0ad63c7e8431689146cac3336c5ccf
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2021-12-20 13:32:28 +01:00
Tianlu Shao
87b93c29be QtConcurrent::run crashes on program exit
When an application is about to be closed and all the
destructors are called, if there isQtConcurrent::run on
the way, it crashes as the internal threadpool pointer
is nullptr.

Fixes: QTBUG-98901
Pick-to: 6.2 6.3
Change-Id: Idd84d1518fc6a225263e6666a0f1de2ccef79c82
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2021-12-20 13:18:26 +01:00
Tatiana Borisova
43e9f86cc1 tst_qglobalstatic is halted on INTEGRITY device
- Stress test creates too many threads on run time.
  Testing system is limited in 123.

Task-number: QTBUG-99123
Pick-to: 6.2 6.3
Change-Id: I215074fa432c8aa18b2a753169646841c01d0b2a
Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-20 10:14:38 +02:00
Ivan Solovev
f8b74a4957 QXmlStreamReader: update test distribution
As mentioned in the linked bugreport, we are not allowed to distribute
the uncompressed files from one of the XML test datasets that we use
in our tests.
This patch removes the uncompressed version, and replaces it by the
xmltest.zip archive taken from [0].
Once the test is started, QZipReader is used to uncompress the archive,
and once the test is done, the uncompressed data is removed.

However the test data from [0] is very old, so it is slightly different
from what we had previously (the previous data was taken from w3c).
As a result, 4 test cases are failing with this data. To fix it, we
store the updated versions of 4 xml files separately, and replace them
after uncompressing the archive.

[0]: http://www.jclark.com/xml/

Fixes: QTBUG-81503
Pick-to: 6.3 6.2 5.15
Change-Id: Ied5233970a529deebca56b1eab07fe1c328a2ee0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-12-19 18:58:44 +01:00
Ivan Solovev
5cc7510801 QZipReader: update to unzip partly broken archives
The problem was discovered while providing a fix for the linked issue.
The original zip archive is very old, and it does not contain separate
entries for directories, only for files.
As a result, QZipReader algorithm was failing to create all the
necessary subdirectory structures, and unzipping failed.

This patch detects such case, and creates a directory hierarchy based
on the file paths.

Task-number: QTBUG-81503
Pick-to: 6.3 6.2 5.15
Change-Id: I204f9b620853b3ffcbb9cbf6fe08fb5958776ea0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-12-19 18:58:40 +01:00
Kai Köhne
c52fcb2ad9 bindablesubscription: Remove duplicated file entry
Pick-to: 6.2 6.3
Change-Id: I7f24425c8ccfb11bda926373099d377f808a70dd
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2021-12-19 14:38:27 +01:00
Thiago Macieira
8db16bfa7e QString: use char16_t in isAscii() instead of QChar
Drive-by simple clarification of the code that needed to be touched
anyway.

Pick-to: 6.3 6.2
Change-Id: Ib42b3adc93bf4d43bd55fffd16c14f984b0fb592
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-18 18:09:21 -03:00
Thiago Macieira
1a9e7a3aad QString: don't let the compiler emit unnecessary looping
When AVX2 was enabled, we know we don't need to loop in qt_is_ascii()
(QtPrivate::isAscii(QLatin1String)).

Pick-to: 6.3 6.2
Change-Id: Ib42b3adc93bf4d43bd55fffd16c14f8f95ae8678
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-18 18:09:19 -03:00
Thiago Macieira
449f6d5f61 QString: replace an #if with if
Pick-to: 6.3 6.2
Change-Id: Ib42b3adc93bf4d43bd55fffd16c111291d1e8ddd
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-18 18:09:17 -03:00
Marc Mutz
dc672cf35a tst_QPropertyAnimation: fix leaks occurring under normal operation
Tests were leaking objects even if all tests passed. In two cases,
there just wasn't a delete at all, in a third, the existing delete
wasn't reached because of a QSKIP.

tst_QPropertyAnimation is now, locally, LSan-clean.

Pick-to: 6.3 6.2 5.15
Change-Id: Ia53d6f6e467f1d2598a7c50efcdf3a3732fe54df
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-18 10:38:21 +01:00
Yuhang Zhao
bdaab71c68 CMake: Remove WinRT leftovers from build system
Qt's WinRT support was removed long time ago.

Change-Id: I60b220e970072c3450e3793862d6f68801d2b5b3
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-18 08:01:39 +08:00
Marc Mutz
9b320edb53 QStringBuilder: fix quadratic behavior in op+=
QByteArray and QString honor a reserve(n) faithfully, meaning that if
n > capacity(), then capacity() == n after the reserve() call.

This is expected behavior, and also what libstdc++'s std::vector does.

The problem is QStringBuilder's op+=, which calls reserve()
unconditionally to ensure capacity for its resize-after-append
magic. If a user builds up a string by repeatedly appending
string-builder expressions, these repeated minimal-progress reserve
calls destroy the string's natural geometric capacity growth, turning
it linear instead, and hence the whole construction becomes quadratic.

Fix by calling reserve() only when necessary, and for a maximum of
O(logN) times, N being the separate calls to QStringBuilder's op+=.

This guarantees amortized-linear runtime of string building again.

Need to insert an explicit detach() call in reserve()'s stead, lest a
detach() in the following data() would reset capacity() to size().

Copied a useful comment from the QByteArray case to the QString case.

[ChangeLog][QtCore][QStringBuilder] Fixed quadratic behavior when
repeatedly appending string-builder expressions (using operator+=) to
QString/QByteArray objects.

Pick-to: 6.3 6.2
Change-Id: I1c210a8d0026c227e55e5e30a46fb747660bb66e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
2021-12-17 23:50:01 +01:00
Lars Knoll
1cc5948839 QHash: Return void from QHashPrivate::Data::erase()
This removes some calculations that are not required in
80% of the cases where d->erase() is being called (as
the return value is ignored). When removing lots of
elements from the hash, the ++it could loop quite a
bit until it found the next valid item in the hash.

This chain of changes combined improve the overall performance of
QHash by 10-50% depending on the operation. Deletes are twice
as fast, reads around 20% faster, inserts around 10% faster.

Task-number: QTBUG-91739
Fixes: QTBUG-98436
Change-Id: I2d82a7c9dd1dd0a4da8402e6d95bfd620caeff3a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-17 20:21:28 +01:00
Thiago Macieira
46dc8e453a QVariant: use a typedef name when saving user types to QDataStream
Due to the way Qt 5 and 6 registered type names, they end up producing
different type names for the same content for a typedef. For example,
because Q_DECLARE_METATYPE can't manage a comma (it's a macro), users
are forced to write something like:

 using MyTypeMap = QMap<QString, MyType>
 Q_DECLARE_METATYPE(MyTypeMap)

Qt 5's Q_DECLARE_METATYPE's argument "MyTypeMap" was the only name we
knew about the type, so that's what got saved in the stream. However, Qt
6 QtPrivate::typenameHelper is much more clever and obtains the name
from the compiler itself, so it "sees through" the typedef and registers
"QMap<QString,MyType>" as the official type name.

If another library/plugin has a different typedef name for the same type
(e.g., StringTypeMap), it's indeterminate which type gets saved and will
even change from run to run (depends on the QHash order).

[ChangeLog][QtCore][QDataStream] If QDataStream is used with a
QDataStream::Version < Qt_6_0 to serialize a user type that was
registered via a typedef with the metatype system, the typedef's name is
used in the stream instead of the non-typedef name. This restores
compatibility with Qt 5, allowing existing content to read the same
QDataStreams; reading from older Qt 6 versions should not be affected.
(Note: if more than one typedef name is registered, it's indetermine
which name gets used)

Fixes: QTBUG-96916
Pick-to: 6.3 6.2
Change-Id: I2bbf422288924c198645fffd16a8d811aa58201e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-12-17 17:54:05 +01:00
Alexandru Croitor
af36675afd CMake: Fix exit code to be shown properly on test failure
The result variable was expanded at configure time rather than at
script execution time due to missing escaping.

A tidbit of information, the result variable can contain not only an
exit code, but a string as well.
For example on arm macOS with a crashed test it contains
'SIGTRAP'.

Curiously if the crashing executable is executed directly without
CMake, 'Trace/BPT trap: 5' is shown instead, perhaps because of
the shell.

Amends 3ef6af024b

Pick-to: 6.2 6.3
Change-Id: I50e57922abfc6eccde205c6252eebfda510bad41
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-17 17:54:05 +01:00
Marc Mutz
5cdaf17e8d tst_QPropertyAnimation: fix wrong comment
... and add some additional checks that hopefully leave the next
reader of the code a little less confused than this one was.

Pick-to: 6.3 6.2 5.15
Change-Id: I73c1b9b1ed1683e3b2de0d811d9b20d65464dff4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2021-12-17 17:54:05 +01:00
Mårten Nordheim
26267ef57e tst_QHash: Update the erase_edge_case test
By using the bucketForHash function we can loop through and find
some appropriate keys to test the edge-case. This will then
automatically keep the test working even if some internals
of QHash changes.

We do this because certain changes which change the bucket the
pre-selected keys would end up in could make the test a no-op,
without warning. And recent and upcoming changes have changed
both this and erase(). We limit the search-space to
the minimum numBuckets * 4, where minimum numBuckets is current
128.

Change-Id: I13b0bce15ee884144e3248846be34667fb5d35cc
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-17 16:37:49 +00:00
Lars Knoll
9c9cdbedf1 QHash: Add and use a Bucket helper class
Introduces a QHashPrivate::Data::Bucket class. This class
helps avoid repeated bitshift and masking operations when
locating bucket entries in the hash.

Change signature of some internal methods to use Bucket
instead of the private iterator, so we can avoid repeated
encoding/decoding steps for the bucket index.

Task-number: QTBUG-91739
Task-number: QTBUG-98436
Change-Id: I9ed2205bf886f9c20a5be109fd88456eec4d1540
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-17 17:37:49 +01:00
Alexandru Croitor
340b2a1a47 CMake: Fix exit code to be shown properly on test failure
The result variable was expanded at configure time rather than at
script execution time due to missing escaping.

A tidbit of information, the result variable can contain not only an
exit code, but a string as well.
For example on arm macOS with a crashed test it contains
'SIGTRAP'.

Curiously if the crashing executable is executed directly without
CMake, 'Trace/BPT trap: 5' is shown instead, perhaps because of
the shell.

Amends 3ef6af024b

Pick-to: 6.2 6.3
Change-Id: I50e57922abfc6eccde205c6252eebfda510bad41
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-17 17:24:36 +01:00
Marc Mutz
2fef4636aa tst_QPropertyAnimation: fix wrong comment
... and add some additional checks that hopefully leave the next
reader of the code a little less confused than this one was.

Pick-to: 6.3 6.2 5.15
Change-Id: I73c1b9b1ed1683e3b2de0d811d9b20d65464dff4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2021-12-17 17:24:36 +01:00
Marc Mutz
c31fecd27f QByteArray: fix UB (precondition violation) in replace()
If after.isNull(), then we called memcpy with a nullptr, which is UB,
even if the size is zero, too.

memmove() has the same precondition.

Fix by guarding the memcpy() call with an explicit length check.

The Qt 5.15 code is sufficiently different to not attempt to pick
there.

Pick-to: 6.3 6.2
Change-Id: I86a2f00ede6ca8fab8d4222f84dccf375c4a2194
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-17 12:34:27 +01:00
Kai Köhne
0c39e5c76d Examples: Remove unneeded target_include_directories
Pick-to: 6.3
Change-Id: Icd97815ee231c34ad4ea5ab94a73bfc26df7e0ca
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-17 10:38:50 +01:00
Kai Köhne
e751c604df mandelbrot example: Remove explicit linking against libm
It seems not needed anymore with modern toolchains.

Pick-to: 6.3
Change-Id: Ic5386cad4576b10f49fd74212f3514e26cfb0abe
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-17 10:38:50 +01:00
Kai Köhne
4f699e8207 analogclock example: Clean up link_libraries
analogclock doesn't use widgets.

Pick-to: 6.3
Change-Id: I75b5efc0bec786b45f8273e3d21c9be204e18225
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-17 10:38:49 +01:00
Kai Köhne
131681652e Examples: Clean up WIN32_EXECUTABLE, MACOSX_BUNDLE properties
Both are FALSE by default, so no point in explicitly setting
them to FALSE.

In addition, dbus/listnames is a command line tool. No reason
to set WIN32_EXECUTABLE, MACOSX_BUNDLE here.

Pick-to: 6.3
Change-Id: I99aaf27a0267c5575bd2ee5b6183991fce721f44
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-17 10:38:49 +01:00
Kai Köhne
7cf8ecf4ce androidnotifier: Simplify example CMakeLists.txt
Building the example when not on android makes little
sense. Therefore just error out in this case.

Pick-to: 6.3
Change-Id: Ib7325156bcd8ffd1b9b3e67174d878f5731a4a4f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2021-12-17 10:38:49 +01:00
Thiago Macieira
4631b61c81 Q_{APPLICATION,GLOBAL}_STATIC: use variadic macros
We can't remove Q_GLOBAL_STATIC_WITH_ARGS, for compatibility reasons.
It's also the only way to pass uniform initialization (i.e., initialize
the value as value{with_braces}), though I don't think this is used
almost anywhere due to the fact that you couldn't pass more than one
argument. But Q_APPLICATION_STATIC is new in 6.3, so we have time to
change it.

[ChangeLog][QtCore][QGlobalStatic] The Q_GLOBAL_STATIC macro is now
variadic. Any extra arguments are used as constructor arguments,
obliterating the need to use Q_GLOBAL_STATIC_WITH_ARGS().

Pick-to: 6.3
Change-Id: Ib42b3adc93bf4d43bd55fffd16be3656a512fe53
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-17 07:56:24 +00:00
Marc Mutz
48b4f144e7 QRingBuffer: simplify QRingChunk special member functions [2/2]
Use NSDMI and let the compiler generate the default ctor, too.

Statically assert that it's still noexcept (we marked it as such,
because MSVC still doesn't noexcept(auto) when an SMF is =default'ed.

Simplify the other ctors, too, relying on NSDMI. Keep one instance of
tailOffset(0), in the 'reserving' ctor, because it's inconsistent with
the other ctors which all do tailOffset{chunk.size()}, so it's best to
leave this explicit, lest the next reader wonders whether it was
forgotten.

Pick-to: 6.3
Change-Id: I0d9f91aa5bc89377c4144589df8786b502e956a4
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-17 07:52:40 +00:00
Dimitrios Apostolou
38e7b5dcd6 Blacklist flaky tst_qgraphicswidget:initialShow on OpenSUSE
Task-number: QTBUG-98921
Change-Id: Ie2c3bed56fdd548a54035565639803c19819d4be
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-12-17 07:03:26 +01:00
Dimitrios Apostolou
725fc4da44 Properly indent qtestlib's XML output
Also regenerate the expected output for tst_selftests, to match new
output. Changed one line source code in tst_seftests for the
same purpose.

Change-Id: I930ba4bb290568d6f67a8910a781725f01f08bf1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-17 07:03:26 +01:00
Dimitrios Apostolou
df0351836e Fix helper script to run successfully on X11
Without the fix, some tests from tst_selftests were failing with:

Invalid MIT-MAGIC-COOKIE-1 key

Change-Id: I2d07f28d9b2c69fe8575fdf10b362d962f456970
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-17 07:03:25 +01:00
Yuhang Zhao
18bc5d652f Windows QPA: Enhance debug information
https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos

Change-Id: I54392b36c52c4318c0d2d5489bbfd582ff7bccb3
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
2021-12-17 13:18:22 +08:00
Marc Mutz
dc1c0536bb QByteArray: optimize replace() a bit
These days, we perform the alias check unconditionally, so the remainder of the function can assume that *this and after do not overlap. So memcpy() suffices, we don't need memmove().

Pick-to: 6.3 6.2
Change-Id: Ib6966facfe643b0aaf50d902709f5fe926bed527
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-17 03:20:22 +01:00
Marc Mutz
572b55baa4 tst_QIODevice: fix UB (precondition violation) in SequentialReadBuffer::readData()
memcpy() mustn't be called with a nullptr, even if the size is zero.

Fixes ubsan error:

   tst_qiodevice.cpp:561:15: runtime error: null pointer passed as argument 1, which is declared to never be null

Even though ubsan only complained about one of them, fix all three
occurrences of the pattern in the test.

Pick-to: 6.3 6.2 5.15
Change-Id: I5c06ab4a20a9e9f8831392c46c6969c05248fdac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-16 23:25:47 +01:00
Marc Mutz
b1938e5787 tst_QByteArray: fix UB (signed overflow)
The first case is simple, as it's a static overflow. Theoretically,
the compiler would be allowed to just remove the complete function as
dead code. This is an error left from the port from int to qsizetype:
Qt 5.15 there has uint(MaxAllocSize) + 1, so use quint here again,
qint64 is wrong.

In the second case, we _may_ reach alloc == MaxAllocSize. Check that,
if we do, we don't then add 1 to it.

Pick-to: 6.3 6.2
Change-Id: I93044ed6f1b77559642fa1e4e8f313cf59eeeb79
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-16 23:25:47 +01:00
Alexandru Croitor
cc6185fb2b coin: Fix sccache to be used when cross-compiling tests
Was likely an oversight.

Amends 9f559699cc

Pick-to: 6.2 6.3
Change-Id: I13c2e4cc32e68c1ce98f59a932e3448250b0679b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-16 19:44:13 +01:00
Tatiana Borisova
4aea86f5e8 Fix autotest runtime failures on INTEGRITY
- add test resources to binaries
- link Qt::Gui to tst_qpointer for static build case

Task-number: QTBUG-99123
Pick-to: 6.2 6.3
Change-Id: I311827b9c641eaf9537091b051c15f9fcbcb9f0c
Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-16 19:45:08 +02:00
Tatiana Borisova
387797e923 Fix INTEGRITY runtime qobject issue
- There is no space symbol in the expression evaluation by GHS compiler.
  Because of space in prefix constant, begin pointer is moved too far and
  skips 1 letter in the class name. In result, on testing stage we see:

  I/O: FAIL!  : tst_QObject::property() Compared strings are not the same
  I/O:    Actual   (property.typeName())    : ropertyObject::Alpha
  I/O:    Expected ("PropertyObject::Alpha"): PropertyObject::Alpha

Pick-to: 6.2 6.3
Change-Id: I52759860fd26b8d50df96dcc4ab0a6b005329a9f
Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-16 19:45:08 +02:00
Marc Mutz
0d91ad44a7 tst_qmetatype: remove traces of compiler workarounds again
Now that all platforms can deal with the full tst_QMetaType again,
remove the last traces of the workaround.

Pick-to: 6.3
Change-Id: I530cab8413f8b68903991b30a1f29b5871877a88
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-16 18:45:08 +01:00
Marc Mutz
795e7dd091 QString: scope a loop variable correctly
The variable idx isn't used outside the respective loops, so make it loop-local.

Change-Id: I62807cb244b068ce4df42812a0e4b99a1f488adc
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
2021-12-16 18:45:07 +01:00
Marc Mutz
6830bdc140 QString: fix UB (pointer arithmetic on nullptr) in qLastIndexOf
Says ubsan:

  qstring.cpp:10484:17: runtime error: applying non-zero offset 18446744073709551614 to null pointer

If we search for a null needle, we stored 0-1 in a size_t variable and
unconditionally appied that offset to the needle's data() pointer. That
being the nullptr, ubsan complained.

To fix, set sl_minus_1 to 0 if it would underflow. In that case,
sl_minus_1, n, and h, are not used, anyway, so their values don't
matter as long as we don't invoke UB.

Pick-to: 6.3 6.2 5.15
Change-Id: Idca4e845c77838dfc84acdb68bbbc98382b5e1d5
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-16 18:45:07 +01:00
Lars Knoll
d1626ca6b0 Fix hash lookup using the value of a key iterator
QHash::operator[] could grow the hash even if the key being
looked up already existed. This in turn invalidated all iterators.
Avoid this by refactoring findOrInsert() to not grow if the key
already exists.

Added advantage is that this should make lookups of existing keys
slightly faster.

Fixes: QTBUG-97752
Pick-to: 6.3 6.2
Change-Id: I9df30459797b42c434ba0ee299fd1d55af8d2313
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-16 18:44:01 +01:00
Thiago Macieira
19d231e47d QThread::idealThreadCount: use the thread affinity set
Instead of returning the total number of logical processors in the
system, which we may not be allowed to wholly run on, use the affinity
set that the calling thread is allowed to use.

Implemented for Linux and FreeBSD only, with up to 4x the number of
processors than CPU_SETSIZE has as default (that would be 4096 logical
processors on Linux, 1024 on FreeBSD). Implementation for Windows is
possible, but the API there is always limited to 64, so I'm unsure if it
is correct. Darwin (macOS) does not have this capability.

Testing:

 $ ./tst_qthread idealThreadCount | grep QDEBUG
QDEBUG : tst_QThread::idealThreadCount() Ideal thread count: 8
 $ taskset 3 ./tst_qthread idealThreadCount | grep QDEBUG
QDEBUG : tst_QThread::idealThreadCount() Ideal thread count: 2

[ChangeLog][QtCore][QThread] idealThreadCount() will now return the
number of logical processors that the current process (thread) has
assigned in its affinity set, instead of the total number of processors
in the system. These two numbers can be different if the process is
launched by the parent with a different affinity set, with tools like
Linux's taskset(1) or schedtool(1). This is currently implemented for
Linux and FreeBSD.

Change-Id: I2cffe62afda945079b63fffd16bd086f64f5f314
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-16 09:24:26 -08:00
Thiago Macieira
c54fb03446 QGlobalStatic: don't use a std::aligned_union if we can be a union
Simplifies further the code with C++11 unrestricted unions.

Pick-to: 6.3
Task-number: QTBUG-99122
Change-Id: Ib42b3adc93bf4d43bd55fffd16c0b6677441bf55
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-16 17:24:26 +00:00
Volker Hilsheimer
e832a805c1 QCache: remove dead code
The Node::replace overloads and the Node::create method are not used
anywhere (including in QHash).

Pick-to: 6.2 6.3
Change-Id: I1f1f8c847c8f1181cd31d95d01997226f94b5fc4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-12-16 14:02:28 +01:00
Marc Mutz
735e2f787a QRingBuffer: simplify QRingChunk special member functions [1/2]
Let the compiler generate the copy and move SMFs.

Statically assert that the move SMFs are still noexcept.

Pick-to: 6.3
Change-Id: I1c569bdf893a5f2cda972c0dd8196cab62494fcb
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-16 12:47:39 +01:00