10324df60e
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> |
||
---|---|---|
.github/workflows | ||
bin | ||
cmake | ||
coin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
libexec | ||
LICENSES | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.cmake.conf | ||
.gitattributes | ||
.gitignore | ||
.lgtm.yml | ||
.tag | ||
CMakeLists.txt | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.cmake | ||
dependencies.yaml | ||
qt_cmdline.cmake |