-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a patch to fix wasm settings used by color dialog
- Loading branch information
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
From 25c2d05340eee01cf55457b8327f8f69d408879a Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Morten=20S=C3=B8rvig?= <morten.sorvig@qt.io> | ||
Date: Fri, 24 Jun 2022 13:10:33 +0200 | ||
Subject: wasm: don't access deleted settings objects | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
The emscripten_idb_async_ functions are async, so there | ||
is no guarantee that the QSettings object which made | ||
the request will be live by the time the completion | ||
callback is made. | ||
|
||
Keep track of live QWasmSettingsPrivate objects, return | ||
early from the callbacks if userData does not point | ||
to a valid QWasmSettingsPrivate. | ||
|
||
Pick-to: 6.4 6.3 6.2 5.15 | ||
Change-Id: Ia319b1875dcf2c329ba27954e3f026e004fe0aac | ||
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> | ||
Reviewed-by: Lorn Potter <lorn.potter@gmail.com> | ||
--- | ||
src/corelib/io/qsettings_wasm.cpp | 43 ++++++++++++++++++++++++++------------- | ||
1 file changed, 29 insertions(+), 14 deletions(-) | ||
|
||
(limited to 'src/corelib/io/qsettings_wasm.cpp') | ||
|
||
diff --git a/src/corelib/io/qsettings_wasm.cpp b/src/corelib/io/qsettings_wasm.cpp | ||
index ba081997fd..5c15e6d89b 100644 | ||
--- a/src/corelib/io/qsettings_wasm.cpp | ||
+++ b/src/corelib/io/qsettings_wasm.cpp | ||
@@ -13,6 +13,8 @@ | ||
|
||
#include <QFileInfo> | ||
#include <QDir> | ||
+#include <QList> | ||
+ | ||
#include <emscripten.h> | ||
|
||
QT_BEGIN_NAMESPACE | ||
@@ -27,6 +29,7 @@ public: | ||
QWasmSettingsPrivate(QSettings::Scope scope, const QString &organization, | ||
const QString &application); | ||
~QWasmSettingsPrivate(); | ||
+ static QWasmSettingsPrivate *get(void *userData); | ||
|
||
std::optional<QVariant> get(const QString &key) const override; | ||
QStringList children(const QString &prefix, ChildSpec spec) const override; | ||
@@ -43,14 +46,19 @@ public: | ||
private: | ||
QString databaseName; | ||
QString id; | ||
+ static QList<QWasmSettingsPrivate *> liveSettings; | ||
}; | ||
|
||
+QList<QWasmSettingsPrivate *> QWasmSettingsPrivate::liveSettings; | ||
+ | ||
static void QWasmSettingsPrivate_onLoad(void *userData, void *dataPtr, int size) | ||
{ | ||
- QWasmSettingsPrivate *wasm = reinterpret_cast<QWasmSettingsPrivate *>(userData); | ||
+ QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData); | ||
+ if (!settings) | ||
+ return; | ||
|
||
- QFile file(wasm->fileName()); | ||
- QFileInfo fileInfo(wasm->fileName()); | ||
+ QFile file(settings->fileName()); | ||
+ QFileInfo fileInfo(settings->fileName()); | ||
QDir dir(fileInfo.path()); | ||
if (!dir.exists()) | ||
dir.mkpath(fileInfo.path()); | ||
@@ -58,32 +66,29 @@ static void QWasmSettingsPrivate_onLoad(void *userData, void *dataPtr, int size) | ||
if (file.open(QFile::WriteOnly)) { | ||
file.write(reinterpret_cast<char *>(dataPtr), size); | ||
file.close(); | ||
- wasm->setReady(); | ||
+ settings->setReady(); | ||
} | ||
} | ||
|
||
static void QWasmSettingsPrivate_onError(void *userData) | ||
{ | ||
- QWasmSettingsPrivate *wasm = reinterpret_cast<QWasmSettingsPrivate *>(userData); | ||
- if (wasm) | ||
- wasm->setStatus(QSettings::AccessError); | ||
+ if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData)) | ||
+ settings->setStatus(QSettings::AccessError); | ||
} | ||
|
||
static void QWasmSettingsPrivate_onStore(void *userData) | ||
{ | ||
- QWasmSettingsPrivate *wasm = reinterpret_cast<QWasmSettingsPrivate *>(userData); | ||
- if (wasm) | ||
- wasm->setStatus(QSettings::NoError); | ||
+ if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData)) | ||
+ settings->setStatus(QSettings::NoError); | ||
} | ||
|
||
static void QWasmSettingsPrivate_onCheck(void *userData, int exists) | ||
{ | ||
- QWasmSettingsPrivate *wasm = reinterpret_cast<QWasmSettingsPrivate *>(userData); | ||
- if (wasm) { | ||
+ if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData)) { | ||
if (exists) | ||
- wasm->loadLocal(wasm->fileName().toLocal8Bit()); | ||
+ settings->loadLocal(settings->fileName().toLocal8Bit()); | ||
else | ||
- wasm->setReady(); | ||
+ settings->setReady(); | ||
} | ||
} | ||
|
||
@@ -114,6 +119,8 @@ QWasmSettingsPrivate::QWasmSettingsPrivate(QSettings::Scope scope, const QString | ||
const QString &application) | ||
: QConfFileSettingsPrivate(QSettings::NativeFormat, scope, organization, application) | ||
{ | ||
+ liveSettings.push_back(this); | ||
+ | ||
setStatus(QSettings::AccessError); // access error until sandbox gets loaded | ||
databaseName = organization; | ||
id = application; | ||
@@ -127,6 +134,14 @@ QWasmSettingsPrivate::QWasmSettingsPrivate(QSettings::Scope scope, const QString | ||
|
||
QWasmSettingsPrivate::~QWasmSettingsPrivate() | ||
{ | ||
+ liveSettings.removeAll(this); | ||
+} | ||
+ | ||
+QWasmSettingsPrivate *QWasmSettingsPrivate::get(void *userData) | ||
+{ | ||
+ if (QWasmSettingsPrivate::liveSettings.contains(reinterpret_cast<QWasmSettingsPrivate *>(userData))) | ||
+ return reinterpret_cast<QWasmSettingsPrivate *>(userData); | ||
+ return nullptr; | ||
} | ||
|
||
void QWasmSettingsPrivate::initAccess() | ||
-- | ||
cgit v1.2.3 | ||
|