|
13 | 13 |
|
14 | 14 | // The layout has changed between Qt 5 and Qt 6
|
15 | 15 | //
|
16 |
| -// Qt5 QVariant has one member, which contains three uints and a union. |
17 |
| -// The three uints are optimised to a reduced size, resulting in a combined size |
18 |
| -// of two pointers. |
19 |
| -// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v5.15.6-lts-lgpl#n491 |
20 |
| -// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v5.15.6-lts-lgpl#n411 |
21 |
| -// |
22 | 16 | // Qt6 QVariant has one member, which contains three pointers and a union
|
23 |
| -// (with a pointer as the largest member) |
| 17 | +// (with a pointer / double as the largest member) |
24 | 18 | // https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v6.2.4#n540
|
25 | 19 | // https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v6.2.4#n474
|
| 20 | +// |
| 21 | +// Qt5 QVariant has one member, which contains three uints and a union |
| 22 | +// (with a pointer / double as the largest member) |
| 23 | +// The three uints are optimised to a reduced size of ushorts |
| 24 | +// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v5.15.6-lts-lgpl#n491 |
| 25 | +// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.h?h=v5.15.6-lts-lgpl#n411 |
26 | 26 | #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
| 27 | + |
| 28 | +#if (QT_POINTER_SIZE == 4) |
| 29 | +// 32bit is 3 * 32bit ptr (12) + union with double (8) + 4 bytes padding |
| 30 | +// alignment is 8 byte on 32bit systems as well due to the double |
27 | 31 | assert_alignment_and_size(QVariant,
|
28 |
| - alignof(::std::size_t), |
29 |
| - sizeof(::std::size_t[4])); |
| 32 | + alignof(double), |
| 33 | + (sizeof(::std::size_t) * 3) + sizeof(double) + |
| 34 | + 4 /* compiler padding */); |
30 | 35 | #else
|
| 36 | +// 64bit is 3 * 64ptr ptr (16) + union with double (8) |
| 37 | +// alignment is 8 bytes from the double or the pointer on 64bit systems |
31 | 38 | assert_alignment_and_size(QVariant,
|
32 |
| - alignof(::std::size_t), |
33 |
| - sizeof(::std::size_t[2])); |
| 39 | + alignof(double), |
| 40 | + (sizeof(::std::size_t) * 3) + sizeof(double)); |
| 41 | +#endif |
| 42 | + |
| 43 | +#else |
| 44 | + |
| 45 | +// 3 * uint (12) + union with double (8) |
| 46 | +// but due to compiler optimisation it ends up as |
| 47 | +// 3 * ushort (6) + union with double (8) + 2 bytes padding |
| 48 | +// alignment is 8 byte on 32bit systems as well due to the double |
| 49 | +assert_alignment_and_size( |
| 50 | + QVariant, |
| 51 | + alignof(double), |
| 52 | + (sizeof(::std::uint16_t /* compiler optimised from ::std::uint32_t */) * 3) + |
| 53 | + sizeof(double) + 2 /* compiler padding */); |
| 54 | + |
34 | 55 | #endif
|
35 | 56 |
|
36 | 57 | static_assert(!::std::is_trivially_copy_assignable<QVariant>::value);
|
|
0 commit comments