1364 #if !defined(QT_NO_QOBJECT)
1365 #include "private/qobject_p.h"
1386 if (strongref.loadRelaxed() < 0)
1387 qWarning(
"QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer");
1394 Q_ASSERT_X(!
d->wasDeleted,
"QWeakPointer",
"Detected QWeakPointer creation in a QObject being deleted");
1404 x->strongref.storeRelaxed(-1);
1405 x->weakref.storeRelaxed(2);
1408 if (
d->sharedRefcount.testAndSetOrdered(
nullptr,
x,
ret)) {
1413 Q_ASSERT((
x->weakref.storeRelaxed(0),
true));
1450 # ifdef QT_SHARED_POINTER_BACKTRACE_SUPPORT
1451 # if defined(__GLIBC__) && (__GLIBC__ >= 2) && !defined(__UCLIBC__) && !defined(QT_LINUXBASE)
1452 # define BACKTRACE_SUPPORTED
1453 # elif defined(Q_OS_MAC)
1454 # define BACKTRACE_SUPPORTED
1458 # if defined(BACKTRACE_SUPPORTED)
1459 # include <sys/types.h>
1460 # include <execinfo.h>
1462 # include <unistd.h>
1463 # include <sys/wait.h>
1470 static const int maxFrames = 32;
1473 stacktrace.
resize(
sizeof(
void*) * maxFrames);
1474 int stack_size = backtrace((
void**)stacktrace.
data(), maxFrames);
1475 stacktrace.
resize(
sizeof(
void*) * stack_size);
1480 static void printBacktrace(
QByteArray stacktrace)
1482 void *
const *stack = (
void *
const *)stacktrace.
constData();
1483 int stack_size = stacktrace.
size() /
sizeof(
void*);
1484 char **stack_symbols = backtrace_symbols(stack, stack_size);
1492 dup2(fileno(stderr), fileno(stdout));
1493 dup2(
filter[0], fileno(stdin));
1496 execlp(
"c++filt",
"c++filt",
"-n",
NULL);
1499 execl(
"/bin/cat",
"/bin/cat",
NULL);
1511 output = fdopen(
filter[1],
"w");
1514 fprintf(stderr,
"Backtrace of the first creation (most recent frame first):\n");
1515 for (
int i = 0;
i < stack_size; ++
i) {
1517 fprintf(output,
"#%-2d %s\n",
i, stack_symbols[
i]);
1519 fprintf(output,
"#%-2d %p\n",
i, stack[
i]);
1524 waitpid(
child, 0, 0);
1536 # ifdef BACKTRACE_SUPPORTED
1563 KnownPointers *
const kp = knownPointers();
1574 Q_ASSERT(!kp->dPointers.contains(d_ptr));
1578 const void *other_d_ptr = kp->dataPointers.value(ptr,
nullptr);
1580 # ifdef BACKTRACE_SUPPORTED
1581 printBacktrace(knownPointers()->dPointers.value(other_d_ptr).backtrace);
1583 qFatal(
"QSharedPointer: internal self-check failed: pointer %p was already tracked "
1584 "by another QSharedPointer object %p", ptr, other_d_ptr);
1589 # ifdef BACKTRACE_SUPPORTED
1590 data.backtrace = saveBacktrace();
1593 kp->dPointers.insert(d_ptr,
data);
1594 kp->dataPointers.insert(ptr, d_ptr);
1595 Q_ASSERT(kp->dPointers.size() == kp->dataPointers.size());
1603 KnownPointers *
const kp = knownPointers();
1609 const auto it = kp->dPointers.constFind(d_ptr);
1611 qFatal(
"QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. "
1612 "To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout "
1613 "in your code.", d_ptr);
1616 const auto it2 = kp->dataPointers.constFind(
it->pointer);
1617 Q_ASSERT(it2 != kp->dataPointers.cend());
1622 kp->dataPointers.erase(it2);
1623 kp->dPointers.erase(
it);
1624 Q_ASSERT(kp->dPointers.size() == kp->dataPointers.size());
1633 # ifdef QT_BUILD_INTERNAL
1634 KnownPointers *
const kp = knownPointers();
1635 Q_ASSERT_X(kp,
"internalSafetyCheckSelfCheck()",
"Called after global statics deletion!");
1637 if (
Q_UNLIKELY(kp->dPointers.size() != kp->dataPointers.size()))
1638 qFatal(
"Internal consistency error: the number of pointers is not equal!");
1641 qFatal(
"Pointer cleaning failed: %d entries remaining",
int(kp->dPointers.size()));
small capitals from c petite p scientific i
[1]
The QByteArray class provides an array of bytes.
qsizetype size() const noexcept
const char * constData() const noexcept
void resize(qsizetype size)
The QHash class is a template class that provides a hash-table-based dictionary.
The QMutex class provides access serialization between threads.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
The QObject class is the base class of all Qt objects.
static QObjectPrivate * get(QObject *o)
The QSharedPointer class holds a strong reference to a shared pointer.
QHash< const void *, Data > dPointers
QHash< const volatile void *, const void * > dataPointers
The QVariant class acts like a union for the most common Qt data types.
QMetaType metaType() const
const void * constData() const
The QWeakPointer class holds a weak reference to a shared pointer.
constexpr Initialization Uninitialized
Q_CORE_EXPORT QWeakPointer< QObject > weakPointerFromVariant_internal(const QVariant &variant)
Q_CORE_EXPORT void internalSafetyCheckRemove(const void *)
Q_CORE_EXPORT void internalSafetyCheckAdd(const void *, const volatile void *)
Q_AUTOTEST_EXPORT void internalSafetyCheckCleanCheck()
Q_CORE_EXPORT QSharedPointer< QObject > sharedPointerFromVariant_internal(const QVariant &variant)
PCRE2_SIZE PRIV() strlen(PCRE2_SPTR str)
#define Q_AUTOTEST_EXPORT
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLint GLint GLint GLint GLint x
[0]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define Q_ASSERT_X(cond, x, msg)
const volatile void * pointer
Q_CORE_EXPORT void setQObjectShared(const QObject *, bool enable)
Q_CORE_EXPORT void checkQObjectShared(const QObject *)
static Q_CORE_EXPORT ExternalRefCountData * getAndRef(const QObject *)