Go to file
Giuseppe D'Angelo 10324df60e QWeakPointer: optimize the converting constructor
The converting constructor of QWeakPointer<T> from a QWeakPointer<X>
needs to adjust the X* received by the "source" to a T*.

In case of non-virtual inheritance, this adjustment can be done
statically, by applying an offset to the pointer. In case of virtual
inheritance, we instead need to dereference the pointer (=access the
pointee), get its vtable, and from there find where (=the offset at
which) the T subobject is located.

This latter scenario requires the pointee to be alive throughout this
operation. Since QWeakPointer isn't an owning smart pointer, it's
perfectly possible that the pointee has already been deleted (the
"source" QWeakPointer<X> is dangling) or is being deleted (e.g. from
another thread that has just released the last QSharedPointer). For
this reason the converting constructor of QWeakPointer employs a
protection: it will lock() itself, and extract the raw pointer from the
QSharedPointer so obtained. This ensures that we won't access a dangling
pointer or a pointee about to be deleted.

We can however limit this (relatively expensive) protection only to the
case where there is virtual inheritance. In the other cases we don't
need it. This commit overloads the converting constructor for
QWeakPointer to deal with the two scenarios separately, and only lock()
in case of virtual inheritance.

Change-Id: I7194b90478cf35024e60cff542091308e4131ec2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-09-26 22:32:51 +02:00
.github/workflows Repair github action workflow 2021-11-10 18:57:33 +01:00
bin Add simple project generation based on existing source files 2023-02-08 12:59:19 +01:00
cmake Remove remnants of Qt for Native Client (NACL) 2023-09-23 13:40:44 +02:00
coin CI: Enable changing chroot in platform config for Debian packaging 2023-09-21 16:16:46 +00:00
config.tests Remove the mandatory x86-64 features from its feature list 2023-05-31 14:55:37 -07:00
dist Add Qt 6.0.0 changes file 2020-11-16 10:02:08 +02:00
doc Docs: Add macros for common Qt products 2023-09-11 07:44:37 +00:00
examples Revamp Local Fortune Server Example: Declare sendFortune() as a method 2023-09-26 19:58:26 +02:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
libexec CMake: Add a config.redo script similar to qt5's config.status 2023-09-20 21:20:13 +02:00
LICENSES Clarify license of SHA-1 algorithm 2023-04-26 16:36:18 +02:00
mkspecs Android: bump Android target API level to 33 2023-09-23 17:38:23 +00:00
qmake Android: bump Android target API level to 33 2023-09-23 17:38:23 +00:00
src QWeakPointer: optimize the converting constructor 2023-09-26 22:32:51 +02:00
tests Long live qxp::is_virtual_base_of 2023-09-26 22:32:51 +02:00
util Remove remnants of Qt for Native Client (NACL) 2023-09-23 13:40:44 +02:00
.cmake.conf CMake: Require CMake 3.21 when building/using Qt on Apple platforms 2023-06-28 22:09:20 +02:00
.gitattributes Give batch files CRLF line endings 2020-11-04 15:02:29 +00:00
.gitignore Add CMakeUserPresets.json to .gitignore 2023-06-23 12:13:08 +02:00
.lgtm.yml Skip LGTM analysis for the bootstrap library and tools 2020-07-16 01:04:34 +02:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
CMakeLists.txt CMake: Fix find_package(Qt6*Tools) in non-qtbase tests 2023-08-23 16:21:58 +02:00
config_help.txt Add coverage and coverage-gcov features 2023-09-22 15:54:30 +02:00
configure CMake: Add a config.redo script similar to qt5's config.status 2023-09-20 21:20:13 +02:00
configure.bat CMake: Add a config.redo script similar to qt5's config.status 2023-09-20 21:20:13 +02:00
configure.cmake Add coverage and coverage-gcov features 2023-09-22 15:54:30 +02:00
dependencies.yaml Re-add dependencies.yaml now that qt5.git wip/qt6 builds fine 2019-09-18 13:19:31 +02:00
qt_cmdline.cmake Add coverage and coverage-gcov features 2023-09-22 15:54:30 +02:00