aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme
diff options
context:
space:
mode:
authorOleg Sidorkin <osidorkin@gmail.com>2022-02-10 16:49:36 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:36 +0300
commitf8f6804a3e352897afabc93afcb32081e3fca601 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/scheme
parent5ce74d4fee2d42a4b86efc02dfdc704d458760e1 (diff)
downloadydb-f8f6804a3e352897afabc93afcb32081e3fca601.tar.gz
Restoring authorship annotation for Oleg Sidorkin <osidorkin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/scheme')
-rw-r--r--library/cpp/scheme/scheme.cpp38
-rw-r--r--library/cpp/scheme/scheme.h8
-rw-r--r--library/cpp/scheme/scimpl.h124
-rw-r--r--library/cpp/scheme/scimpl_protobuf.cpp2
-rw-r--r--library/cpp/scheme/scimpl_select.rl66
-rw-r--r--library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp184
-rw-r--r--library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp6
-rw-r--r--library/cpp/scheme/tests/fuzz_ops/lib/vm_apply.cpp38
-rw-r--r--library/cpp/scheme/tests/ut/scheme_merge_ut.cpp2
-rw-r--r--library/cpp/scheme/tests/ut/scheme_path_ut.cpp30
-rw-r--r--library/cpp/scheme/tests/ut/scheme_proto_ut.cpp2
-rw-r--r--library/cpp/scheme/tests/ut/scheme_ut.cpp90
12 files changed, 265 insertions, 265 deletions
diff --git a/library/cpp/scheme/scheme.cpp b/library/cpp/scheme/scheme.cpp
index b3d555e459..3efd116d4f 100644
--- a/library/cpp/scheme/scheme.cpp
+++ b/library/cpp/scheme/scheme.cpp
@@ -161,7 +161,7 @@ namespace NSc {
return *this;
}
- CoreMutableForSet(); // trigger COW
+ CoreMutableForSet(); // trigger COW
TScCore& selfCore = *TheCore;
const TScCore& otherCore = other.Core();
@@ -191,28 +191,28 @@ namespace NSc {
selfCore.SetNumber(otherCore.FloatNumber);
break;
case EType::String:
- if (selfCore.Pool.Get() == otherCore.Pool.Get()) {
- selfCore.SetOwnedString(otherCore.String);
- } else {
- selfCore.SetString(otherCore.String);
- }
+ if (selfCore.Pool.Get() == otherCore.Pool.Get()) {
+ selfCore.SetOwnedString(otherCore.String);
+ } else {
+ selfCore.SetString(otherCore.String);
+ }
break;
case EType::Array:
selfCore.SetArray();
for (const TValue& e : otherCore.GetArray()) {
- selfCore.Push().DoCopyFromImpl(e, otherLoopCtx, selfOverrideCtx);
+ selfCore.Push().DoCopyFromImpl(e, otherLoopCtx, selfOverrideCtx);
}
break;
case EType::Dict: {
- TCorePtr tmp = NewCore(selfCore.Pool);
- auto& tmpCore = *tmp;
- tmpCore.SetDict();
+ TCorePtr tmp = NewCore(selfCore.Pool);
+ auto& tmpCore = *tmp;
+ tmpCore.SetDict();
const TDict& d = otherCore.GetDict();
- tmpCore.Dict.reserve(d.size());
+ tmpCore.Dict.reserve(d.size());
for (const TDict::value_type& e : d) {
- tmpCore.Add(e.first).DoCopyFromImpl(e.second, otherLoopCtx, selfOverrideCtx);
+ tmpCore.Add(e.first).DoCopyFromImpl(e.second, otherLoopCtx, selfOverrideCtx);
}
- TheCore = std::move(tmp);
+ TheCore = std::move(tmp);
break;
}
}
@@ -231,7 +231,7 @@ namespace NSc {
}
bool TValue::SamePool(const TValue& a, const TValue& b) {
- return Same(a, b) || a.TheCore->Pool.Get() == b.TheCore->Pool.Get();
+ return Same(a, b) || a.TheCore->Pool.Get() == b.TheCore->Pool.Get();
}
bool TValue::Equal(const TValue& a, const TValue& b) {
@@ -323,7 +323,7 @@ namespace NSc {
const TDict& ddelta = deltaCore.Dict;
for (const auto& dit : ddelta) {
- core.GetOrAdd(dit.first).DoMergeImpl(dit.second, lowPriorityDelta, otherLoopCtx, selfOverrideGuard);
+ core.GetOrAdd(dit.first).DoMergeImpl(dit.second, lowPriorityDelta, otherLoopCtx, selfOverrideGuard);
}
} else if (!delta.IsNull() && (!lowPriorityDelta || IsNull())) {
DoCopyFromImpl(delta, otherLoopCtx, selfOverrideGuard);
@@ -394,7 +394,7 @@ namespace NSc {
}
TValue& TValue::FromJsonValue(TValue& res, const NJson::TJsonValue& val) {
- TScCore& core = res.CoreMutableForSet();
+ TScCore& core = res.CoreMutableForSet();
core.SetNull();
switch (val.GetType()) {
@@ -415,19 +415,19 @@ namespace NSc {
core.SetNumber(val.GetDouble());
break;
case NJson::JSON_STRING:
- core.SetString(val.GetString());
+ core.SetString(val.GetString());
break;
case NJson::JSON_ARRAY: {
core.SetArray();
for (const auto& item : val.GetArray()) {
- FromJsonValue(core.Push(), item);
+ FromJsonValue(core.Push(), item);
}
break;
}
case NJson::JSON_MAP: {
core.SetDict();
for (const auto& item : val.GetMap()) {
- FromJsonValue(core.Add(item.first), item.second);
+ FromJsonValue(core.Add(item.first), item.second);
}
break;
}
diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h
index 1b6f5d8323..3d7c59f3c9 100644
--- a/library/cpp/scheme/scheme.h
+++ b/library/cpp/scheme/scheme.h
@@ -193,7 +193,7 @@ namespace NSc {
inline bool Has(size_t idx) const;
inline const TValue& Get(size_t idx) const; // returns child or default
- inline TValue* GetNoAdd(size_t idx); // returns link to existing child or nullptr
+ inline TValue* GetNoAdd(size_t idx); // returns link to existing child or nullptr
inline TValue& Push(); // returns new child
@@ -260,7 +260,7 @@ namespace NSc {
inline bool Has(TStringBuf idx) const;
inline const TValue& Get(TStringBuf idx) const;
- inline TValue* GetNoAdd(TStringBuf idx); // returns link to existing child or nullptr
+ inline TValue* GetNoAdd(TStringBuf idx); // returns link to existing child or nullptr
TValue& Add(TStringBuf idx) {
return GetOrAdd(idx);
@@ -364,7 +364,7 @@ namespace NSc {
// if the path is syntactically valid and the target value exists
// otherwise returns NSc::Null()
- TValue* TrySelectOrAdd(TStringBuf path); // returns the target value if it exists or creates if not
+ TValue* TrySelectOrAdd(TStringBuf path); // returns the target value if it exists or creates if not
// if the path is syntactically valid
// otherwise returns NSc::Null()
@@ -413,7 +413,7 @@ namespace NSc {
bool IsSameOrAncestorOfImpl(const TScCore& other, NImpl::TSelfLoopContext& loopCtx) const;
inline TScCore& CoreMutable();
- inline TScCore& CoreMutableForSet();
+ inline TScCore& CoreMutableForSet();
inline const TScCore& Core() const;
static inline TScCore* NewCore(TPoolPtr&);
diff --git a/library/cpp/scheme/scimpl.h b/library/cpp/scheme/scimpl.h
index ce9539dfa0..4f68f16290 100644
--- a/library/cpp/scheme/scimpl.h
+++ b/library/cpp/scheme/scimpl.h
@@ -6,7 +6,7 @@
namespace NSc {
struct TValue::TScCore : TAtomicRefCount<TScCore, TDestructor>, TNonCopyable {
- TPoolPtr Pool;
+ TPoolPtr Pool;
double FloatNumber = 0;
i64 IntNumber = 0;
TStringBuf String;
@@ -15,9 +15,9 @@ namespace NSc {
TValue::EType ValueType = TValue::EType::Null;
TScCore(TPoolPtr& p)
- : Pool(p)
- , Dict(Pool->Get())
- , Array(Pool->Get())
+ : Pool(p)
+ , Dict(Pool->Get())
+ , Array(Pool->Get())
{
}
@@ -90,13 +90,13 @@ namespace NSc {
IntNumber = b;
}
- void SetString(TStringBuf s) {
- SetOwnedString(Pool->AppendBuf(s));
- }
-
- void SetOwnedString(TStringBuf s) {
+ void SetString(TStringBuf s) {
+ SetOwnedString(Pool->AppendBuf(s));
+ }
+
+ void SetOwnedString(TStringBuf s) {
ValueType = TValue::EType::String;
- String = s;
+ String = s;
}
double& GetNumberMutable(double defaultnum) {
@@ -208,9 +208,9 @@ namespace NSc {
a.back().CopyOnWrite = false;
}
- TValue& Push() {
+ TValue& Push() {
SetArray();
- DoPush(Pool, Array);
+ DoPush(Pool, Array);
return Array.back();
}
@@ -228,36 +228,36 @@ namespace NSc {
return IsArray() && Array.size() > key ? Array[key] : TValue::DefaultValue();
}
- TValue* GetNoAdd(size_t key) {
- return IsArray() && Array.size() > key ? &Array[key] : nullptr;
+ TValue* GetNoAdd(size_t key) {
+ return IsArray() && Array.size() > key ? &Array[key] : nullptr;
}
- TValue& GetOrAdd(size_t key) {
+ TValue& GetOrAdd(size_t key) {
SetArray();
for (size_t i = Array.size(); i <= key; ++i) {
- DoPush(Pool, Array);
+ DoPush(Pool, Array);
}
return Array[key];
}
- TValue& Back() {
+ TValue& Back() {
SetArray();
if (Array.empty()) {
- DoPush(Pool, Array);
+ DoPush(Pool, Array);
}
return Array.back();
}
- TValue& Insert(size_t key) {
+ TValue& Insert(size_t key) {
SetArray();
if (Array.size() <= key) {
- return GetOrAdd(key);
+ return GetOrAdd(key);
} else {
- Array.insert(Array.begin() + key, TValue(Pool));
+ Array.insert(Array.begin() + key, TValue(Pool));
Array[key].CopyOnWrite = false;
return Array[key];
}
@@ -282,28 +282,28 @@ namespace NSc {
return it != Dict.end() ? it->second : TValue::DefaultValue();
}
- TValue* GetNoAdd(TStringBuf key) {
+ TValue* GetNoAdd(TStringBuf key) {
if (!IsDict()) {
- return nullptr;
+ return nullptr;
}
- return Dict.FindPtr(key);
+ return Dict.FindPtr(key);
}
- TValue& Add(TStringBuf key) {
+ TValue& Add(TStringBuf key) {
SetDict();
- TDict::iterator it = Dict.insert(std::make_pair(Pool->AppendBuf(key), TValue(Pool))).first;
+ TDict::iterator it = Dict.insert(std::make_pair(Pool->AppendBuf(key), TValue(Pool))).first;
it->second.CopyOnWrite = false;
return it->second;
}
- TValue& GetOrAdd(TStringBuf key) {
+ TValue& GetOrAdd(TStringBuf key) {
SetDict();
TDict::insert_ctx ctx;
TDict::iterator it = Dict.find(key, ctx);
if (it == Dict.end()) {
- it = Dict.insert_direct(std::make_pair(Pool->AppendBuf(key), TValue(Pool)), ctx);
+ it = Dict.insert_direct(std::make_pair(Pool->AppendBuf(key), TValue(Pool)), ctx);
it->second.CopyOnWrite = false;
}
@@ -331,9 +331,9 @@ namespace NSc {
return new (p->Pool.Allocate<TScCore>()) TScCore(p);
}
- TValue::TValue() {
- auto p = TPoolPtr(new NDefinitions::TPool);
- TheCore = NewCore(p);
+ TValue::TValue() {
+ auto p = TPoolPtr(new NDefinitions::TPool);
+ TheCore = NewCore(p);
}
TValue::TValue(double t)
@@ -397,19 +397,19 @@ namespace NSc {
}
TValue::TValue(TValue& v)
- : TheCore(v.TheCore)
+ : TheCore(v.TheCore)
, CopyOnWrite(v.CopyOnWrite)
{
}
TValue::TValue(const TValue& v)
- : TheCore(v.TheCore)
+ : TheCore(v.TheCore)
, CopyOnWrite(true)
{
}
TValue::TValue(TValue&& v) noexcept
- : TheCore(std::move(v.TheCore))
+ : TheCore(std::move(v.TheCore))
, CopyOnWrite(v.CopyOnWrite)
{}
@@ -529,8 +529,8 @@ namespace NSc {
TValue& TValue::operator=(const TValue& v) & {
if (!Same(*this, v)) {
- //Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
- auto tmpCore = TheCore;
+ //Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
+ auto tmpCore = TheCore;
TheCore = v.TheCore;
CopyOnWrite = true;
}
@@ -539,8 +539,8 @@ namespace NSc {
TValue& TValue::operator=(TValue&& v) & noexcept {
if (!Same(*this, v)) {
- //Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
- auto tmpCore = TheCore;
+ //Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
+ auto tmpCore = TheCore;
TheCore = std::move(v.TheCore);
CopyOnWrite = v.CopyOnWrite;
}
@@ -556,18 +556,18 @@ namespace NSc {
}
TValue& TValue::GetOrAddUnsafe(size_t idx) {
- return CoreMutable().GetOrAdd(idx);
+ return CoreMutable().GetOrAdd(idx);
}
TValue& TValue::GetOrAdd(TStringBuf idx) {
- return CoreMutable().GetOrAdd(idx);
+ return CoreMutable().GetOrAdd(idx);
}
const TValue& TValue::Get(size_t idx) const {
return Core().Get(idx);
}
- TValue* TValue::GetNoAdd(size_t idx) {
+ TValue* TValue::GetNoAdd(size_t idx) {
return CoreMutable().GetNoAdd(idx);
}
@@ -575,12 +575,12 @@ namespace NSc {
return Core().Get(idx);
}
- TValue* TValue::GetNoAdd(TStringBuf key) {
+ TValue* TValue::GetNoAdd(TStringBuf key) {
return CoreMutable().GetNoAdd(key);
}
TValue& TValue::Back() {
- return CoreMutable().Back();
+ return CoreMutable().Back();
}
const TValue& TValue::Back() const {
@@ -604,7 +604,7 @@ namespace NSc {
}
TValue& TValue::InsertUnsafe(size_t idx) {
- return CoreMutable().Insert(idx);
+ return CoreMutable().Insert(idx);
}
template <class TIt>
@@ -623,7 +623,7 @@ namespace NSc {
}
TValue& TValue::Push() {
- return CoreMutable().Push();
+ return CoreMutable().Push();
}
TValue TValue::Pop() {
@@ -663,22 +663,22 @@ namespace NSc {
}
TValue& TValue::SetNumber(double i) {
- CoreMutableForSet().SetNumber(i);
+ CoreMutableForSet().SetNumber(i);
return *this;
}
TValue& TValue::SetIntNumber(i64 n) {
- CoreMutableForSet().SetIntNumber(n);
+ CoreMutableForSet().SetIntNumber(n);
return *this;
}
TValue& TValue::SetBool(bool val) {
- CoreMutableForSet().SetBool(val);
+ CoreMutableForSet().SetBool(val);
return *this;
}
TValue& TValue::SetString(TStringBuf s) {
- CoreMutableForSet().SetString(s);
+ CoreMutableForSet().SetString(s);
return *this;
}
@@ -767,13 +767,13 @@ namespace NSc {
}
TValue::TValue(TPoolPtr& p)
- : TheCore(NewCore(p))
+ : TheCore(NewCore(p))
{
}
TValue::TScCore& TValue::CoreMutable() {
if (Y_UNLIKELY(!TheCore)) {
- *this = TValue();
+ *this = TValue();
} else if (Y_UNLIKELY(CopyOnWrite) && Y_UNLIKELY(TheCore->RefCount() > 1)) {
*this = Clone();
}
@@ -783,22 +783,22 @@ namespace NSc {
return *TheCore;
}
- TValue::TScCore& TValue::CoreMutableForSet() {
- if (Y_UNLIKELY(!TheCore) || Y_UNLIKELY(CopyOnWrite) && Y_UNLIKELY(TheCore->RefCount() > 1)) {
- *this = TValue();
- }
-
- CopyOnWrite = false;
-
- return *TheCore;
- }
-
+ TValue::TScCore& TValue::CoreMutableForSet() {
+ if (Y_UNLIKELY(!TheCore) || Y_UNLIKELY(CopyOnWrite) && Y_UNLIKELY(TheCore->RefCount() > 1)) {
+ *this = TValue();
+ }
+
+ CopyOnWrite = false;
+
+ return *TheCore;
+ }
+
const TValue::TScCore& TValue::Core() const {
return TheCore ? *TheCore : DefaultCore();
}
TValue& TValue::SetNull() {
- CoreMutableForSet().SetNull();
+ CoreMutableForSet().SetNull();
return *this;
}
diff --git a/library/cpp/scheme/scimpl_protobuf.cpp b/library/cpp/scheme/scimpl_protobuf.cpp
index 849428a7ef..0c99122c69 100644
--- a/library/cpp/scheme/scimpl_protobuf.cpp
+++ b/library/cpp/scheme/scimpl_protobuf.cpp
@@ -23,7 +23,7 @@ namespace NSc {
try {
if (field->is_repeated()) {
if (field->is_map() && mapAsDict) {
- auto& elem = v[field->name()];
+ auto& elem = v[field->name()];
for (int i2 = 0; i2 < r->FieldSize(msg, field); ++i2) {
auto val = FromRepeatedField(msg, field, i2);
if (val.IsDict()) {
diff --git a/library/cpp/scheme/scimpl_select.rl6 b/library/cpp/scheme/scimpl_select.rl6
index 20d2e4eb35..11aa549b78 100644
--- a/library/cpp/scheme/scimpl_select.rl6
+++ b/library/cpp/scheme/scimpl_select.rl6
@@ -216,13 +216,13 @@ namespace NSc {
return DefaultValue();
}
- TValue* TValue::TrySelectOrAdd(TStringBuf path) {
+ TValue* TValue::TrySelectOrAdd(TStringBuf path) {
TSelectorCtx<TSelector<TValue, TGetNext<false> > > ctx(*this, path);
if (ctx.SelectPath()) {
- return ctx.Selector.Current;
+ return ctx.Selector.Current;
} else {
- return nullptr;
+ return nullptr;
}
}
diff --git a/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp b/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp
index f34571d967..7c16527c23 100644
--- a/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp
+++ b/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp
@@ -1,90 +1,90 @@
#include "fuzz_json.h"
-#include "util/generic/fwd.h"
+#include "util/generic/fwd.h"
#include <library/cpp/scheme/scheme.h>
#include <util/stream/null.h>
-namespace {
- static constexpr size_t MAX_DEPTH = 4;
- static constexpr size_t MAX_PATH_LEN = 256;
- static constexpr size_t MAX_ITERATIONS = 4;
-
- void SplitOnDepth(const TStringBuf src, const size_t depth, const size_t maxPathLen,
- TStringBuf& left, TStringBuf& right)
- {
- size_t pos = 0;
- size_t prevPos = 0;
- for(size_t i = 0; i < depth; ++i) {
- if (pos > maxPathLen) {
- break;
- }
- prevPos = pos;
- pos = src.find_first_of(TStringBuf("/]"), pos + 1);
- if (pos == TStringBuf::npos) {
- break;
- }
- }
- if (pos == TStringBuf::npos && prevPos > 0) {
- pos = prevPos;
- }
- if (src.length() > maxPathLen) {
- if (pos == TStringBuf::npos || pos > maxPathLen) {
- pos = maxPathLen;
- }
- }
- if (pos == TStringBuf::npos || pos == 0) {
- left = src;
- right = TStringBuf();
- } else {
- src.SplitAt(pos + 1, left, right);
- }
- }
-
- TString tmp;
- //Limit max array size in the path to 256
- TStringBuf ProcessPath(TStringBuf path) {
- size_t pos = 0;
- while(pos != TStringBuf::npos) {
- pos = path.find(']', pos + 1);
- if (pos == TStringBuf::npos) {
- continue;
- }
- size_t open = path.rfind('[', pos);
- if (open == TStringBuf::npos) {
- continue;
- }
- bool allDigit = true;
- for(size_t i = open + 1; i < pos; ++i) {
- if (path[i] < '0' || path[i] > '9') {
- allDigit = false;
- break;
- }
- }
- if (!allDigit) {
- continue;
- }
- if (pos - open > 4) {
- TString str = TString::Join(path.Head(open + 1), "256", path.Tail(pos));
- tmp = std::move(str);
- path = tmp;
- pos = (open + 1) + 3;
- continue;
- }
- }
- return path;
- }
-}
-
+namespace {
+ static constexpr size_t MAX_DEPTH = 4;
+ static constexpr size_t MAX_PATH_LEN = 256;
+ static constexpr size_t MAX_ITERATIONS = 4;
+
+ void SplitOnDepth(const TStringBuf src, const size_t depth, const size_t maxPathLen,
+ TStringBuf& left, TStringBuf& right)
+ {
+ size_t pos = 0;
+ size_t prevPos = 0;
+ for(size_t i = 0; i < depth; ++i) {
+ if (pos > maxPathLen) {
+ break;
+ }
+ prevPos = pos;
+ pos = src.find_first_of(TStringBuf("/]"), pos + 1);
+ if (pos == TStringBuf::npos) {
+ break;
+ }
+ }
+ if (pos == TStringBuf::npos && prevPos > 0) {
+ pos = prevPos;
+ }
+ if (src.length() > maxPathLen) {
+ if (pos == TStringBuf::npos || pos > maxPathLen) {
+ pos = maxPathLen;
+ }
+ }
+ if (pos == TStringBuf::npos || pos == 0) {
+ left = src;
+ right = TStringBuf();
+ } else {
+ src.SplitAt(pos + 1, left, right);
+ }
+ }
+
+ TString tmp;
+ //Limit max array size in the path to 256
+ TStringBuf ProcessPath(TStringBuf path) {
+ size_t pos = 0;
+ while(pos != TStringBuf::npos) {
+ pos = path.find(']', pos + 1);
+ if (pos == TStringBuf::npos) {
+ continue;
+ }
+ size_t open = path.rfind('[', pos);
+ if (open == TStringBuf::npos) {
+ continue;
+ }
+ bool allDigit = true;
+ for(size_t i = open + 1; i < pos; ++i) {
+ if (path[i] < '0' || path[i] > '9') {
+ allDigit = false;
+ break;
+ }
+ }
+ if (!allDigit) {
+ continue;
+ }
+ if (pos - open > 4) {
+ TString str = TString::Join(path.Head(open + 1), "256", path.Tail(pos));
+ tmp = std::move(str);
+ path = tmp;
+ pos = (open + 1) + 3;
+ continue;
+ }
+ }
+ return path;
+ }
+}
+
namespace NSc::NUt {
-
-
+
+
void FuzzJson(TStringBuf wire) {
if (wire.size() < 2) {
return;
}
-
- ProcessPath("[123][1234][12][2134][12312312][1][12]");
+
+ ProcessPath("[123][1234][12][2134][12312312][1][12]");
ui8 len1 = wire[0];
ui8 len2 = wire[1];
wire.Skip(2);
@@ -94,22 +94,22 @@ namespace NSc::NUt {
NSc::TValue val2 = NSc::TValue::FromJson(json2);
NSc::TValue val3;
val3.MergeUpdate(val1);
-
- size_t i = 0;
- while (!wire.empty()) {
- TStringBuf path;
- SplitOnDepth(wire, MAX_DEPTH, MAX_PATH_LEN, path, wire);
- path = ProcessPath(path);
- if (auto* target = val3.TrySelectOrAdd(path)) {
- target->MergeUpdate(val2);
- }
- ++i;
- // Release memory since there are up to MAX_DICT_SIZE * MAX_DEPTH elements
- if (i > MAX_ITERATIONS) {
- Cnull << val3.ToJson();
- val3 = NSc::TValue();
- }
- }
+
+ size_t i = 0;
+ while (!wire.empty()) {
+ TStringBuf path;
+ SplitOnDepth(wire, MAX_DEPTH, MAX_PATH_LEN, path, wire);
+ path = ProcessPath(path);
+ if (auto* target = val3.TrySelectOrAdd(path)) {
+ target->MergeUpdate(val2);
+ }
+ ++i;
+ // Release memory since there are up to MAX_DICT_SIZE * MAX_DEPTH elements
+ if (i > MAX_ITERATIONS) {
+ Cnull << val3.ToJson();
+ val3 = NSc::TValue();
+ }
+ }
Cnull << val3.ToJson();
}
}
diff --git a/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp b/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp
index a100d3a631..8a7facba24 100644
--- a/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp
+++ b/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp
@@ -29,9 +29,9 @@ namespace NSc::NUt {
if (!ApplyNextAction(st, *act)) {
break;
}
- if (!NSc::TValue::DefaultValue().IsNull()) {
- std::terminate();
- }
+ if (!NSc::TValue::DefaultValue().IsNull()) {
+ std::terminate();
+ }
}
}
}
diff --git a/library/cpp/scheme/tests/fuzz_ops/lib/vm_apply.cpp b/library/cpp/scheme/tests/fuzz_ops/lib/vm_apply.cpp
index 563187f9f4..ada7b8854f 100644
--- a/library/cpp/scheme/tests/fuzz_ops/lib/vm_apply.cpp
+++ b/library/cpp/scheme/tests/fuzz_ops/lib/vm_apply.cpp
@@ -77,22 +77,22 @@ namespace NSc::NUt {
Y_FAIL(); \
}
-#define Y_GEN_PTR_OP(op, arg, st, act) \
- if (auto* r = (op)) { \
- switch (act.GetRef(arg).Type) { \
- case TRef::T_CREATE_BACK: \
- Y_GEN_TRY_OP(st.TryPushBack(*r)) \
- break; \
- case TRef::T_CREATE_FRONT: \
- Y_GEN_TRY_OP(st.TryPushFront(*r)) \
- break; \
- case TRef::T_REF__POS: \
- st.LRef(act.GetRef(arg).Pos) = *r; \
- break; \
- default: \
- Y_FAIL(); \
- } \
- }
+#define Y_GEN_PTR_OP(op, arg, st, act) \
+ if (auto* r = (op)) { \
+ switch (act.GetRef(arg).Type) { \
+ case TRef::T_CREATE_BACK: \
+ Y_GEN_TRY_OP(st.TryPushBack(*r)) \
+ break; \
+ case TRef::T_CREATE_FRONT: \
+ Y_GEN_TRY_OP(st.TryPushFront(*r)) \
+ break; \
+ case TRef::T_REF__POS: \
+ st.LRef(act.GetRef(arg).Pos) = *r; \
+ break; \
+ default: \
+ Y_FAIL(); \
+ } \
+ }
bool ApplyNextAction(TVMState& st, TVMAction act) {
switch (act.Type) {
@@ -228,7 +228,7 @@ namespace NSc::NUt {
return true;
case VMA_ARRAY_GET_NO_ADD__IDX_REF:
- Y_GEN_PTR_OP(st.Current().GetNoAdd(act.GetIdx(0)), 1, st, act);
+ Y_GEN_PTR_OP(st.Current().GetNoAdd(act.GetIdx(0)), 1, st, act);
return true;
case VMA_DICT_CLEAR:
@@ -260,7 +260,7 @@ namespace NSc::NUt {
return true;
case VMA_DICT_GET_NO_ADD__IDX_REF:
- Y_GEN_PTR_OP(st.Current().GetNoAdd(act.GetKey(0)), 1, st, act);
+ Y_GEN_PTR_OP(st.Current().GetNoAdd(act.GetKey(0)), 1, st, act);
return true;
case VMA_MERGE_UPDATE__POS:
@@ -288,7 +288,7 @@ namespace NSc::NUt {
return true;
case VMA_SELECT_OR_ADD__PATH_REF:
- Y_GEN_PTR_OP(st.Current().TrySelectOrAdd(act.GetPath(0)), 1, st, act);
+ Y_GEN_PTR_OP(st.Current().TrySelectOrAdd(act.GetPath(0)), 1, st, act);
return true;
case VMA_SELECT_AND_DELETE__PATH_REF:
diff --git a/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp b/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp
index 5376456540..2a06cf110d 100644
--- a/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp
@@ -164,7 +164,7 @@ Y_UNIT_TEST_SUITE(TSchemeMergeTest) {
v["a"] = NSc::TValue::FromJson("[0.125,0.12,0.1,0.08,0.06]");
UNIT_ASSERT_JSON_EQ_JSON(v, "{a:[0.125,0.12,0.1,0.08,0.06]}");
- NSc::TValue a = v.TrySelectOrAdd("a")->MergeUpdateJson("[1,2,3]");
+ NSc::TValue a = v.TrySelectOrAdd("a")->MergeUpdateJson("[1,2,3]");
UNIT_ASSERT_JSON_EQ_JSON(a, "[1,2,3]");
UNIT_ASSERT_JSON_EQ_JSON(v, "{a:[1,2,3]}");
diff --git a/library/cpp/scheme/tests/ut/scheme_path_ut.cpp b/library/cpp/scheme/tests/ut/scheme_path_ut.cpp
index 9d9fd2cf63..0d4d79d483 100644
--- a/library/cpp/scheme/tests/ut/scheme_path_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_path_ut.cpp
@@ -15,7 +15,7 @@ Y_UNIT_TEST_SUITE(TSchemePathTest) {
UNIT_ASSERT(!v.PathExists(path));
UNIT_ASSERT(NSc::TValue::PathValid(path));
UNIT_ASSERT(NSc::TValue::Same(v.TrySelect(path), NSc::Null()));
- *v.TrySelectOrAdd(path) = 1;
+ *v.TrySelectOrAdd(path) = 1;
NSc::NUt::AssertSchemeJson(expected, v);
UNIT_ASSERT(v.PathExists(path));
UNIT_ASSERT(1 == v.TrySelectOrAdd(path)->GetNumber());
@@ -33,19 +33,19 @@ Y_UNIT_TEST_SUITE(TSchemePathTest) {
UNIT_ASSERT(v.PathExists(""));
UNIT_ASSERT(v.PathExists("//"));
- UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
+ UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
NSc::NUt::AssertSchemeJson("null", v);
UNIT_ASSERT(NSc::TValue::Same(v.TrySelectAndDelete("//"), NSc::Null()));
NSc::NUt::AssertSchemeJson("null", v);
v.SetDict();
- UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
+ UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
NSc::NUt::AssertSchemeJson("{}", v);
UNIT_ASSERT(NSc::TValue::Same(v.TrySelectAndDelete("//"), NSc::Null()));
NSc::NUt::AssertSchemeJson("{}", v);
v.SetArray();
- UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
+ UNIT_ASSERT(NSc::TValue::Same(v, *v.TrySelectOrAdd("//")));
NSc::NUt::AssertSchemeJson("[]", v);
UNIT_ASSERT(NSc::TValue::Same(v.TrySelectAndDelete("//"), NSc::Null()));
NSc::NUt::AssertSchemeJson("[]", v);
@@ -63,7 +63,7 @@ Y_UNIT_TEST_SUITE(TSchemePathTest) {
Y_UNIT_TEST(TestSelectAndMerge) {
NSc::TValue v;
- v.TrySelectOrAdd("blender/enabled")->MergeUpdateJson("1");
+ v.TrySelectOrAdd("blender/enabled")->MergeUpdateJson("1");
UNIT_ASSERT_VALUES_EQUAL(NSc::TValue::FromJson("1").ToJson(), "1");
UNIT_ASSERT_VALUES_EQUAL(v.ToJson(), "{\"blender\":{\"enabled\":1}}");
}
@@ -97,61 +97,61 @@ Y_UNIT_TEST_SUITE(TSchemePathTest) {
{
NSc::TValue val;
- *val.TrySelectOrAdd("") = 100;
+ *val.TrySelectOrAdd("") = 100;
const TString res = R"=(100)=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd("a") = 100;
+ *val.TrySelectOrAdd("a") = 100;
const TString res = R"=({"a":100})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=(////)=") = 100;
+ *val.TrySelectOrAdd(R"=(////)=") = 100;
const TString res = R"=(100)=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=()=") = 100;
+ *val.TrySelectOrAdd(R"=()=") = 100;
const TString res = R"=(100)=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=("")=") = 100;
+ *val.TrySelectOrAdd(R"=("")=") = 100;
const TString res = R"=({"":100})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=("[1]")=") = 100;
+ *val.TrySelectOrAdd(R"=("[1]")=") = 100;
const TString res = R"=({"[1]":100})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=("\"\"")=") = 100;
+ *val.TrySelectOrAdd(R"=("\"\"")=") = 100;
const TString res = R"=({"\"\"":100})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=("/10/")=") = 100;
+ *val.TrySelectOrAdd(R"=("/10/")=") = 100;
const TString res = R"=({"/10/":100})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=(/"[10]"//""/"\"/10/\""///)=") = 100;
+ *val.TrySelectOrAdd(R"=(/"[10]"//""/"\"/10/\""///)=") = 100;
const TString res = R"=({"[10]":{"":{"\"/10/\"":100}}})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
{
NSc::TValue val;
- *val.TrySelectOrAdd(R"=(/"[10]"//""/"\"/10/\""///)=") = 100;
+ *val.TrySelectOrAdd(R"=(/"[10]"//""/"\"/10/\""///)=") = 100;
const TString res = R"=({"[10]":{"":{"\"/10/\"":100}}})=";
UNIT_ASSERT_VALUES_EQUAL(val.ToJson(), res);
}
diff --git a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
index 5379ef6164..e711a0d092 100644
--- a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
@@ -27,7 +27,7 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
if (mapAsDict) {
v[key] = value;
} else {
- auto& newElement = v.Push();
+ auto& newElement = v.Push();
newElement["key"] = key;
newElement["value"] = value;
}
diff --git a/library/cpp/scheme/tests/ut/scheme_ut.cpp b/library/cpp/scheme/tests/ut/scheme_ut.cpp
index 0ddefa7fea..1a5d07c31b 100644
--- a/library/cpp/scheme/tests/ut/scheme_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_ut.cpp
@@ -317,12 +317,12 @@ Y_UNIT_TEST_SUITE(TSchemeTest) {
}
Y_UNIT_TEST(TestAssignmentDictChild) {
- {
- NSc::TValue v;
- {
- NSc::TValue b;
- v["a"] = b;
- }
+ {
+ NSc::TValue v;
+ {
+ NSc::TValue b;
+ v["a"] = b;
+ }
v = v["a"];
}
{
@@ -331,7 +331,7 @@ Y_UNIT_TEST_SUITE(TSchemeTest) {
NSc::TValue b;
v["a"] = b;
}
- v = v.Get("a");
+ v = v.Get("a");
}
{
NSc::TValue v;
@@ -341,8 +341,8 @@ Y_UNIT_TEST_SUITE(TSchemeTest) {
}
v = std::move(v["a"]);
}
- }
-
+ }
+
Y_UNIT_TEST(TestInsert) {
NSc::TValue v;
v.Insert(0, "b");
@@ -767,18 +767,18 @@ Y_UNIT_TEST_SUITE(TSchemeTest) {
UNIT_ASSERT(w.IsDict());
UNIT_ASSERT_VALUES_EQUAL(w.Get("foo").GetString(), "baz");
}
- UNIT_ASSERT(NSc::TValue::DefaultValue().IsNull());
+ UNIT_ASSERT(NSc::TValue::DefaultValue().IsNull());
+ }
+
+ //SPI-25156
+ Y_UNIT_TEST(TestMoveNotCorruptingDefault) {
+ using namespace NSc;
+ TValue w = TValue::FromJson("{foo:bar}");
+ TValue v = std::move(w);
+ w["foo"] = "baz"; // no crash here
+ UNIT_ASSERT(NSc::TValue::DefaultValue().IsNull());
}
- //SPI-25156
- Y_UNIT_TEST(TestMoveNotCorruptingDefault) {
- using namespace NSc;
- TValue w = TValue::FromJson("{foo:bar}");
- TValue v = std::move(w);
- w["foo"] = "baz"; // no crash here
- UNIT_ASSERT(NSc::TValue::DefaultValue().IsNull());
- }
-
Y_UNIT_TEST(TestCopyFrom) {
{
TString sa = "[1,2]";
@@ -845,34 +845,34 @@ Y_UNIT_TEST_SUITE(TSchemeTest) {
}
}
- Y_UNIT_TEST(TestCopyingDictIntoSelf) { //Found by fuzzing
- NSc::TValue a;
- NSc::TValue b = a.GetOrAdd("aa");
- b.CopyFrom(a);
- NSc::TValue target = NSc::TValue::FromJsonThrow("{\"aa\":null}");
- UNIT_ASSERT_VALUES_EQUAL(b, target);
- UNIT_ASSERT_VALUES_EQUAL(a, target);
- }
-
- Y_UNIT_TEST(TestCopyingDictIntoSelfByRef) { //Found by fuzzing
- NSc::TValue a;
- NSc::TValue& b = a.GetOrAdd("aa");
- b.CopyFrom(a);
- UNIT_ASSERT_VALUES_EQUAL(b, NSc::TValue::FromJsonThrow("{\"aa\":null}"));
- UNIT_ASSERT_VALUES_EQUAL(a, NSc::TValue::FromJsonThrow("{\"aa\": {\"aa\": null}}"));
- }
-
+ Y_UNIT_TEST(TestCopyingDictIntoSelf) { //Found by fuzzing
+ NSc::TValue a;
+ NSc::TValue b = a.GetOrAdd("aa");
+ b.CopyFrom(a);
+ NSc::TValue target = NSc::TValue::FromJsonThrow("{\"aa\":null}");
+ UNIT_ASSERT_VALUES_EQUAL(b, target);
+ UNIT_ASSERT_VALUES_EQUAL(a, target);
+ }
+
+ Y_UNIT_TEST(TestCopyingDictIntoSelfByRef) { //Found by fuzzing
+ NSc::TValue a;
+ NSc::TValue& b = a.GetOrAdd("aa");
+ b.CopyFrom(a);
+ UNIT_ASSERT_VALUES_EQUAL(b, NSc::TValue::FromJsonThrow("{\"aa\":null}"));
+ UNIT_ASSERT_VALUES_EQUAL(a, NSc::TValue::FromJsonThrow("{\"aa\": {\"aa\": null}}"));
+ }
+
Y_UNIT_TEST(TestGetNoAdd) {
NSc::TValue v = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5}}");
- UNIT_ASSERT(v.GetNoAdd("a") != nullptr);
- UNIT_ASSERT(v.GetNoAdd("b") != nullptr);
- UNIT_ASSERT(v.GetNoAdd("c") != nullptr);
- UNIT_ASSERT(v.GetNoAdd("d") == nullptr);
- UNIT_ASSERT(v.GetNoAdd("value") == nullptr);
-
- NSc::TValue* child = v.GetNoAdd("c");
- UNIT_ASSERT(child != nullptr);
- (*child)["e"]["f"] = 42;
+ UNIT_ASSERT(v.GetNoAdd("a") != nullptr);
+ UNIT_ASSERT(v.GetNoAdd("b") != nullptr);
+ UNIT_ASSERT(v.GetNoAdd("c") != nullptr);
+ UNIT_ASSERT(v.GetNoAdd("d") == nullptr);
+ UNIT_ASSERT(v.GetNoAdd("value") == nullptr);
+
+ NSc::TValue* child = v.GetNoAdd("c");
+ UNIT_ASSERT(child != nullptr);
+ (*child)["e"]["f"] = 42;
const NSc::TValue expectedResult = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5,e:{f:42}}}");
UNIT_ASSERT_VALUES_EQUAL(v, expectedResult);
}