summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonarray.h
Commit message (Collapse)AuthorAgeFilesLines
* Mark QJson and QCbor classes as security-criticalMarc Mutz2025-06-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These components process input external to the process, and the application depends on these components to report errors to detect failure, so these components are security-critical. The writers are, too, because a valid use of the classes is to stream-read something, filter or edit a few nodes, and then stream back, in which case writers see the same input as the readers, only in reverse, and have to build a valid output. Where there's doubt whether a header should be considered critical or not, err on the side of critical. We can always revisit the decision later when we know what semantics we'll attach to this marking. Where a header only contains declarations (and class definitions), mark as significant with reason "header, declarations only". It is probably a good idea to avoid any non-trivial inline code in headers whose .cpp files are security-critical, but moving all inline code out-of-line is a task for a different patch. Amends 8df072fc8006510c9b743e8ffedaaf51a876883a. QUIP: 23 Task-number: QTBUG-135194 Pick-to: 6.10 6.9 6.8 Change-Id: Ie317c4df652430e6e68954c37d553b760836dff8 Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
* QJson: Remove QT_JSON_READONLYThiago Macieira2025-01-171-1/+1
| | | | | | | | | | | moc (and thus the bootstrap library) has needed JSON output since Qt 5.15 (commit da284ef10e0ef80776b9fc9b7bb0e6dc8d71ba63 "Add support for machine-readable JSON output to the MOC"). Pick-to: 6.9 Change-Id: I4b8cf51c092eb35cc383fffd48d120f0cb2c56b0 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Johannes Grunenberg <nerixdev@outlook.de>
* serialization: remove incorrect noexcept on comparison operators [2/2]Ivan Solovev2024-08-301-9/+9
| | | | | | | | | | | | | | | | | This patch is about removing noexcept on functions that use Q_ASSERT. The argument is that in these cases Q_ASSERTs act as precondition checks, so we should probably follow the Lakos rule. Although, technically the change is fine, because the current implementation of Q_ASSERT is marked as noexcept(true), there are some ideas of changing that in future, so we should not be setting in stone something we can't change later. Found in 6.8 API review. Pick-to: 6.8 Change-Id: I1d4aa228c713821c0ebbfc0f3b956d29fe652ed8 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* serialization: remove incorrect noexcept on comparison operators [1/2]Ivan Solovev2024-08-281-4/+4
| | | | | | | | | | | | | | | | | | | | QJsonValue comparison cannot be noexcept, because it might allocate, for example when calling QCborValue::toString(). As a result, all the QJsonValue(Const)Ref comparison operators also cannot be noexcept, because they convert to QJsonValue to do the comparison. QJsonObject comparison cannot be noexcept, because it might call QCborValue::makeValue(), which might allocate. QJsonArray comparison cannot be noexcept, because it might also call QCborValue::makeValue(), which might allocate. Found in 6.8 API review. Pick-to: 6.8 Change-Id: I775746b2a76765bca26b87d5af396a8dfdfca7f9 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJsonArray iterators: use new comparison helper macrosTatiana Borisova2024-03-261-9/+84
| | | | | | | | | | | | | | | | New comparison macros are used for following classes: - QJsonArray::iterator - QJsonArray::const_iterator Replace public operators operator==(), operator!=(), operator!<(), etc of classes to friend methods comparesEqual(), compareThreeWay(); Use *_helper methods to have an access to protected members of QCborValueConstRef class from friend functions. Task-number: QTBUG-120300 Change-Id: I9b41b619107ce69d8b6dab4938232fab841aab51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJsonArray: use new comparison helper macrosTatiana Borisova2024-03-211-1/+10
| | | | | | | | | | | | | | | | | Replace public operators operator==(), operator!=() of QJsonArray to friend methods comparesEqual(). Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Add friend method comparesEqual(QJsonArray, QJsonValue) to the QJsonArray class, to support comparison between QJsonArray and QJsonValue elements, see test-case fromToVariantConversions() Task-number: QTBUG-120300 Change-Id: I8440ca0761bede8551ff792bfa7f22e47b56fa79 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVariant: make many more QtCore types nothrow-copyableThiago Macieira2022-07-301-2/+2
| | | | | | | | | | | | | | | All of those are implicitly-shared Qt data types whose copy constructors can't throw and have wide contracts (there aren't even any assertions for validity in any of them). These are all types with a QVariant implicit constructor, except for QCborValue, which is updated on this list so QJsonValue (which has a QVariant constructor) is also legitimately noexcept. To ensure we haven't made a mistake, the Private constructor checks again. Change-Id: I3859764fed084846bcb0fffd17044d8319a45e1f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QJsonValueConstRef: fix null pointer dereferencesThiago Macieira2022-03-181-1/+1
| | | | | | | | | Introduced in commit 705ea62f9e08730793adc7f6cec753c88e66ac4e, but apparently these constructors aren't used anywhere yet. Change-Id: Ic30914a4448d4bc28974fffd16dc521ab49d3be4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonValueConstRef: prepare for Qt 7Thiago Macieira2022-02-151-13/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of storing a pointer to the QJsonArray or QJsonObject (like the Qt 4 & pre-5.15 versions did), do like QCborValueConstRef and store the pointer to the QCborContainerPrivate. Unlike QCborValueRef, we must keep the is_object bit because of API behavior that assigning an Undefined to an object reference deletes it from the container. I've chosen to use size_t instead of qsizetype for this because then we don't lose any bits of the index. Therefore, the index in the case of objects is stored as pair count (like before), different from QCborValueRef which stores the actual index in the QCborContainerPrivate. It's the LSB (on little-endian architectures) so the calculation of 2 * index + 1 is the actual value stored in memory or in the register. Unfortunately, right now, both Clang and GCC don't realize this and generate unnecessary instructions. Clang: 0000000000000000 <QJsonValueConstRef::concreteType(QJsonValueConstRef)>: 0: mov %rsi,%rax 3: shr %rax 6: mov %rsi,%rcx 9: or $0x1,%rcx d: test $0x1,%sil 11: cmove %rax,%rcx [GCC code is identical, except it uses an AND instead of TEST] That OR at offset 9 is a no-op because it sets a bit that is already set in those conditions. At least they don't do unnecessary shifts. Change-Id: I89446ea06b5742efb194fffd16bb7aadb6a9b341 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJson{Array,Object}: rewrite & simplify some iterator functionsThiago Macieira2022-02-151-12/+6
| | | | | | | | | Instead of manipulating indices in multiple functions, make some call the others. This reduces the number of places porting must happen at, if we wanted to. Change-Id: I89446ea06b5742efb194fffd16bb78d24e0528b2 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJsonValueRef: optimize the assignmentThiago Macieira2022-02-151-0/+1
| | | | | | | | | | | | | | | Inline some content to avoid unnecessary round-trips through qcborvalue.cpp, qjsonarray.cpp and qjsonobject.cpp. Unlike the CBOR counterparts, JSON support has this extra functionality that assigning Undefined causes the item to be removed from the object (arrays don't have that behavior, they just become null). And unlike QCborValueRef, we detach on assignment, not on the obtention of the QJsonValueRef. This is more dangerous, so we may want to revise. Change-Id: I89446ea06b5742efb194fffd16bb775e9566ca1a Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJsonValueConcreteRef: optimize concrete()Thiago Macieira2022-02-151-0/+2
| | | | | | | | | | | | Inline the content to avoid a round-trip through qjsonarray.cpp and qjsonobject.cpp. This change revealed an inadviseable unit test check that dereferences the end() iterator to get its type. I haven't changed it, but have marked with ###. I also fixed a likely copy&paste mistake in that test. Change-Id: I89446ea06b5742efb194fffd16bb774f3bfbe5f5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonArray: use QJsonValueConstRefThiago Macieira2022-02-151-7/+8
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6086dcd1d3268 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Make QStringList an alias to QList<QString>Lars Knoll2020-09-121-1/+0
| | | | | | | | | | | | | | | | | | Fix our API, so that QStringList and QList<QString> are the same thing. This required a bit of refactoring in QList and moving the indexOf(), lastIndexOf() and contains() method into QListSpecialMethods. In addition, we need to ensure that the QStringList(const QString&) constructor is still available for compatibility with Qt 5. Once those two are done, all methods in QStringList can be moved into QListSpecialMethods<QString>. Change-Id: Ib8afbf5b6d9df4d0d47051252233506f62335fa3 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use qsizetype for size in QJsonArray and QJsonObjectSona Kurazyan2020-08-181-27/+33
| | | | | Change-Id: I126b7e817f076486910777bb4e3354487ad670cd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Improve the iterators of QJsonArray and QJsonObjectSona Kurazyan2020-07-261-69/+94
| | | | | | | | | Remove the fake QJsonValuePtr and QJsonValueRefPtr required for operator()-> of QJsonArray and QJsonObject iterators. Task-number: QTBUG-85700 Change-Id: I622a5a426edb13b32f9d00a02c3c148320fbccba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean-up some Qt 5 leftovers from JSON serialization classesSona Kurazyan2020-07-221-13/+4
| | | | | Change-Id: I2ddf6901d627677395b39bec34c2c47d27e88d0b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Sweep Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6 -> Q_DECLARE_SHAREDMarc Mutz2020-05-191-1/+1
| | | | | | | | | | | | This is Qt 6, so Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6 is the same as Q_DECLARE_SHARED. Let's hope we'll collectively get better at detecting missing Q_DECLARE_SHARED so we won't need a Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT7 in the future. Change-Id: I3da9faff4c66b64a3b257309012a2a10a6c6d027 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change qHash() to work with size_t instead of uintLars Knoll2020-04-091-1/+1
| | | | | | | | | | | This is required, so that QHash and QSet can hold more than 2^32 items on 64 bit platforms. The actual hashing functions for strings are still 32bit, this will be changed in a follow-up commit. Change-Id: I4372125252486075ff3a0b45ecfa818359fe103b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2019-10-261-18/+8
|\ | | | | | | Change-Id: I379794a01cbf6fb39d94b24cc8c90b1971a212b9
| * Reimplement JSON support on top of CborUlf Hermann2019-10-211-18/+8
| | | | | | | | | | | | | | | | | | | | | | | | In turn, deprecate the QJsonDocument methods that deal with JSON binary data. You should use CBOR for data serialization these days. [ChangeLog][Deprecation Notice] The binary JSON representation is deprecated. The CBOR format should be used instead. Fixes: QTBUG-47629 Change-Id: Ic8b92ea36de87815b12307a9d8b1095f07166db8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Get rid of QList forward declarationsLars Knoll2019-10-041-1/+0
|/ | | | | | | | Include qcontainerfwd.h instead where required. This prepares for unifying QList and QVector. Change-Id: I6c85e2bdd44fb41aedd884b0d551f682760df5b5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove handling of missing Q_COMPILER_INITIALIZER_LISTSAllan Sandfeld Jensen2019-05-021-4/+0
| | | | | | Change-Id: Id65b39c787235a051262544932e6717d076f1ea0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-3/+3
| | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add QJsonArray::cbegin()/cend() methodsLars Knoll2019-01-251-0/+2
| | | | | | | | Add those to be consistent with the rest of Qt and the STL. Fixes: QTBUG-32793 Change-Id: Ib712b7b16b8be6627aeac79b90c6e9cdf92b60e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Implement QJsonArray data stream operatorJędrzej Nowacki2018-10-031-0/+5
| | | | | Change-Id: Ib3c83c06605f0fe39108855bc3416bf453cab043 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* JSON: Add qHash functions for JSON and CBOR typesUlf Hermann2018-08-271-0/+2
| | | | | | | This way we can easily use them as keys in QHash and QSet. Change-Id: Ie744c3b5ad1176ba2ab035c7e650af483757a0c9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Create corelib/serialization and move existing file formats into itThiago Macieira2018-01-261-0/+274
This is in preparation to adding CBOR support. We don't need yet another dir for CBOR and placing it in src/corelib/json is just wrong. Change-Id: I9741f017961b410c910dfffd14ffb9d870340fa6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>