Skip to content

Commit 95abb81

Browse files
authored
Merge pull request ClickHouse#79574 from ClickHouse/hanfei/fix-poco-json-datarace
fix data race in poco::JSON::stringify
2 parents ac34cc2 + 341682b commit 95abb81

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

base/poco/JSON/include/Poco/JSON/Array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace JSON
208208
// The reason we have this flag here (rather than as argument to stringify())
209209
// is because Array can be returned stringified from a Dynamic::Var:toString(),
210210
// so it must know whether to escape unicode or not.
211-
bool _escapeUnicode;
211+
std::atomic<bool> _escapeUnicode;
212212
};
213213

214214

base/poco/JSON/include/Poco/JSON/Object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define JSON_Object_INCLUDED
1919

2020

21+
#include <atomic>
2122
#include <deque>
2223
#include <iostream>
2324
#include <map>
@@ -292,7 +293,7 @@ namespace JSON
292293
// The reason for this flag (rather than as argument to stringify()) is
293294
// because Object can be returned stringified from Dynamic::Var::toString(),
294295
// so it must know whether to escape unicode or not.
295-
bool _escapeUnicode;
296+
std::atomic<bool> _escapeUnicode;
296297
mutable StructPtr _pStruct;
297298
mutable bool _modified;
298299
};

base/poco/JSON/src/Object.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Object::Object(int options):
3333

3434
Object::Object(const Object& other) : _values(other._values),
3535
_preserveInsOrder(other._preserveInsOrder),
36-
_escapeUnicode(other._escapeUnicode),
36+
_escapeUnicode(other._escapeUnicode.load()),
3737
_pStruct(!other._modified ? other._pStruct : 0),
3838
_modified(other._modified)
3939
{
@@ -48,7 +48,7 @@ Object::Object(Object&& other) :
4848
_values(std::move(other._values)),
4949
_keys(std::move(other._keys)),
5050
_preserveInsOrder(other._preserveInsOrder),
51-
_escapeUnicode(other._escapeUnicode),
51+
_escapeUnicode(other._escapeUnicode.load()),
5252
_pStruct(!other._modified ? other._pStruct : 0),
5353
_modified(other._modified)
5454
{
@@ -63,7 +63,7 @@ Object &Object::operator= (Object &&other)
6363
_values = other._values;
6464
_preserveInsOrder = other._preserveInsOrder;
6565
syncKeys(other._keys);
66-
_escapeUnicode = other._escapeUnicode;
66+
_escapeUnicode = other._escapeUnicode.load();
6767
_pStruct = !other._modified ? other._pStruct : 0;
6868
_modified = other._modified;
6969
other.clear();
@@ -87,7 +87,7 @@ Object &Object::operator= (const Object &other)
8787
_values = other._values;
8888
_keys = other._keys;
8989
_preserveInsOrder = other._preserveInsOrder;
90-
_escapeUnicode = other._escapeUnicode;
90+
_escapeUnicode = other._escapeUnicode.load();
9191
_pStruct = !other._modified ? other._pStruct : 0;
9292
_modified = other._modified;
9393
}

0 commit comments

Comments
 (0)