diff options
Diffstat (limited to 'src/corelib/ipc/qsharedmemory.cpp')
-rw-r--r-- | src/corelib/ipc/qsharedmemory.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/corelib/ipc/qsharedmemory.cpp b/src/corelib/ipc/qsharedmemory.cpp index ea0ff4f1b3..02761c0263 100644 --- a/src/corelib/ipc/qsharedmemory.cpp +++ b/src/corelib/ipc/qsharedmemory.cpp @@ -7,6 +7,7 @@ #include "qtipccommon_p.h" #include "qsystemsemaphore.h" +#include <q20memory.h> #include <qdebug.h> #ifdef Q_OS_WIN # include <qt_windows.h> @@ -23,15 +24,6 @@ QT_BEGIN_NAMESPACE using namespace QtIpcCommon; using namespace Qt::StringLiterals; -#if __cplusplus >= 202002L -using std::construct_at; -#else -template <typename T> static void construct_at(T *ptr) -{ - new (ptr) T; -} -#endif - QSharedMemoryPrivate::~QSharedMemoryPrivate() { destructBackend(); @@ -39,6 +31,7 @@ QSharedMemoryPrivate::~QSharedMemoryPrivate() inline void QSharedMemoryPrivate::constructBackend() { + using namespace q20; visit([](auto p) { construct_at(p); }); } @@ -133,20 +126,15 @@ QSharedMemory::QSharedMemory(const QNativeIpcKey &key, QObject *parent) } /*! - \deprecated - Constructs a shared memory object with the given \a parent and with the legacy key set to \a key. Because its key is set, its create() and attach() functions can be called. - Legacy keys are deprecated. See \l{Native IPC Keys} for more information. - \sa setKey(), create(), attach() */ QSharedMemory::QSharedMemory(const QString &key, QObject *parent) : QSharedMemory(legacyNativeKey(key), parent) { - d_func()->legacyKey = key; } /*! @@ -188,9 +176,7 @@ QSharedMemory::~QSharedMemory() */ void QSharedMemory::setKey(const QString &key) { - Q_D(QSharedMemory); setNativeKey(legacyNativeKey(key)); - d->legacyKey = key; } /*! @@ -247,7 +233,6 @@ void QSharedMemory::setNativeKey(const QNativeIpcKey &key) if (isAttached()) detach(); d->cleanHandle(); - d->legacyKey = QString(); if (key.type() == d->nativeKey.type()) { // we can reuse the backend d->nativeKey = key; @@ -264,7 +249,11 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) if (!cleanHandle()) return false; #if QT_CONFIG(systemsemaphore) - systemSemaphore.setNativeKey(semaphoreNativeKey(), 1, mode); + const QString legacyKey = QNativeIpcKeyPrivate::legacyKey(nativeKey); + const QNativeIpcKey semKey = legacyKey.isEmpty() + ? semaphoreNativeKey() + : QSystemSemaphore::legacyNativeKey(legacyKey, nativeKey.type()); + systemSemaphore.setNativeKey(semKey, 1, mode); if (systemSemaphore.error() != QSystemSemaphore::NoError) { QString function = "QSharedMemoryPrivate::initKey"_L1; errorString = QSharedMemory::tr("%1: unable to set key on lock (%2)") @@ -301,7 +290,6 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) } /*! - \deprecated Returns the legacy key assigned with setKey() to this shared memory, or a null key if no key has been assigned, or if the segment is using a nativeKey(). The key is the identifier used by Qt applications to identify the shared memory @@ -315,7 +303,7 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) QString QSharedMemory::key() const { Q_D(const QSharedMemory); - return d->legacyKey; + return QNativeIpcKeyPrivate::legacyKey(d->nativeKey); } /*! @@ -686,12 +674,12 @@ bool QSharedMemory::isKeyTypeSupported(QNativeIpcKey::Type type) QNativeIpcKey QSharedMemory::platformSafeKey(const QString &key, QNativeIpcKey::Type type) { - return { QtIpcCommon::platformSafeKey(key, IpcType::SharedMemory, type), type }; + return QtIpcCommon::platformSafeKey(key, IpcType::SharedMemory, type); } QNativeIpcKey QSharedMemory::legacyNativeKey(const QString &key, QNativeIpcKey::Type type) { - return { legacyPlatformSafeKey(key, IpcType::SharedMemory, type), type }; + return QtIpcCommon::legacyPlatformSafeKey(key, IpcType::SharedMemory, type); } #endif // QT_CONFIG(sharedmemory) |