diff options
author | ivanmorozov <ivanmorozov@yandex-team.ru> | 2022-02-10 16:47:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:33 +0300 |
commit | cba5d9a444e2cfe105f55ccda66cd21d50440017 (patch) | |
tree | 79983e83d1a91aebeb1999338090eec69e24cc33 | |
parent | eb540cc7a103419462d0cc870ca403966e2194c6 (diff) | |
download | ydb-cba5d9a444e2cfe105f55ccda66cd21d50440017.tar.gz |
Restoring authorship annotation for <ivanmorozov@yandex-team.ru>. Commit 1 of 2.
53 files changed, 493 insertions, 493 deletions
diff --git a/build/plugins/res.py b/build/plugins/res.py index a937caba81..30dbd157a5 100644 --- a/build/plugins/res.py +++ b/build/plugins/res.py @@ -37,10 +37,10 @@ def remove_prefix(text, prefix): def onfat_resource(unit, *args): unit.onpeerdir(['library/cpp/resource']) - # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters, + # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters, # we make several calls of rescompiler # https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682425.aspx - for part_args in split(args, 8000): + for part_args in split(args, 8000): output = listid(part_args) + '.cpp' inputs = [x for x, y in iterpair(part_args) if x != '-'] if inputs: diff --git a/contrib/libs/libiconv/dynamic/libiconv.exports b/contrib/libs/libiconv/dynamic/libiconv.exports index c38a20d918..bd430f4a92 100644 --- a/contrib/libs/libiconv/dynamic/libiconv.exports +++ b/contrib/libs/libiconv/dynamic/libiconv.exports @@ -1,4 +1,4 @@ -C libiconv -C libiconv_open -C libiconv_close +C libiconv +C libiconv_open +C libiconv_close C libiconvctl
\ No newline at end of file diff --git a/contrib/libs/libidn/dynamic/libidn.exports b/contrib/libs/libidn/dynamic/libidn.exports index 586b60a0f8..729795e2af 100644 --- a/contrib/libs/libidn/dynamic/libidn.exports +++ b/contrib/libs/libidn/dynamic/libidn.exports @@ -1,5 +1,5 @@ -C idna_to_ascii_4i -C idna_to_unicode_44i +C idna_to_ascii_4i +C idna_to_unicode_44i C idna_to_ascii_4z C idna_to_unicode_44z C punycode_encode diff --git a/library/cpp/balloc/balloc.cpp b/library/cpp/balloc/balloc.cpp index fab489db4c..f27ae2ee9a 100644 --- a/library/cpp/balloc/balloc.cpp +++ b/library/cpp/balloc/balloc.cpp @@ -72,7 +72,7 @@ namespace NBalloc { tls.Mode = Disabled; #endif } - + static void Y_FORCE_INLINE Enable() { tls.Mode = ToBeEnabled; } @@ -278,10 +278,10 @@ extern "C" bool IsOwnedByBalloc(void* ptr) { return NBalloc::IsOwnedByBalloc(ptr); } -extern "C" bool BallocDisabled() { - return NBalloc::IsDisabled(); -} - +extern "C" bool BallocDisabled() { + return NBalloc::IsDisabled(); +} + extern "C" void DisableBalloc() { NBalloc::Disable(); } diff --git a/library/cpp/balloc/malloc-info.cpp b/library/cpp/balloc/malloc-info.cpp index 604b1fb145..a86edd5a0e 100644 --- a/library/cpp/balloc/malloc-info.cpp +++ b/library/cpp/balloc/malloc-info.cpp @@ -6,7 +6,7 @@ using namespace NMalloc; extern "C" void DisableBalloc(); extern "C" void EnableBalloc(); -extern "C" bool BallocDisabled(); +extern "C" bool BallocDisabled(); namespace { bool SetAllocParam(const char* name, const char* value) { @@ -21,13 +21,13 @@ namespace { } return false; } - + bool CheckAllocParam(const char* name, bool defaultValue) { - if (strcmp(name, "disable") == 0) { - return BallocDisabled(); - } - return defaultValue; - } + if (strcmp(name, "disable") == 0) { + return BallocDisabled(); + } + return defaultValue; + } } TMallocInfo NMalloc::MallocInfo() { @@ -35,7 +35,7 @@ TMallocInfo NMalloc::MallocInfo() { r.Name = "balloc"; r.SetParam = SetAllocParam; - r.CheckParam = CheckAllocParam; + r.CheckParam = CheckAllocParam; return r; } diff --git a/library/cpp/balloc/optional/operators.cpp b/library/cpp/balloc/optional/operators.cpp index 79f74a5806..302302ed89 100644 --- a/library/cpp/balloc/optional/operators.cpp +++ b/library/cpp/balloc/optional/operators.cpp @@ -1 +1 @@ -#include "operators.h" +#include "operators.h" diff --git a/library/cpp/balloc/optional/operators.h b/library/cpp/balloc/optional/operators.h index 6107d28a6e..3f9e7f4e35 100644 --- a/library/cpp/balloc/optional/operators.h +++ b/library/cpp/balloc/optional/operators.h @@ -1,15 +1,15 @@ -#pragma once - +#pragma once + #include <library/cpp/malloc/api/malloc.h> -#include <util/string/type.h> - -inline bool BallocEnabled() { - return !::NMalloc::MallocInfo().CheckParam("disable", true); -} - -inline void ThreadDisableBalloc() { - ::NMalloc::MallocInfo().SetParam("disable", "true"); -} +#include <util/string/type.h> + +inline bool BallocEnabled() { + return !::NMalloc::MallocInfo().CheckParam("disable", true); +} + +inline void ThreadDisableBalloc() { + ::NMalloc::MallocInfo().SetParam("disable", "true"); +} inline void ThreadEnableBalloc() { ::NMalloc::MallocInfo().SetParam("disable", "false"); diff --git a/library/cpp/balloc/optional/ya.make b/library/cpp/balloc/optional/ya.make index f740fc0b7d..a9fdce993b 100644 --- a/library/cpp/balloc/optional/ya.make +++ b/library/cpp/balloc/optional/ya.make @@ -1,15 +1,15 @@ -LIBRARY() - -OWNER(ivanmorozov) - -SRCS( - operators.cpp -) - -PEERDIR( +LIBRARY() + +OWNER(ivanmorozov) + +SRCS( + operators.cpp +) + +PEERDIR( library/cpp/malloc/api -) - -END() +) + +END() NEED_CHECK() diff --git a/library/cpp/http/misc/httpreqdata.cpp b/library/cpp/http/misc/httpreqdata.cpp index f6951f68cd..204c4b7b63 100644 --- a/library/cpp/http/misc/httpreqdata.cpp +++ b/library/cpp/http/misc/httpreqdata.cpp @@ -65,9 +65,9 @@ const char* TBaseServerRequestData::RemoteAddr() const { } const char* TBaseServerRequestData::HeaderIn(TStringBuf key) const { - auto it = HeadersIn_.find(key); + auto it = HeadersIn_.find(key); - if (it == HeadersIn_.end()) { + if (it == HeadersIn_.end()) { return nullptr; } @@ -108,7 +108,7 @@ const char* TBaseServerRequestData::Environment(const char* key) const { } void TBaseServerRequestData::Clear() { - HeadersIn_.clear(); + HeadersIn_.clear(); Addr = Path = Search = nullptr; OrigSearch = {}; SearchLength = 0; @@ -180,7 +180,7 @@ bool TBaseServerRequestData::Parse(const char* origReq) { } void TBaseServerRequestData::AddHeader(const TString& name, const TString& value) { - HeadersIn_[name] = value; + HeadersIn_[name] = value; if (stricmp(name.data(), "Host") == 0) { size_t hostLen = strcspn(value.data(), ":"); @@ -192,5 +192,5 @@ void TBaseServerRequestData::AddHeader(const TString& name, const TString& value void TBaseServerRequestData::SetPath(const TString& path) { PathStorage = TBuffer(path.data(), path.size() + 1); - Path = PathStorage.Data(); + Path = PathStorage.Data(); } diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index 16e59c4d78..7fd7745314 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -61,11 +61,11 @@ public: const char* HeaderIn(TStringBuf key) const; const THttpHeadersContainer& HeadersIn() const { - return HeadersIn_; - } - + return HeadersIn_; + } + inline size_t HeadersCount() const noexcept { - return HeadersIn_.size(); + return HeadersIn_.size(); } TString HeaderByIndex(size_t n) const noexcept; @@ -87,7 +87,7 @@ public: void AddHeader(const TString& name, const TString& value); private: - TBuffer PathStorage; + TBuffer PathStorage; mutable char* Addr; TString Host; TString Port; diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd7..6180660246 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -660,14 +660,14 @@ bool TClientRequest::CheckLoopback() { return true; } -void TClientRequest::ReleaseConnection() { +void TClientRequest::ReleaseConnection() { if (Conn_ && HttpConn_ && HttpServ()->Options().KeepAliveEnabled && HttpConn_->CanBeKeepAlive() && (!HttpServ()->Options().RejectExcessConnections || !HttpServ()->MaxRequestsReached())) { - Output().Finish(); - Conn_->DeActivate(); + Output().Finish(); + Conn_->DeActivate(); Y_UNUSED(Conn_.Release()); - } -} - + } +} + void TClientRequest::ResetConnection() { if (HttpConn_) { // send RST packet to client @@ -706,7 +706,7 @@ void TClientRequest::Process(void* ThreadSpecificResource) { } if (Reply(ThreadSpecificResource)) { - ReleaseConnection(); + ReleaseConnection(); /* * *this will be destroyed... diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index b292d38f27..e9e9c71c15 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -126,7 +126,7 @@ public: bool CheckLoopback(); void ProcessFailRequest(int failstate); - void ReleaseConnection(); + void ReleaseConnection(); void ResetConnection(); diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp index 3d058bae36..a6345e0943 100644 --- a/library/cpp/json/json_writer.cpp +++ b/library/cpp/json/json_writer.cpp @@ -118,22 +118,22 @@ namespace NJson { Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits); } - void TJsonWriter::Write(const TJsonValue& v) { - Buf.WriteJsonValue(&v, SortKeys, FloatToStringMode, DoubleNDigits); - } - + void TJsonWriter::Write(const TJsonValue& v) { + Buf.WriteJsonValue(&v, SortKeys, FloatToStringMode, DoubleNDigits); + } + TString WriteJson(const TJsonValue* value, bool formatOutput, bool sortkeys, bool validateUtf8) { TStringStream ss; WriteJson(&ss, value, formatOutput, sortkeys, validateUtf8); return ss.Str(); } - + TString WriteJson(const TJsonValue& value, bool formatOutput, bool sortkeys, bool validateUtf8) { TStringStream ss; WriteJson(&ss, &value, formatOutput, sortkeys, validateUtf8); return ss.Str(); } - + void WriteJson(IOutputStream* out, const TJsonValue* val, bool formatOutput, bool sortkeys, bool validateUtf8) { TJsonWriter w(out, formatOutput, sortkeys, validateUtf8); w.Write(val); diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h index c7f5c9499a..71b5e4d1d0 100644 --- a/library/cpp/json/json_writer.h +++ b/library/cpp/json/json_writer.h @@ -85,7 +85,7 @@ namespace NJson { void Write(double value); void Write(bool value); void Write(const TJsonValue* value); - void Write(const TJsonValue& value); + void Write(const TJsonValue& value); // must use all variations of integer types since long // and long long are different types but with same size diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp index c61e8d1dc4..fe9ae61505 100644 --- a/library/cpp/json/writer/json_value.cpp +++ b/library/cpp/json/writer/json_value.cpp @@ -9,7 +9,7 @@ #include <util/stream/output.h> #include <util/string/cast.h> #include <util/string/type.h> -#include <util/string/vector.h> +#include <util/string/vector.h> #include <util/system/yassert.h> #include <util/ysaveload.h> #include <util/generic/bt_exception.h> @@ -850,7 +850,7 @@ namespace NJson { } return currentJson; - } + } } // anonymous namespace bool TJsonValue::GetValueByPath(const TStringBuf path, TJsonValue& result, char delimiter) const { @@ -860,8 +860,8 @@ namespace NJson { return true; } return false; - } - + } + bool TJsonValue::SetValueByPath(const TStringBuf path, const TJsonValue& value, char delimiter) { TJsonValue* const ptr = GetValuePtrByPath<true>(this, path, delimiter); if (ptr) { @@ -886,12 +886,12 @@ namespace NJson { TJsonValue* TJsonValue::GetValueByPath(const TStringBuf key, char delim) noexcept { return GetValuePtrByPath<false>(this, key, delim); - } + } void TJsonValue::DoScan(const TString& path, TJsonValue* parent, IScanCallback& callback) { if (!callback.Do(path, parent, *this)) { return; - } + } if (Type == JSON_MAP) { for (auto&& i : *Value.Map) { @@ -901,9 +901,9 @@ namespace NJson { for (ui32 i = 0; i < Value.Array->size(); ++i) { (*Value.Array)[i].DoScan(TString::Join(path, "[", ToString(i), "]"), this, callback); } - } - } - + } + } + void TJsonValue::Scan(IScanCallback& callback) { DoScan("", nullptr, callback); } diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 3f0f50bc4c..b41712c5d6 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -27,13 +27,13 @@ namespace NJson { class IScanCallback { public: virtual ~IScanCallback() = default; - + virtual bool Do(const TString& path, TJsonValue* parent, TJsonValue& value) = 0; }; - + class TJsonValue { void Clear() noexcept; - + public: typedef THashMap<TString, TJsonValue> TMapType; typedef TDeque<TJsonValue> TArray; @@ -96,7 +96,7 @@ namespace NJson { // returns NULL on failure const TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') const noexcept; TJsonValue* GetValueByPath(TStringBuf path, char delimiter = '.') noexcept; - + void EraseValue(TStringBuf key); void EraseValue(size_t index); @@ -178,7 +178,7 @@ namespace NJson { /// Non-robust comparison. bool operator==(const TJsonValue& rhs) const; - + bool operator!=(const TJsonValue& rhs) const { return !(*this == rhs); } diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp index dc7f6affdf..40000bd68a 100644 --- a/library/cpp/json/writer/json_value_ut.cpp +++ b/library/cpp/json/writer/json_value_ut.cpp @@ -234,22 +234,22 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { } Y_UNIT_TEST(GetValueByPathTest) { - { - TJsonValue lhs; - TJsonValue first; - TJsonValue second; - TJsonValue last; - first.InsertValue("e", "f"); - second.InsertValue("c", first); - last.InsertValue("a", second); - lhs.InsertValue("l", last); - - TJsonValue result; + { + TJsonValue lhs; + TJsonValue first; + TJsonValue second; + TJsonValue last; + first.InsertValue("e", "f"); + second.InsertValue("c", first); + last.InsertValue("a", second); + lhs.InsertValue("l", last); + + TJsonValue result; UNIT_ASSERT(lhs.GetValueByPath("l/a/c/e", result, '/')); - UNIT_ASSERT(result.GetStringRobust() == "f"); + UNIT_ASSERT(result.GetStringRobust() == "f"); UNIT_ASSERT(!lhs.GetValueByPath("l/a/c/se", result, '/')); UNIT_ASSERT(lhs.GetValueByPath("l/a/c", result, '/')); - UNIT_ASSERT(result.GetStringRobust() == "{\"e\":\"f\"}"); + UNIT_ASSERT(result.GetStringRobust() == "{\"e\":\"f\"}"); // faster TStringBuf version UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l", '/'), last); @@ -282,9 +282,9 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { UNIT_ASSERT(lhs.SetValueByPath("l/a/c/se", "h", '/')); UNIT_ASSERT(lhs.GetValueByPath("l/a/c/se", result, '/')); UNIT_ASSERT(result.GetStringRobust() == "h"); - } - } - + } + } + Y_UNIT_TEST(GetValueByPathConstTest) { TJsonValue lhs; TJsonValue first; diff --git a/library/cpp/lcs/lcs_via_lis.cpp b/library/cpp/lcs/lcs_via_lis.cpp index 1a52608aed..ee385e84fd 100644 --- a/library/cpp/lcs/lcs_via_lis.cpp +++ b/library/cpp/lcs/lcs_via_lis.cpp @@ -1 +1 @@ -#include "lcs_via_lis.h" +#include "lcs_via_lis.h" diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index fd2a906d6f..1db0dc41eb 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -1574,7 +1574,7 @@ static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { static Y_FORCE_INLINE void* LFAlloc(size_t _nSize) { void* res = LFAllocImpl(_nSize); #ifdef DBG_FILL_MEMORY - if (FillMemoryOnAllocation && res && (_nSize <= DBG_FILL_MAX_SIZE)) { + if (FillMemoryOnAllocation && res && (_nSize <= DBG_FILL_MAX_SIZE)) { memset(res, 0xcf, _nSize); } #endif @@ -1817,12 +1817,12 @@ static bool LFAlloc_SetParam(const char* param, const char* value) { LB_LIMIT_TOTAL_SIZE = (atoi(value) + N_PAGE_SIZE - 1) / N_PAGE_SIZE; return true; } -#ifdef DBG_FILL_MEMORY - if (!strcmp(param, "FillMemoryOnAllocation")) { - FillMemoryOnAllocation = !strcmp(value, "true"); - return true; - } -#endif +#ifdef DBG_FILL_MEMORY + if (!strcmp(param, "FillMemoryOnAllocation")) { + FillMemoryOnAllocation = !strcmp(value, "true"); + return true; + } +#endif if (!strcmp(param, "TransparentHugePages")) { TransparentHugePages = !strcmp(value, "true"); return true; diff --git a/library/cpp/logger/backend.cpp b/library/cpp/logger/backend.cpp index b26bf5e88c..e0ea81471d 100644 --- a/library/cpp/logger/backend.cpp +++ b/library/cpp/logger/backend.cpp @@ -1,66 +1,66 @@ #include "backend.h" -#include <util/generic/vector.h> -#include <util/system/mutex.h> -#include <util/generic/singleton.h> +#include <util/generic/vector.h> +#include <util/system/mutex.h> +#include <util/generic/singleton.h> #include <util/generic/yexception.h> -namespace { - class TGlobalLogsStorage { - private: +namespace { + class TGlobalLogsStorage { + private: TVector<TLogBackend*> Backends; - TMutex Mutex; + TMutex Mutex; - public: - void Register(TLogBackend* backend) { - TGuard<TMutex> g(Mutex); - Backends.push_back(backend); - } - - void UnRegister(TLogBackend* backend) { - TGuard<TMutex> g(Mutex); - for (ui32 i = 0; i < Backends.size(); ++i) { - if (Backends[i] == backend) { - Backends.erase(Backends.begin() + i); - return; - } - } + public: + void Register(TLogBackend* backend) { + TGuard<TMutex> g(Mutex); + Backends.push_back(backend); + } + + void UnRegister(TLogBackend* backend) { + TGuard<TMutex> g(Mutex); + for (ui32 i = 0; i < Backends.size(); ++i) { + if (Backends[i] == backend) { + Backends.erase(Backends.begin() + i); + return; + } + } Y_FAIL("Incorrect pointer for log backend"); - } - + } + void Reopen(bool flush) { - TGuard<TMutex> g(Mutex); - for (auto& b : Backends) { + TGuard<TMutex> g(Mutex); + for (auto& b : Backends) { if (flush) { b->ReopenLog(); } else { b->ReopenLogNoFlush(); } - } - } - }; -} - + } + } + }; +} + template <> -class TSingletonTraits<TGlobalLogsStorage> { -public: - static const size_t Priority = 50; -}; - +class TSingletonTraits<TGlobalLogsStorage> { +public: + static const size_t Priority = 50; +}; + ELogPriority TLogBackend::FiltrationLevel() const { - return LOG_MAX_PRIORITY; -} - + return LOG_MAX_PRIORITY; +} + TLogBackend::TLogBackend() noexcept { - Singleton<TGlobalLogsStorage>()->Register(this); + Singleton<TGlobalLogsStorage>()->Register(this); } TLogBackend::~TLogBackend() { - Singleton<TGlobalLogsStorage>()->UnRegister(this); + Singleton<TGlobalLogsStorage>()->UnRegister(this); } - + void TLogBackend::ReopenLogNoFlush() { ReopenLog(); -} +} void TLogBackend::ReopenAllBackends(bool flush) { Singleton<TGlobalLogsStorage>()->Reopen(flush); diff --git a/library/cpp/logger/backend.h b/library/cpp/logger/backend.h index d088726d6d..791771ced9 100644 --- a/library/cpp/logger/backend.h +++ b/library/cpp/logger/backend.h @@ -23,7 +23,7 @@ public: virtual void ReopenLogNoFlush(); virtual ELogPriority FiltrationLevel() const; - + static void ReopenAllBackends(bool flush = true); virtual size_t QueueSize() const; diff --git a/library/cpp/logger/filter.cpp b/library/cpp/logger/filter.cpp index 300ac6b595..2007e4e56a 100644 --- a/library/cpp/logger/filter.cpp +++ b/library/cpp/logger/filter.cpp @@ -1 +1 @@ -#include "filter.h" +#include "filter.h" diff --git a/library/cpp/logger/filter.h b/library/cpp/logger/filter.h index 9ef83fb58c..4cc66ff512 100644 --- a/library/cpp/logger/filter.h +++ b/library/cpp/logger/filter.h @@ -1,32 +1,32 @@ -#pragma once +#pragma once -#include "priority.h" -#include "record.h" -#include "backend.h" -#include <util/generic/ptr.h> - -class TFilteredLogBackend: public TLogBackend { +#include "priority.h" +#include "record.h" +#include "backend.h" +#include <util/generic/ptr.h> + +class TFilteredLogBackend: public TLogBackend { THolder<TLogBackend> Backend; ELogPriority Level; -public: +public: TFilteredLogBackend(THolder<TLogBackend>&& t, ELogPriority level = LOG_MAX_PRIORITY) noexcept : Backend(std::move(t)) - , Level(level) - { - } - + , Level(level) + { + } + ELogPriority FiltrationLevel() const override { - return Level; - } - + return Level; + } + void ReopenLog() override { - Backend->ReopenLog(); - } - + Backend->ReopenLog(); + } + void WriteData(const TLogRecord& rec) override { if (rec.Priority <= (ELogPriority)Level) { - Backend->WriteData(rec); - } - } -}; + Backend->WriteData(rec); + } + } +}; diff --git a/library/cpp/logger/global/common.cpp b/library/cpp/logger/global/common.cpp index 4fb05c19b4..844936cebe 100644 --- a/library/cpp/logger/global/common.cpp +++ b/library/cpp/logger/global/common.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include <util/generic/yexception.h> diff --git a/library/cpp/logger/global/common.h b/library/cpp/logger/global/common.h index 7dcf650dec..52daf1f5be 100644 --- a/library/cpp/logger/global/common.h +++ b/library/cpp/logger/global/common.h @@ -12,10 +12,10 @@ #include <library/cpp/logger/log.h> -namespace NLoggingImpl { - const size_t SingletonPriority = 500; -} - +namespace NLoggingImpl { + const size_t SingletonPriority = 500; +} + template <class T> T* CreateDefaultLogger() { return nullptr; @@ -35,15 +35,15 @@ namespace NLoggingImpl { public: inline static bool Usage() { - return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); + return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); } inline static T* Get() { - return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); + return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); } inline static void Set(T* v) { - SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Reset(v); + SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Reset(v); } }; @@ -62,8 +62,8 @@ public: Y_ASSERT(TLoggerOperator::Usage()); return *TLoggerOperator::Get(); } -}; - +}; + namespace NLoggingImpl { TString GetLocalTimeSSimple(); diff --git a/library/cpp/logger/global/global.cpp b/library/cpp/logger/global/global.cpp index 9fbd10f666..1a9dc8c1c7 100644 --- a/library/cpp/logger/global/global.cpp +++ b/library/cpp/logger/global/global.cpp @@ -1,12 +1,12 @@ -#include "global.h" - +#include "global.h" + static void DoInitGlobalLog(THolder<TGlobalLog> logger, THolder<ILoggerFormatter> formatter) { TLoggerOperator<TGlobalLog>::Set(logger.Release()); if (!formatter) { formatter.Reset(CreateRtyLoggerFormatter()); } TLoggerFormatterOperator::Set(formatter.Release()); -} +} void DoInitGlobalLog(const TString& logType, const int logLevel, const bool rotation, const bool startAsDaemon, THolder<ILoggerFormatter> formatter, bool threaded) { DoInitGlobalLog( @@ -35,9 +35,9 @@ template <> TNullLog* CreateDefaultLogger<TNullLog>() { return new TNullLog("null"); } - -NPrivateGlobalLogger::TVerifyEvent::~TVerifyEvent() { - const TString info = Str(); - FATAL_LOG << info << Endl; + +NPrivateGlobalLogger::TVerifyEvent::~TVerifyEvent() { + const TString info = Str(); + FATAL_LOG << info << Endl; Y_FAIL("%s", info.data()); -} +} diff --git a/library/cpp/logger/global/global.h b/library/cpp/logger/global/global.h index cbe71b16ea..0692b79c9a 100644 --- a/library/cpp/logger/global/global.h +++ b/library/cpp/logger/global/global.h @@ -1,26 +1,26 @@ -#pragma once - -#include "common.h" +#pragma once + +#include "common.h" #include "rty_formater.h" - -// ATTENTION! MUST CALL DoInitGlobalLog BEFORE USAGE - + +// ATTENTION! MUST CALL DoInitGlobalLog BEFORE USAGE + bool GlobalLogInitialized(); void DoInitGlobalLog(const TString& logType, const int logLevel, const bool rotation, const bool startAsDaemon, THolder<ILoggerFormatter> formatter = {}, bool threaded = false); void DoInitGlobalLog(THolder<TLogBackend> backend, THolder<ILoggerFormatter> formatter = {}); - -inline void InitGlobalLog2Null() { + +inline void InitGlobalLog2Null() { DoInitGlobalLog("null", TLOG_EMERG, false, false); -} - -inline void InitGlobalLog2Console(int loglevel = TLOG_INFO) { - DoInitGlobalLog("console", loglevel, false, false); -} - -class TGlobalLog: public TLog { -public: +} + +inline void InitGlobalLog2Console(int loglevel = TLOG_INFO) { + DoInitGlobalLog("console", loglevel, false, false); +} + +class TGlobalLog: public TLog { +public: TGlobalLog(const TString& logType, ELogPriority priority = LOG_MAX_PRIORITY) - : TLog(logType, priority) + : TLog(logType, priority) { } @@ -28,15 +28,15 @@ public: : TLog(std::move(backend)) { } -}; - +}; + template <> TGlobalLog* CreateDefaultLogger<TGlobalLog>(); -class TNullLog: public TLog { -public: +class TNullLog: public TLog { +public: TNullLog(const TString& logType, ELogPriority priority = LOG_MAX_PRIORITY) - : TLog(logType, priority) + : TLog(logType, priority) { } @@ -44,8 +44,8 @@ public: : TLog(std::move(backend)) { } -}; - +}; + template <> TNullLog* CreateDefaultLogger<TNullLog>(); @@ -62,21 +62,21 @@ public: }; #define FATAL_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_CRIT, "CRITICAL_INFO") -#define ALERT_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ALERT, "ALERT") +#define ALERT_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ALERT, "ALERT") #define ERROR_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ERR, "ERROR") #define WARNING_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_WARNING, "WARNING") #define NOTICE_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_NOTICE, "NOTICE") #define INFO_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_INFO, "INFO") #define DEBUG_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_DEBUG, "DEBUG") #define RESOURCES_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_RESOURCES, "RESOURCES") - + #define TEMPLATE_LOG(logLevel) SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, logLevel, ToString(logLevel).data()) -#define IS_LOG_ACTIVE(logLevel) (TLoggerOperator<TGlobalLog>::Log().FiltrationLevel() >= logLevel) - +#define IS_LOG_ACTIVE(logLevel) (TLoggerOperator<TGlobalLog>::Log().FiltrationLevel() >= logLevel) + #define RTY_MEM_LOG(Action) \ { NOTICE_LOG << "RESOURCES On " << Action << ": " << NLoggingImpl::GetSystemResources() << Endl; }; - + #define VERIFY_WITH_LOG(expr, msg, ...) \ do { \ if (Y_UNLIKELY(!(expr))) { \ @@ -84,42 +84,42 @@ public: Y_VERIFY(false, msg, ##__VA_ARGS__); \ }; \ } while (0); - -namespace NPrivateGlobalLogger { - class TVerifyEvent: public TStringStream { - public: - ~TVerifyEvent(); - template <class T> + +namespace NPrivateGlobalLogger { + class TVerifyEvent: public TStringStream { + public: + ~TVerifyEvent(); + template <class T> inline TVerifyEvent& operator<<(const T& t) { static_cast<IOutputStream&>(*this) << t; - - return *this; - } - }; - class TNullStream: public TStringStream { - public: - ~TNullStream() = default; - - template <class T> - inline TNullStream& operator<<(const T& /*t*/) { - return *this; - } - }; -} - -#define CHECK_WITH_LOG(expr) \ - Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " - -#if !defined(NDEBUG) && !defined(__GCCXML__) -#define ASSERT_WITH_LOG(expr) \ - Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " -#else -#define ASSERT_WITH_LOG(expr) \ - Y_UNLIKELY(false && !(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TNullStream() -#endif - -#define CHECK_EQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) == (b)) << a << " != " << b; -#define CHECK_LEQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) <= (b)) << a << " > " << b; - + + return *this; + } + }; + class TNullStream: public TStringStream { + public: + ~TNullStream() = default; + + template <class T> + inline TNullStream& operator<<(const T& /*t*/) { + return *this; + } + }; +} + +#define CHECK_WITH_LOG(expr) \ + Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " + +#if !defined(NDEBUG) && !defined(__GCCXML__) +#define ASSERT_WITH_LOG(expr) \ + Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " +#else +#define ASSERT_WITH_LOG(expr) \ + Y_UNLIKELY(false && !(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TNullStream() +#endif + +#define CHECK_EQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) == (b)) << a << " != " << b; +#define CHECK_LEQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) <= (b)) << a << " > " << b; + #define FAIL_LOG(msg, ...) VERIFY_WITH_LOG(false, msg, ##__VA_ARGS__) -#define S_FAIL_LOG CHECK_WITH_LOG(false) +#define S_FAIL_LOG CHECK_WITH_LOG(false) diff --git a/library/cpp/logger/global/ya.make b/library/cpp/logger/global/ya.make index 20eb361e72..843f01016c 100644 --- a/library/cpp/logger/global/ya.make +++ b/library/cpp/logger/global/ya.make @@ -6,10 +6,10 @@ PEERDIR( library/cpp/logger ) -IF (OS_WINDOWS) - NO_WERROR() -ENDIF() - +IF (OS_WINDOWS) + NO_WERROR() +ENDIF() + SRCS( common.cpp global.cpp diff --git a/library/cpp/logger/log.cpp b/library/cpp/logger/log.cpp index e1d70cc3d2..23bfea0e0c 100644 --- a/library/cpp/logger/log.cpp +++ b/library/cpp/logger/log.cpp @@ -101,13 +101,13 @@ public: inline void WriteData(ELogPriority priority, const char* data, size_t len) const { if (IsOpen()) { Backend_->WriteData(TLogRecord(priority, data, len)); - } + } } - + inline ELogPriority DefaultPriority() noexcept { return DefaultPriority_; } - + inline void SetDefaultPriority(ELogPriority priority) noexcept { DefaultPriority_ = priority; } @@ -197,9 +197,9 @@ void TLog::SetDefaultPriority(ELogPriority priority) noexcept { } ELogPriority TLog::FiltrationLevel() const noexcept { - return Impl_->FiltrationLevel(); -} - + return Impl_->FiltrationLevel(); +} + ELogPriority TLog::DefaultPriority() const noexcept { return Impl_->DefaultPriority(); } diff --git a/library/cpp/logger/log.h b/library/cpp/logger/log.h index 8be984ccc8..09ab9ba1a5 100644 --- a/library/cpp/logger/log.h +++ b/library/cpp/logger/log.h @@ -85,7 +85,7 @@ public: // Call `FiltrationLevel()` of the underlying backend. ELogPriority FiltrationLevel() const noexcept; - + // Set current log formatter. void SetFormatter(TLogFormatter formatter) noexcept; diff --git a/library/cpp/malloc/api/malloc.cpp b/library/cpp/malloc/api/malloc.cpp index eed1c58a38..c417c3bb74 100644 --- a/library/cpp/malloc/api/malloc.cpp +++ b/library/cpp/malloc/api/malloc.cpp @@ -13,10 +13,10 @@ namespace { } bool CheckEmptyParam(const char*, bool defaultValue) { - return defaultValue; - } + return defaultValue; + } } - + namespace NMalloc { volatile bool IsAllocatorCorrupted = false; @@ -24,7 +24,7 @@ namespace NMalloc { : Name() , SetParam(SetEmptyParam) , GetParam(GetEmptyParam) - , CheckParam(CheckEmptyParam) + , CheckParam(CheckEmptyParam) { } diff --git a/library/cpp/malloc/api/malloc.h b/library/cpp/malloc/api/malloc.h index ebd545d6dd..f6aa9b9640 100644 --- a/library/cpp/malloc/api/malloc.h +++ b/library/cpp/malloc/api/malloc.h @@ -12,7 +12,7 @@ namespace NMalloc { bool (*SetParam)(const char* param, const char* value); const char* (*GetParam)(const char* param); - bool (*CheckParam)(const char* param, bool defaultValue); + bool (*CheckParam)(const char* param, bool defaultValue); }; extern volatile bool IsAllocatorCorrupted; diff --git a/library/cpp/messagebus/scheduler/scheduler.cpp b/library/cpp/messagebus/scheduler/scheduler.cpp index 5a5fe52894..7ed8576e27 100644 --- a/library/cpp/messagebus/scheduler/scheduler.cpp +++ b/library/cpp/messagebus/scheduler/scheduler.cpp @@ -26,11 +26,11 @@ TScheduler::~TScheduler() { Y_VERIFY(StopThread, "state check"); } -size_t TScheduler::Size() const { - TGuard<TLock> guard(Lock); - return Items.size() + (!!NextItem ? 1 : 0); -} - +size_t TScheduler::Size() const { + TGuard<TLock> guard(Lock); + return Items.size() + (!!NextItem ? 1 : 0); +} + void TScheduler::Stop() { { TGuard<TLock> guard(Lock); @@ -39,11 +39,11 @@ void TScheduler::Stop() { CondVar.Signal(); } Thread.Get(); - - if (!!NextItem) { - NextItem.Destroy(); - } - + + if (!!NextItem) { + NextItem.Destroy(); + } + for (auto& item : Items) { item.Destroy(); } @@ -105,7 +105,7 @@ void TScheduler::SchedulerThread() { continue; } - current = NextItem.Release(); + current = NextItem.Release(); } current->Do(); diff --git a/library/cpp/object_factory/object_factory.h b/library/cpp/object_factory/object_factory.h index 96cc11bcfd..82085e0929 100644 --- a/library/cpp/object_factory/object_factory.h +++ b/library/cpp/object_factory/object_factory.h @@ -38,7 +38,7 @@ namespace NObjectFactory { return new TDerivedProduct(std::forward<TArgs>(args)...); } }; - + template <class TBaseProduct, class TDerivedProduct> class TFactoryObjectCreator<TBaseProduct, TDerivedProduct, void>: public IFactoryObjectCreator<TBaseProduct, void> { TDerivedProduct* Create() const override { @@ -82,12 +82,12 @@ namespace NObjectFactory { typename ICreators::const_iterator i = Creators.find(key); return i == Creators.end() ? nullptr : i->second.Get(); } - + bool HasImpl(const TKey& key) const { TReadGuard guard(CreatorsLock); return Creators.find(key) != Creators.end(); } - + private: typedef TSimpleSharedPtr<IFactoryObjectCreator<TProduct, TArgs...>> ICreatorPtr; typedef TMap<TKey, ICreatorPtr> ICreators; @@ -119,8 +119,8 @@ namespace NObjectFactory { result = Singleton<TObjectFactory<TProduct, TKey>>()->Create(defKey); } return result; - } - + } + static TProduct* Construct(const TKey& key) { TProduct* result = Singleton<TObjectFactory<TProduct, TKey>>()->Create(key); return result; @@ -139,8 +139,8 @@ namespace NObjectFactory { static bool Has(const TKey& key) { return Singleton<TObjectFactory<TProduct, TKey>>()->HasImpl(key); - } - + } + static void GetRegisteredKeys(TSet<TKey>& keys) { return Singleton<TObjectFactory<TProduct, TKey>>()->GetKeys(keys); } @@ -168,7 +168,7 @@ namespace NObjectFactory { TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, void>* creator) { Singleton<TObjectFactory<TProduct, TKey>>()->template Register<Product>(key, creator); } - + TRegistrator(const TKey& key) { Singleton<TObjectFactory<TProduct, TKey>>()->template Register<Product>(key); } @@ -179,7 +179,7 @@ namespace NObjectFactory { } }; }; - + template <class TProduct, class TKey, class... TArgs> class TParametrizedObjectFactory: public IObjectFactory<TProduct, TKey, TArgs...> { public: @@ -190,7 +190,7 @@ namespace NObjectFactory { static bool Has(const TKey& key) { return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->HasImpl(key); - } + } static TProduct* Construct(const TKey& key, TArgs... args) { return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); @@ -224,7 +224,7 @@ namespace NObjectFactory { TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key, creator); } - + TRegistrator(const TKey& key) { Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key); } @@ -233,10 +233,10 @@ namespace NObjectFactory { : TRegistrator(Product::GetTypeName()) { } - - TString GetName() const { - return Product::GetTypeName(); - } + + TString GetName() const { + return Product::GetTypeName(); + } }; }; diff --git a/library/cpp/unicode/normalization/normalization.h b/library/cpp/unicode/normalization/normalization.h index 4f5f57881c..8d9d671351 100644 --- a/library/cpp/unicode/normalization/normalization.h +++ b/library/cpp/unicode/normalization/normalization.h @@ -358,7 +358,7 @@ namespace NUnicode { //! decompose utf16 or utf32 string to any container supporting push_back or to T* template <NUnicode::ENormalization Norm, class T, typename TCharType> inline void Normalize(const TCharType* begin, size_t len, T& out) { - ::NUnicode::TNormalizer<Norm> dec; + ::NUnicode::TNormalizer<Norm> dec; dec.Normalize(begin, len, out); } @@ -374,7 +374,7 @@ inline TBasicString<TCharType> Normalize(const TCharType* str, size_t len) { template <NUnicode::ENormalization N, typename TCharType> inline TBasicString<TCharType> Normalize(const TBasicString<TCharType>& str) { - ::NUnicode::TNormalizer<N> dec; + ::NUnicode::TNormalizer<N> dec; return dec.Normalize(str); } diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..dd0754969b 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -153,7 +153,7 @@ inline size_t WriteSymbol(wchar16 s, T& dest) noexcept { template <class T> inline size_t WriteSymbol(wchar32 s, T& dest) noexcept { if (s > 0xFFFF) { - if (s >= ::NUnicode::UnicodeInstancesLimit()) { + if (s >= ::NUnicode::UnicodeInstancesLimit()) { return WriteSymbol(static_cast<wchar16>(BROKEN_RUNE), dest); } diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..52606b3846 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -17,7 +17,7 @@ void SlashFolderLocal(TString& folder) { #ifdef _win32_ size_t pos; while ((pos = folder.find('/')) != TString::npos) - folder.replace(pos, 1, LOCSLASH_S); + folder.replace(pos, 1, LOCSLASH_S); #endif if (folder[folder.size() - 1] != LOCSLASH_C) folder.append(LOCSLASH_S); @@ -506,7 +506,7 @@ const char* GetFileNameComponent(const char* f) { } TString GetSystemTempDir() { -#ifdef _win_ +#ifdef _win_ char buffer[1024]; DWORD size = GetTempPath(1024, buffer); if (!size) { @@ -527,14 +527,14 @@ TString ResolveDir(const char* path) { } bool SafeResolveDir(const char* path, TString& result) { - try { - result = ResolvePath(path, true); - return true; - } catch (...) { - return false; - } -} - + try { + result = ResolvePath(path, true); + return true; + } catch (...) { + return false; + } +} + TString GetDirName(const TString& path) { return TFsPath(path).Dirname(); } diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..d095e0a900 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -82,7 +82,7 @@ TString ResolvePath(const char* path, bool isDir = false); TString ResolveDir(const char* path); bool SafeResolveDir(const char* path, TString& result); - + TString GetDirName(const TString& path); TString GetBaseName(const TString& path); diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp index b21fcdbf20..0f86fef549 100644 --- a/util/folder/filelist.cpp +++ b/util/folder/filelist.cpp @@ -13,15 +13,15 @@ void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringB TDirIterator dir(dirname, opts); Clear(); - + size_t dirNameLength = dirname.length(); while (dirNameLength && (dirname[dirNameLength - 1] == '\\' || dirname[dirNameLength - 1] == '/')) { --dirNameLength; } - + for (auto file = dir.begin(); file != dir.end(); ++file) { if (file->fts_pathlen == file->fts_namelen || file->fts_pathlen <= dirNameLength) { - continue; + continue; } TStringBuf filename = file->fts_path + dirNameLength + 1; diff --git a/util/folder/path.cpp b/util/folder/path.cpp index bfe0c67d68..821ca18ba2 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -365,7 +365,7 @@ void TFsPath::DeleteIfExists() const { void TFsPath::MkDir(const int mode) const { CheckDefined(); - if (!Exists()) { + if (!Exists()) { int r = Mkdir(this->c_str(), mode); if (r != 0) { // TODO (stanly) will still fail on Windows because @@ -375,11 +375,11 @@ void TFsPath::MkDir(const int mode) const { ythrow TIoSystemError() << "could not create directory " << Path_; } } - } + } } void TFsPath::MkDirs(const int mode) const { - CheckDefined(); + CheckDefined(); if (!Exists()) { Parent().MkDirs(mode); MkDir(mode); @@ -423,41 +423,41 @@ void TFsPath::ForceDelete() const { } void TFsPath::CopyTo(const TString& newPath, bool force) const { - if (IsDirectory()) { - if (force) { - TFsPath(newPath).MkDirs(); - } else if (!TFsPath(newPath).IsDirectory()) { + if (IsDirectory()) { + if (force) { + TFsPath(newPath).MkDirs(); + } else if (!TFsPath(newPath).IsDirectory()) { ythrow TIoException() << "Target path is not a directory " << newPath; - } + } TVector<TFsPath> children; - List(children); - for (auto&& i : children) { - i.CopyTo(newPath + "/" + i.GetName(), force); - } - } else { - if (force) { - TFsPath(newPath).Parent().MkDirs(); - } else { - if (!TFsPath(newPath).Parent().IsDirectory()) { + List(children); + for (auto&& i : children) { + i.CopyTo(newPath + "/" + i.GetName(), force); + } + } else { + if (force) { + TFsPath(newPath).Parent().MkDirs(); + } else { + if (!TFsPath(newPath).Parent().IsDirectory()) { ythrow TIoException() << "Parent (" << TFsPath(newPath).Parent() << ") of a target path is not a directory " << newPath; - } - if (TFsPath(newPath).Exists()) { + } + if (TFsPath(newPath).Exists()) { ythrow TIoException() << "Path already exists " << newPath; - } - } - NFs::Copy(Path_, newPath); - } -} - + } + } + NFs::Copy(Path_, newPath); + } +} + void TFsPath::ForceRenameTo(const TString& newPath) const { - try { - RenameTo(newPath); + try { + RenameTo(newPath); } catch (const TIoSystemError& /* error */) { - CopyTo(newPath, true); - ForceDelete(); - } -} - + CopyTo(newPath, true); + ForceDelete(); + } +} + TFsPath TFsPath::Cwd() { return TFsPath(::NFs::CurrentWorkingDirectory()); } diff --git a/util/folder/path.h b/util/folder/path.h index 2fb4d6b4ef..904f6199d6 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -139,8 +139,8 @@ public: * @brief create this directory * * @param mode specifies permissions to use as described in mkdir(2), makes sense only on Unix-like systems. - * - * Nothing to do if dir exists. + * + * Nothing to do if dir exists. */ void MkDir(const int mode = MODE0777) const; @@ -187,7 +187,7 @@ public: void ForceRenameTo(const TString& newPath) const; void CopyTo(const TString& newPath, bool force) const; - + void Touch() const; TFsPath RealPath() const; diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index e6a3451016..e6a42f2e09 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -56,36 +56,36 @@ namespace { Y_UNIT_TEST_SUITE(TFsPathTests) { Y_UNIT_TEST(TestMkDirs) { - const TFsPath path = "a/b/c/d/e/f"; - path.ForceDelete(); - TFsPath current = path; - ui32 checksCounter = 0; - while (current != ".") { - UNIT_ASSERT(!path.Exists()); - ++checksCounter; - current = current.Parent(); - } + const TFsPath path = "a/b/c/d/e/f"; + path.ForceDelete(); + TFsPath current = path; + ui32 checksCounter = 0; + while (current != ".") { + UNIT_ASSERT(!path.Exists()); + ++checksCounter; + current = current.Parent(); + } UNIT_ASSERT_VALUES_EQUAL(checksCounter, 6); - - path.MkDirs(); - UNIT_ASSERT(path.Exists()); - - current = path; - while (current != ".") { - UNIT_ASSERT(path.Exists()); - current = current.Parent(); - } - } - + + path.MkDirs(); + UNIT_ASSERT(path.Exists()); + + current = path; + while (current != ".") { + UNIT_ASSERT(path.Exists()); + current = current.Parent(); + } + } + Y_UNIT_TEST(MkDirFreak) { - TFsPath path; + TFsPath path; UNIT_ASSERT_EXCEPTION(path.MkDir(), TIoException); UNIT_ASSERT_EXCEPTION(path.MkDirs(), TIoException); - path = "."; - path.MkDir(); - path.MkDirs(); - } - + path = "."; + path.MkDir(); + path.MkDirs(); + } + Y_UNIT_TEST(Parent) { #ifdef _win_ UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc/passwd").Parent(), TFsPath("\\etc")); @@ -149,25 +149,25 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { } Y_UNIT_TEST(TestForceRename) { - TTestDirectory xx("TestForceRename"); - TFsPath fMain = xx.Child("main"); - - TFsPath f1 = fMain.Child("f1"); - f1.MkDirs(); - TFsPath f1Child = f1.Child("f1child"); - f1Child.Touch(); - - TFsPath f2 = fMain.Child("f2"); - f2.MkDirs(); - - fMain.ForceRenameTo("TestForceRename/main1"); - - UNIT_ASSERT(!xx.Child("main").Exists()); - UNIT_ASSERT(xx.Child("main1").Child("f1").Exists()); - UNIT_ASSERT(xx.Child("main1").Child("f2").Exists()); - UNIT_ASSERT(xx.Child("main1").Child("f1").Child("f1child").Exists()); - } - + TTestDirectory xx("TestForceRename"); + TFsPath fMain = xx.Child("main"); + + TFsPath f1 = fMain.Child("f1"); + f1.MkDirs(); + TFsPath f1Child = f1.Child("f1child"); + f1Child.Touch(); + + TFsPath f2 = fMain.Child("f2"); + f2.MkDirs(); + + fMain.ForceRenameTo("TestForceRename/main1"); + + UNIT_ASSERT(!xx.Child("main").Exists()); + UNIT_ASSERT(xx.Child("main1").Child("f1").Exists()); + UNIT_ASSERT(xx.Child("main1").Child("f2").Exists()); + UNIT_ASSERT(xx.Child("main1").Child("f1").Child("f1child").Exists()); + } + Y_UNIT_TEST(TestRenameFail) { UNIT_ASSERT_EXCEPTION(TFsPath("sfsfsfsdfsfsdfdf").RenameTo("sdfsdf"), TIoException); } diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..37d9cf435e 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -9,16 +9,16 @@ #include <util/stream/output.h> #include <util/ysaveload.h> -namespace NMaybe { - struct TPolicyUndefinedExcept { +namespace NMaybe { + struct TPolicyUndefinedExcept { [[noreturn]] static void OnEmpty(const std::type_info& valueTypeInfo); - }; - - struct TPolicyUndefinedFail { + }; + + struct TPolicyUndefinedFail { [[noreturn]] static void OnEmpty(const std::type_info& valueTypeInfo); - }; -} - + }; +} + struct TNothing { explicit constexpr TNothing(int) noexcept { } @@ -448,9 +448,9 @@ private: } }; -template <class T> -using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; - +template <class T> +using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; + template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept> constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) { return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value)); diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h index 5257afa2e6..56635bcc42 100644 --- a/util/generic/object_counter.h +++ b/util/generic/object_counter.h @@ -23,10 +23,10 @@ public: AtomicIncrement(Count_); } - inline TObjectCounter(const TObjectCounter& /*item*/) noexcept { - AtomicIncrement(Count_); - } - + inline TObjectCounter(const TObjectCounter& /*item*/) noexcept { + AtomicIncrement(Count_); + } + inline ~TObjectCounter() { AtomicDecrement(Count_); } diff --git a/util/generic/objects_counter_ut.cpp b/util/generic/objects_counter_ut.cpp index 4d5da37a56..d12a1e78c6 100644 --- a/util/generic/objects_counter_ut.cpp +++ b/util/generic/objects_counter_ut.cpp @@ -1,36 +1,36 @@ -#include "object_counter.h" - +#include "object_counter.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(ObjectsCounter) { - struct TObject: public TObjectCounter<TObject> { - }; - + struct TObject: public TObjectCounter<TObject> { + }; + Y_UNIT_TEST(Test1) { - TObject obj; + TObject obj; TVector<TObject> objects; - for (ui32 i = 0; i < 100; ++i) { - objects.push_back(obj); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 101); - } - + for (ui32 i = 0; i < 100; ++i) { + objects.push_back(obj); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 101); + } + Y_UNIT_TEST(TestEq) { - TObject obj; - { - TObject obj1 = obj; - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - } - + TObject obj; + { + TObject obj1 = obj; + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + } + Y_UNIT_TEST(TestMove) { - TObject obj; - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - { - TObject obj1 = std::move(obj); - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - } -} + TObject obj; + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + { + TObject obj1 = std::move(obj); + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + } +} diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 6eaf24cc5f..89edb7f2b7 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -31,7 +31,7 @@ SRCS( generic/mapfindptr_ut.cpp generic/maybe_ut.cpp generic/mem_copy_ut.cpp - generic/objects_counter_ut.cpp + generic/objects_counter_ut.cpp generic/overloaded_ut.cpp generic/ptr_ut.cpp generic/queue_ut.cpp diff --git a/util/system/cpu_id.cpp b/util/system/cpu_id.cpp index 598c71f4d9..b88b2c12c8 100644 --- a/util/system/cpu_id.cpp +++ b/util/system/cpu_id.cpp @@ -9,8 +9,8 @@ #include <immintrin.h> #elif defined(_x86_) #include <cpuid.h> -#endif - +#endif + #include <string.h> #if defined(_x86_) && !defined(_win_) diff --git a/util/system/env.cpp b/util/system/env.cpp index ead9b566a5..33b9288e2d 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -3,13 +3,13 @@ #include <util/generic/string.h> #include <util/generic/yexception.h> -#ifdef _win_ +#ifdef _win_ #include <util/generic/vector.h> #include "winint.h" #else #include <cerrno> #include <cstdlib> -#endif +#endif /** * On Windows there may be many copies of enviroment variables, there at least two known, one is diff --git a/util/system/error.cpp b/util/system/error.cpp index f778ec42cb..f02b3e800f 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -26,19 +26,19 @@ void ClearLastSystemError() { int LastSystemError() { #if defined(_win_) - int ret = GetLastError(); + int ret = GetLastError(); - if (ret) + if (ret) return ret; - ret = WSAGetLastError(); - - if (ret) - return ret; - // when descriptors number are over maximum, errno set in this variable - ret = *(_errno()); - return ret; - + ret = WSAGetLastError(); + + if (ret) + return ret; + // when descriptors number are over maximum, errno set in this variable + ret = *(_errno()); + return ret; + #else return errno; #endif diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..42adcb8b2f 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -1272,7 +1272,7 @@ TFile Duplicate(int fd) { FHANDLE dupHandle; if (!::DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &dupHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) { - ythrow TFileError() << "can not duplicate file descriptor " << LastSystemError() << Endl; + ythrow TFileError() << "can not duplicate file descriptor " << LastSystemError() << Endl; } return TFile(dupHandle); diff --git a/util/system/fs.cpp b/util/system/fs.cpp index d2611a8ccc..33b23d09de 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -95,9 +95,9 @@ bool NFs::Rename(const TString& oldPath, const TString& newPath) { void NFs::HardLinkOrCopy(const TString& existingPath, const TString& newPath) { if (!NFs::HardLink(existingPath, newPath)) { Copy(existingPath, newPath); - } -} - + } +} + bool NFs::HardLink(const TString& existingPath, const TString& newPath) { #if defined(_win_) return NFsPrivate::WinHardLink(existingPath, newPath); diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index de071ebf55..b6e12857e4 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -15,7 +15,7 @@ class TFsTest: public TTestBase { UNIT_TEST(TestCreateRemove); UNIT_TEST(TestRename); UNIT_TEST(TestSymlink); - UNIT_TEST(TestHardlink); + UNIT_TEST(TestHardlink); UNIT_TEST(TestCwdOpts); UNIT_TEST(TestEnsureExists); UNIT_TEST_SUITE_END(); @@ -24,7 +24,7 @@ public: void TestCreateRemove(); void TestRename(); void TestSymlink(); - void TestHardlink(); + void TestHardlink(); void TestCwdOpts(); void TestEnsureExists(); }; @@ -97,10 +97,10 @@ void TFsTest::TestCreateRemove() { } void RunRenameTest(TFsPath src, TFsPath dst) { - // if previous running was failed + // if previous running was failed TFsPath dir1 = "dir"; TFsPath dir2 = "dst_dir"; - + NFs::Remove(src); NFs::Remove(dst); @@ -109,22 +109,22 @@ void RunRenameTest(TFsPath src, TFsPath dst) { NFs::Remove(dir2 / src); NFs::Remove(dir2); - { + { TFile file(src, CreateNew | WrOnly); - file.Write("123", 3); - } - + file.Write("123", 3); + } + UNIT_ASSERT(NFs::Rename(src, dst)); UNIT_ASSERT(NFs::Exists(dst)); UNIT_ASSERT(!NFs::Exists(src)); - { + { TFile file(dst, OpenExisting); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); - } + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); + } NFs::MakeDirectory(dir1); - { + { TFile file(dir1 / src, CreateNew | WrOnly); file.Write("123", 3); } @@ -166,26 +166,26 @@ static void RunHardlinkTest(const TFsPath& src, const TFsPath& dst) { } { TFile file(src, OpenExisting | WrOnly); - file.Write("1234", 4); - } - { + file.Write("1234", 4); + } + { TFile file(dst, OpenExisting | RdOnly); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 4); - } - { + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 4); + } + { TFile file(dst, OpenExisting | WrOnly); - file.Write("12345", 5); - } + file.Write("12345", 5); + } - { + { TFile file(src, OpenExisting | RdOnly); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); - } + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); + } UNIT_ASSERT(NFs::Remove(dst)); UNIT_ASSERT(NFs::Remove(src)); -} - +} + void TFsTest::TestHardlink() { RunHardlinkTest("tempfile", "hardlinkfile"); RunHardlinkTest("tempfile_абвг", "hardlinkfile_абвг"); //utf-8 names diff --git a/util/system/rwlock.h b/util/system/rwlock.h index 0bb9b3fe1c..e9d4062992 100644 --- a/util/system/rwlock.h +++ b/util/system/rwlock.h @@ -55,24 +55,24 @@ struct TWriteGuardOps { }; template <class T> -struct TTryWriteGuardOps: public TWriteGuardOps<T> { +struct TTryWriteGuardOps: public TWriteGuardOps<T> { static inline bool TryAcquire(T* t) noexcept { - return t->TryAcquireWrite(); - } -}; - -template <class T> + return t->TryAcquireWrite(); + } +}; + +template <class T> using TReadGuardBase = TGuard<T, TReadGuardOps<T>>; template <class T> using TTryReadGuardBase = TTryGuard<T, TTryReadGuardOps<T>>; template <class T> using TWriteGuardBase = TGuard<T, TWriteGuardOps<T>>; -template <class T> -using TTryWriteGuardBase = TTryGuard<T, TTryWriteGuardOps<T>>; +template <class T> +using TTryWriteGuardBase = TTryGuard<T, TTryWriteGuardOps<T>>; using TReadGuard = TReadGuardBase<TRWMutex>; using TTryReadGuard = TTryReadGuardBase<TRWMutex>; using TWriteGuard = TWriteGuardBase<TRWMutex>; -using TTryWriteGuard = TTryWriteGuardBase<TRWMutex>; +using TTryWriteGuard = TTryWriteGuardBase<TRWMutex>; |