Commit Graph

42050 Commits

Author SHA1 Message Date
Thiago Macieira
00fbc087dd Inline the size and data pointers in QByteArray
Change-Id: I82feeb2c9bd2900f421fc0c8d78698b1e83db043
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 18:20:04 +01:00
Lars Knoll
e58b44d557 Change representation of string data in the meta object
Don't store our string data as QByteArrayLiterals anymore, but revert
back to simply storing them as an array of char* and offsets into that
array.

This is required to be able to inline size and begin into QByteArray
itself. Once that change is done, we can then avoid creating copies of
the string data again.

Change-Id: I362a54581caefdb1b3da4a7ab922d37e2e63dc02
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 18:19:58 +01:00
Thiago Macieira
746ab4bbd6 Inline the size and data pointer members in QString
I'd have preferred to use QArrayDataPointer<ushort> for QString, but
that option wasn't the best one. QArrayDataPointer try to do some
operations using QArrayDataOps and that would expand to unnecessary
code. What's more, the existing code expected to be able to modify and
access the d pointer.

Instead, this commit introduces QStringPrivate (named differently from
QStringData to catch potential users), which contains the three
members. This POD class is also used in QJsonValue to store the
"inlined" QString. QHashedString in qtdeclarative will need a similar
solution.

Change-Id: I33f072158e6e2cd031d4d2ffc81f4a8dbaf4e616
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 18:19:50 +01:00
Thiago Macieira
b42a2b3c33 Inline the size and begin pointer in QVector
Add QGenericArray to simplify operations. This class can be shared by
other tool classes. If there is nothing else to share it, we can move
the code onto qvector.h. The one candidate is QList.

All tests pass and valgrind is good.

Change-Id: Ieaa80709caf5f50520aa97312ab726396f5475eb
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 18:19:38 +01:00
Lars Knoll
3d9bae304c Fix potential out of bounds write in the JSON writer
If a small string (1 or 2 chars) would require a JSON escape sequence
when writing out the string, the code could write out of bounds of the
byte array. Fix that by always allocating at least 16 bytes of space.

Change-Id: I4d023e7ed837b25b0a5dcf6cfaaf94aa55695b9f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2019-12-08 10:30:10 +01:00
Lars Knoll
37e054993b Get rid of the operator[](uint) overloads
Those make no sense and where probably only there to workaround
bugs in some old compilers.

Change-Id: I5b196cc5306ac1c6307257b70179278d82d383c1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2019-12-08 10:30:02 +01:00
Thiago Macieira
4802f96d4d Various cleanups in qarraydataops and qarraydatapointer
Various cleanups. Add copyAppend overload for forward iterators and a
insert overload for inserting n elements.

Change-Id: Ic41cd20818b8307e957948d04ef6379368defa55
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:56 +01:00
Thiago Macieira
443aaa6dec Remove bad test in QVector
This test hardcodes the allocation behaviour instead of testing what
it should be testing. Unfortunately, it can't test the actual problem
directly since the problem was "it crashed when using vectors with 1
billion elements".

Change-Id: Iec6a26ae490b8fdd4a7db1269e3bae85fc77ee52
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:49 +01:00
Thiago Macieira
add048bc4e Start moving QArrayData's size and data pointer to the main class
This requires that the allocation functions return two pointers: the d
pointer and the pointer to the actual data.

Ported QArrayDataPointer & SimpleVector to the inlined size & data.

For now, the size and offset members are not yet removed from
QArrayData, to let QVector, QByteArray and QString compile unmodified.

Change-Id: I8489300976723d75b8fd5831427b1e2bba486196
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:42 +01:00
Thiago Macieira
f2569c0ff7 Add QArrayDataOps::moveAppend()
Same as copyAppend() but calls the move constructor

Change-Id: I7de033f80b0e4431b7f1ffff13f9399e39b5fee4
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:33 +01:00
Thiago Macieira
8f3189f7a2 Add the QArrayDataOps::parameter_type typedef
It's a typedef meant to replace the "const T &" parameters (hence the
name). But it's actually just a T for POD types, so we don't create
references to them.

Change-Id: I10c746d5e852c957ec84319712597478c4dc872c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:25 +01:00
Thiago Macieira
812a611dc0 Stop using the reference counter to store data state
Instead of using the reference count to store whether the data is
sharable and whether the header is immutable, move the settings to the
flags member. This allows us to save one comparison per deref() or
needsDetach(). It also allows for the possibility of mutable data
pointed to by a static header.

Change-Id: Ie678a2ff2bb9bce73497cb6138b431c465b0f3bb
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:17 +01:00
Thiago Macieira
62c673ccc6 Add reference-count manipulation functions to QArrayData and hide ref
The next change will stop using some values in the reference counter as
settings from the data.

Change-Id: I94df1fe643896373fac2f000fff55bc7708fc807
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:09 +01:00
Thiago Macieira
a3aa2fcfa7 Introduce the Mutable flag and move QArrayDataPointer::needsDetach
The Mutable flag now contains the information on whether the data this
QArrayData points to is mutable. This decouples the mutability /
immutability setting from the allocation and from the type of data,
opening the way for mutable raw or foreign data.

There are still plenty of places in the source code that check the
size of the allocation when it actually wants d->isMutable(). Fixing
this will require reviewing all the code, so is left for later.

The needsDetach() function is moved to QArrayData and
de-constified. It returns true when a reallocation is necessary if the
data is to be modified.

Change-Id: I17e2bc5a3f6ef1f3eba8a205acd9852b95524f57
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:29:01 +01:00
Thiago Macieira
b6aa133cf5 Make the AllocOptions flag to QVector::reallocData mandatory
This forces us to calculate the reallocation flags properly.

Change-Id: I3486b193ad6732df666fc9ddad96831c9fbe068c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-08 10:28:53 +01:00
Lars Knoll
cde2fde3f0 Fix a use-after-free problem in QByteArray::replace
if the string pointed to by after is part of the QByteArray, we
were trying to protect against a use-after-free by copying
after. Unfortunately, it was not used later on in the code instead
of the original after.

Change-Id: I2f2263e4bb1855e802bba2fc08db34762c66887a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:18:35 +01:00
Lars Knoll
551c665b7d Remove unused private method
Change-Id: I3502c3c0451e7829fff0159a5d0891df34d04fe7
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-12-07 14:18:28 +01:00
Thiago Macieira
f6a151024b Introduce flags to indicate the QArrayData type
These flags allow us to determine what type of data QArrayData is
carrying. There are currently only two supported types:
 - raw data type: constructed via fromRawData or static data
 - allocated data type: regular data done via heap allocation

The QArrayData object is usually allocated on the heap, unless its own
reference count is -1 (indicating static const QArrayData). Such
object should have a type of RawDataType, since we can't call free().

Add GrowsBackward for completeness as well as the StaticDataFlags
default for static data.

Change-Id: Icc915a468a2acf2eae91a94e82451f852d382c92
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:18:19 +01:00
Thiago Macieira
8fb45ae5b8 Introduce QArrayData::allocatedCapacity() and use it instead of d->alloc
In almost all cases, use d->allocatedCapacity() or
d->constAllocatedCapacity() instead of d->alloc, since they do the
same thing (right now). In the future, the functions will be
changed. There is a separate const version because most const code
should not need to know the allocation size -- only mutating code
should need to know that

There are a few cases where d->alloc was replaced with a better
alternative, like d->size. The one case that remains in the code will
be replaced by a different test when it's available.

Change-Id: I48135469db4caf150f82df93fff42d2309b23719
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:18:12 +01:00
Thiago Macieira
64db4861bf Replace QArrayData::capacityReserved with a full flags field
Instead of stealing one bit from the alloc field, let's use a full
32-bit for the flags. The first flag to be in the field is the
CapacityReserved (even though the allocate() function will store some
others there, not relevant for now).

This is done in preparation for the need for more flags necessary
anyway.

Change-Id: I4c997d14743495e0d4558a6fb0a6042eb3d4975d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:18:04 +01:00
Thiago Macieira
bf0b4f332a Rename QArrayData::AllocateOptions enum and update some flags
Rename to QArrayData::ArrayOptions in preparation for these flags
being in the array itself, instead of used just for allocating new
ones.

For that reason, rename QArrayData::Default to
DefaultAllocationFlags. And introduce QArray::DefaultRawFlags to mean
the flags needed for creating a raw (static) QArrayData.

Also rename QArrayData::Grow to GrowsForward, so we may add
GrowsBackward in the future.

Change-Id: I536d9b34124f775d53cf810f62d6b0eaada8daef
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:17:55 +01:00
Thiago Macieira
41287d355b Add QArrayData::sharedNullData()
Just to simplify a few operations, like detecting when a QChar* or char*
coming from a QString or QByteArray, respectively, were null data.

While you're not supposed to dereference the pointer returned by
QVector::data() unless you know that the array is non-empty, that is
permitted for QString and QByteArray. That is, QString().constData()
must return a valid pointer to a null QChar.

Change-Id: I80b4b62f203dc841e5c99c20c51d92ca576e4bfe
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:17:45 +01:00
Thiago Macieira
329ec3a268 Tell the compiler that QArrayData::allocate allocates memory
ICC, GCC and Clang support __attribute__((malloc)) that tells them that
the function returns newly allocated memory which doesn't alias anything
else. Though technically we may return memory that has already been used
(the shared null or such), that should not be a problem.

Change-Id: Id3d5c7bf4d4c45069621ffff13f7f81f8b08ea3d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:17:31 +01:00
Thiago Macieira
d7e7befe50 Tell the compiler that QArrayData returns aligned pointers
GCC 4.9 and later support the __attribute__((alloc_align)) attributes
that indicate the alignment of the data. To make it work on GCC since
4.7 and Clang as of 3.6, we instead use __builtin_assume_aligned(). I
don't know which version of ICC first implemented this, but ICC 15 does
and it also reports itself as GCC 4.9.

Change-Id: I58bd914b9bdd0ed3349ba56fa78220ab06114852
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-12-07 14:17:23 +01:00
Lars Knoll
a07925576a Fix qChecksum test
The test passed mostly by accident so far, as the created QByteArray
was shorter than what the test assumed.

Change-Id: I06858801d83a504eadc73ec2be281c88f8ffad5d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2019-12-07 14:17:16 +01:00
Olivier Goffart
cedf0207d1 Use Q_NAMESPACE for the Qt namespace, and remove the old moc hack to support it
Since I can't #include qobjectdefs from qnamespace because of circular dependency,
move the Qt macro in the qtmetamacros.h header.

Deprecate QObject::staticQtMetaObject since now one can just use Qt::staticMetaObject

Change-Id: I11982aa17c2afa2067486b113f8052672f3695eb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2019-12-06 20:29:15 +00:00
Olivier Goffart
b0498b1864 Fix tst_moc for C++17
The throw() specification is no longer accepted in C++17 mode, so remove that.

Also pass the -std=c++1z to the compiler as Qt is going to require C++17 soon

Change-Id: I6d249e574d90cd1cf5c0ea595830d2db07681050
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-12-06 16:19:27 +01:00
Andrew Patterson
d8fa009a15 Make setModel() virtual
Task-number: QTBUG-74255
Change-Id: I354e547dd75019a964f4b8e4f087a72e610816f3
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2019-12-06 06:23:44 -05:00
Qt Forward Merge Bot
2625d2713c Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I9d63a4c4b229a831b5369f6ec74ac97ba6d6556a
2019-12-05 01:00:44 +01:00
Olivier Goffart
8652c79df0 Remove QVariant::operator< and related operator
The operator does not have a total order

Change-Id: Ifd263c3495aca08c8ccceb9949596c308a76a6c1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-12-04 17:37:52 +01:00
Volker Hilsheimer
de6520805a Document that toggleViewAction can't be used to toggle the dock widget
...from code.

This is by design; the action is updated when the dock widget changes,
not the other way around (which would easily result in infinite loops).

Change-Id: I9e71784d239a9cbb6c8efaeaa3e3adc6dc590f65
Fixes: QTBUG-80022
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
2019-12-04 16:33:02 +01:00
Qt Forward Merge Bot
0c29ebe374 Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I4134c0c6b6c9911950f58b3b5c86e789d28a185b
2019-12-04 01:00:23 +01:00
Qt Forward Merge Bot
d025c1a75f Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: Ia70e81943ef097941339f9ef9ace28592a2eb740
2019-12-04 01:00:07 +01:00
Edward Welbourne
dc7fa56948 QMacTimeZonePrivate: use .member rather than [- member] notation
Apparently this is our preferred style for Objective C member references.

Change-Id: I8b2bbaabadbea2cfa74f209372e77cee79e3c895
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2019-12-03 19:00:22 +01:00
Edward Welbourne
deb166a5ff Make QMacTimeZonePrivate default constructor more efficient
Inline systemTimeZoneId() in it to save the need for init().
We thus save the lookup by name for a time-zone object, when that
object is what we took the name from anyway.

Do some minor tidy-up in the other constructors and add an assert to
systemTimeZoneId() to match the new one in the default constructor.

Change-Id: Ib70acf31bdb4a4fa1306eebd1fd5f00ad6b89bcc
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2019-12-03 18:59:58 +01:00
Timur Pocheptsov
e5438e8ded QSslSocket (OpenSSL) improve alert messages handling
1. Add a new verification callback. This gives an option
to report errors directly from this callback (by emitting
handshakeInterruptedOnError()). This allows an application
to explain to its peer why the handshake was interrupted (by
sending a corresponding alert message).
2. This also means we want to notice such alerts (in Qt,
from the application's point of view, they are mostly
informational only, no interaction is required). So we
also introduce a new 'info callback', that can notice alert
messages read or written. We also introduce two new enums
describing the level and type of an alert message. QSslSocket
gets three new signals (for incoming/outgoing alerts and
verification errors found early).
3. In case we requested a certificate, but the peer provided
none, we would previously abruptly close the connection without
a proper alert message (and such a situation is not handled
by any verification callbacks, since there is no certificate(s)
to verify essentially). So we now introduce a new verification
option that maps to what OpenSSL calls 'SSL_VERIFY_FAIL_IF_NO_PEER_CERT'.
This way, the proper alert will be generated.

Fixes: QTBUG-68419
Change-Id: I5d1e9298b4040a2d4f867f5b1a3567a2253927b8
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-12-03 18:06:02 +01:00
David Faure
9f79ab360f Fix assert in QTextDocument CSS parser on "border-width: 1pt"
The code was assuming that if the parsing of the value worked,
then it must be a list of 4 variants. But in this case it's just
a single length.

This came from <td> using 4 values for border-width
while other elements use a single value. But the storage
is shared. So the fix is to use 4 values everywhere.
When reading 4 and there's only one, it gets duplicated,
so the caller can just use the first one in that case.

Task-number: QTBUG-80496
Change-Id: I682244b6e3781c4d673a62d5e6511dac263c58e8
Reviewed-by: Nils Jeisecke <nils.jeisecke@saltation.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-12-03 17:54:24 +01:00
Volker Hilsheimer
e4d1a03df0 QMacStyle: correct placement of edit field in combobox
The dark edit field is now centered within the frame around it, with a
thin border on all sides, including between input field and button.

Change-Id: I27e853289e9048c21fdc81e45fadacba9665b49e
Fixes: QTBUG-63454
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2019-12-03 17:06:39 +01:00
Volker Hilsheimer
2ed59f0d42 QMdiArea: on macOS using tabs, render document icons next to the text
This is closer to what titles of documents look like in macOS apps,
even though MDI is not a well-defined concept on this platform.

To implement this, the QCommonStylePrivate::tabLayout method had to be
made virtual, as it is called by the QCommonStyle class. It was already
reimplemented in QMacStylePrivate, but didn't get called in all cases.
Now that it is called as an override, adjust the icon placement to
include the padding so that we get identical results to 5.13 for
normal tab widgets.

Change-Id: I7a63f6d76891146ca713259096a7737a86584d81
Fixes: QTBUG-63445
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2019-12-03 17:06:12 +01:00
Morten Johan Sørvig
4d796cbf17 Prevent emscripten_webgl_destroy_context from removing event handlers
The JavaScript implementation of that function has
the following code:

  if (typeof JSEvents === 'object')
    JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all
    // JS event handlers on the DOM element that the GL context is associated with since the context
    // is now deleted.

This breaks mouse/keyboard events, etc.

Disable this logic by temporarily setting the JSEvents object
to undefined, for the duration of the emscripten_webgl_destroy_context
call.

Fixes: QTBUG-74850
Change-Id: Ied3177b0ca6e63e8ea07143bf7d6a850b0bce35a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2019-12-03 14:54:15 +00:00
Laszlo Agocs
c625d92385 Fix depth in renderText()
Fixes: QTBUG-31156
Change-Id: I3cbb3f9c5dfbcb182dbe283b0bf0f05a031970a5
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
2019-12-03 13:51:28 +01:00
Kai Koehne
b6632443d4 CMake: Use lower-case macro/function names
CMake is case-insensitive for macro and function names. Still, it is
"strongly recommended to stay with the case chosen in the function
definition." So let's make the function and macro definition lower-case,
like we also recommend in the documentation.

Change-Id: I1f64b18716f034cb696d2e19a2b380aaadd6cd07
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-12-03 12:51:10 +01:00
Edward Welbourne
580fd2dbd3 Relocate a comment that had become detached from its code
Two little tool functions had come between it and the function it
actually describes.

Change-Id: Ib49d1623833275ea79c7916fece29aed9503aa40
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2019-12-03 12:28:37 +01:00
Joni Poikelin
8310d636be Fix serializing QUuid with QDataStream with Qt 4 stream versions
Fixes: QTBUG-76103
Change-Id: Iac92c33539940f5f67d014db5240c6dc14bfb772
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-12-03 13:28:22 +02:00
Laszlo Agocs
443ef0010a rhi: Remove unused compat functions
These were kept around to keep Qt Quick compiling, but the
migration there has been done a long time ago. Remove these
leftovers now.

Change-Id: Ibd47381b410b11b5475a85c7ed3cb05c22f7adbb
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
2019-12-03 12:15:26 +01:00
Kai Koehne
fea316cbe7 CMake: Remove conditions for CMake < 3.1
We don't support anything older than CMake 3.1

Change-Id: I5425a2fddfe5416a6a127a81da669fb37ac4d81c
Reviewed-by: Liang Qi <liang.qi@qt.io>
2019-12-03 10:28:50 +01:00
Ulf Hermann
25bcd8f08b Merge "Merge remote-tracking branch 'origin/5.14' into 5.15" 2019-12-03 06:58:19 +01:00
Heikki Halmet
ad1810e321 Blacklist tst_QNetworkInterface::localAddress(linklocal-ipv4) on Windows
This will blacklist this test for ci. Currently blocking enabling tests
for MSVC2019

Task-number: QTBUG-65667
Task-number: QTQAINFRA-2875
Change-Id: I7198490b1529ce2f4409bfa7399031dad7644a06
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Heikki Halmet <heikki.halmet@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2019-12-03 05:57:26 +00:00
Ulf Hermann
e62d04b933 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/corelib/serialization/qcborvalue.cpp

Change-Id: I675a3029955c96e81a33ed9d98b72b55b6784b52
2019-12-03 06:57:05 +01:00
Tor Arne Vestbø
9ac156c90b iOS: Guard against request for textInputView without focus window
Change-Id: I7b8df07fffef1cc948f6720685234540a20ccc81
Fixes: QTBUG-79316
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2019-12-03 01:14:58 +01:00