diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:25 +0300 |
commit | 344ea37b4a345701ab0e67de2266a1c1bd7baf2d (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system | |
parent | 706b83ed7de5a473436620367af31fc0ceecde07 (diff) | |
download | ydb-344ea37b4a345701ab0e67de2266a1c1bd7baf2d.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 2 of 2.
Diffstat (limited to 'util/system')
86 files changed, 927 insertions, 927 deletions
diff --git a/util/system/align.h b/util/system/align.h index 0261b6848e..ea0bbc5b46 100644 --- a/util/system/align.h +++ b/util/system/align.h @@ -5,45 +5,45 @@ #include <util/generic/bitops.h> template <class T> -static inline T AlignDown(T len, T align) noexcept { +static inline T AlignDown(T len, T align) noexcept { Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 return len & ~(align - 1); } template <class T> -static inline T AlignUp(T len, T align) noexcept { +static inline T AlignUp(T len, T align) noexcept { const T alignedResult = AlignDown(len + (align - 1), align); Y_ASSERT(alignedResult >= len); // check for overflow return alignedResult; } template <class T> -static inline T AlignUpSpace(T len, T align) noexcept { +static inline T AlignUpSpace(T len, T align) noexcept { Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 return ((T)0 - len) & (align - 1); // AlignUp(len, align) - len; } template <class T> -static inline T* AlignUp(T* ptr, size_t align) noexcept { +static inline T* AlignUp(T* ptr, size_t align) noexcept { return (T*)AlignUp((uintptr_t)ptr, align); } template <class T> -static inline T* AlignDown(T* ptr, size_t align) noexcept { +static inline T* AlignDown(T* ptr, size_t align) noexcept { return (T*)AlignDown((uintptr_t)ptr, align); } template <class T> -static inline T AlignUp(T t) noexcept { +static inline T AlignUp(T t) noexcept { return AlignUp(t, (size_t)PLATFORM_DATA_ALIGN); } template <class T> -static inline T AlignDown(T t) noexcept { +static inline T AlignDown(T t) noexcept { return AlignDown(t, (size_t)PLATFORM_DATA_ALIGN); } template <class T> -static inline T Align(T t) noexcept { +static inline T Align(T t) noexcept { return AlignUp(t); } diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp index 4ae0d9c3e7..74fb10b6b1 100644 --- a/util/system/atexit.cpp +++ b/util/system/atexit.cpp @@ -34,7 +34,7 @@ namespace { { } - inline void Finish() noexcept { + inline void Finish() noexcept { AtomicSet(FinishStarted_, 1); auto guard = Guard(Lock_); @@ -72,8 +72,8 @@ namespace { private: TAdaptiveLock Lock_; TAtomic FinishStarted_; - TDeque<TFunc> Store_; - TPriorityQueue<TFunc*, TVector<TFunc*>, TCmp> Items_; + TDeque<TFunc> Store_; + TPriorityQueue<TFunc*, TVector<TFunc*>, TCmp> Items_; }; static TAtomic atExitLock = 0; diff --git a/util/system/atomic_ut.cpp b/util/system/atomic_ut.cpp index 0265f57c60..07211ffba7 100644 --- a/util/system/atomic_ut.cpp +++ b/util/system/atomic_ut.cpp @@ -213,11 +213,11 @@ using TAltAtomic = volatile TChooser<TAtomicBase, long, long long>::TdType; class TTTest: public TAtomicTest<TAltAtomic> { public: - TString Name() const noexcept override { + TString Name() const noexcept override { return "TAtomicTest<TAltAtomic>"; } - static TString StaticName() noexcept { + static TString StaticName() noexcept { return "TAtomicTest<TAltAtomic>"; } }; diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp index 3e6e05a61f..b77fe58fb1 100644 --- a/util/system/backtrace.cpp +++ b/util/system/backtrace.cpp @@ -6,7 +6,7 @@ #include <util/stream/output.h> #include <util/stream/format.h> #include <util/generic/array_ref.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #ifdef _win_ #include "mutex.h" @@ -278,7 +278,7 @@ void TBackTrace::PrintTo(IOutputStream& out) const { FormatBackTraceFn(&out, Data, Size); } -TString TBackTrace::PrintToString() const { +TString TBackTrace::PrintToString() const { TStringStream ss; PrintTo(ss); return ss.Str(); diff --git a/util/system/backtrace.h b/util/system/backtrace.h index 0f91f96951..2fce7585c3 100644 --- a/util/system/backtrace.h +++ b/util/system/backtrace.h @@ -35,7 +35,7 @@ public: TBackTrace(); void Capture(); void PrintTo(IOutputStream&) const; - TString PrintToString() const; + TString PrintToString() const; size_t size() const; const void* const* data() const; operator TBackTraceView() const; diff --git a/util/system/backtrace_ut.cpp b/util/system/backtrace_ut.cpp index 766e6bbfa2..9b5ead71bc 100644 --- a/util/system/backtrace_ut.cpp +++ b/util/system/backtrace_ut.cpp @@ -31,7 +31,7 @@ void SomeMethod() { return; #endif - UNIT_ASSERT(out.Empty() || out.Str().find("SomeMethod") != TString::npos); + UNIT_ASSERT(out.Empty() || out.Str().find("SomeMethod") != TString::npos); } class TBackTraceTest: public TTestBase { diff --git a/util/system/byteorder.h b/util/system/byteorder.h index 56dc3943a7..94b9fea515 100644 --- a/util/system/byteorder.h +++ b/util/system/byteorder.h @@ -33,7 +33,7 @@ #endif #ifndef SwapBytes16 -inline ui16 SwapBytes16(ui16 val) noexcept { +inline ui16 SwapBytes16(ui16 val) noexcept { #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n])) DoSwap(byte_n(val, 0), byte_n(val, 1)); return val; @@ -42,7 +42,7 @@ inline ui16 SwapBytes16(ui16 val) noexcept { #endif #ifndef SwapBytes32 -inline ui32 SwapBytes32(ui32 val) noexcept { +inline ui32 SwapBytes32(ui32 val) noexcept { #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n])) DoSwap(byte_n(val, 0), byte_n(val, 3)); DoSwap(byte_n(val, 1), byte_n(val, 2)); @@ -52,7 +52,7 @@ inline ui32 SwapBytes32(ui32 val) noexcept { #endif #ifndef SwapBytes64 -inline ui64 SwapBytes64(ui64 val) noexcept { +inline ui64 SwapBytes64(ui64 val) noexcept { union { ui64 val; ui32 p[2]; @@ -66,8 +66,8 @@ inline ui64 SwapBytes64(ui64 val) noexcept { } #endif -//for convenience -static inline ui8 SwapBytes8(ui8 v) noexcept { +//for convenience +static inline ui8 SwapBytes8(ui8 v) noexcept { return v; } @@ -94,22 +94,22 @@ namespace NSwapBytes { } template <class T> -inline T SwapBytes(T val) noexcept { +inline T SwapBytes(T val) noexcept { return NSwapBytes::TSwapBytesHelper<sizeof(T) * 8>::Swap(val); } template <class T> -inline T LittleToBig(T val) noexcept { +inline T LittleToBig(T val) noexcept { return SwapBytes(val); } template <class T> -inline T BigToLittle(T val) noexcept { +inline T BigToLittle(T val) noexcept { return LittleToBig(val); } template <class T> -inline T HostToInet(T val) noexcept { +inline T HostToInet(T val) noexcept { #if defined(_big_endian_) return val; #elif defined(_little_endian_) @@ -120,12 +120,12 @@ inline T HostToInet(T val) noexcept { } template <class T> -inline T InetToHost(T val) noexcept { +inline T InetToHost(T val) noexcept { return HostToInet(val); } template <class T> -inline T HostToLittle(T val) noexcept { +inline T HostToLittle(T val) noexcept { #if defined(_big_endian_) return BigToLittle(val); #elif defined(_little_endian_) @@ -136,6 +136,6 @@ inline T HostToLittle(T val) noexcept { } template <class T> -inline T LittleToHost(T val) noexcept { +inline T LittleToHost(T val) noexcept { return HostToLittle(val); } diff --git a/util/system/compiler.h b/util/system/compiler.h index 7782564207..b373edcc46 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -24,7 +24,7 @@ * int main() { * Hi(); // void Hi() * Do<int>(); // void Do() [T = int] - * Do<TString>(); // void Do() [T = TString] + * Do<TString>(); // void Do() [T = TString] * } * @endcode */ @@ -216,8 +216,8 @@ constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) { * * // we know that xs and ys are non-negative from domain knowledge, * // but we can't change the types of xs and ys because of API constrains - * int Foo(const TVector<int>& xs, const TVector<int>& ys) { - * TVector<int> avgs; + * int Foo(const TVector<int>& xs, const TVector<int>& ys) { + * TVector<int> avgs; * avgs.resize(xs.size()); * for (size_t i = 0; i < xs.size(); ++i) { * auto x = xs[i]; @@ -313,12 +313,12 @@ _YandexAbort(); #else #define Y_WEAK #endif - + #if defined(__CUDACC_VER_MAJOR__) #define Y_CUDA_AT_LEAST(x, y) (__CUDACC_VER_MAJOR__ > x || (__CUDACC_VER_MAJOR__ == x && __CUDACC_VER_MINOR__ >= y)) #else #define Y_CUDA_AT_LEAST(x, y) 0 -#endif +#endif // NVidia CUDA C++ Compiler did not know about noexcept keyword until version 9.0 #if !Y_CUDA_AT_LEAST(9, 0) @@ -336,145 +336,145 @@ _YandexAbort(); #define Y_LEAF #define Y_WRAPPER #endif - -/** - * @def Y_PRAGMA - * - * Macro for use in other macros to define compiler pragma - * See below for other usage examples - * - * @code - * #if defined(__clang__) || defined(__GNUC__) - * #define Y_PRAGMA_NO_WSHADOW \ - * Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") - * #elif defined(_MSC_VER) - * #define Y_PRAGMA_NO_WSHADOW \ - * Y_PRAGMA("warning(disable:4456 4457") - * #else - * #define Y_PRAGMA_NO_WSHADOW - * #endif - * @endcode - */ -#if defined(__clang__) || defined(__GNUC__) + +/** + * @def Y_PRAGMA + * + * Macro for use in other macros to define compiler pragma + * See below for other usage examples + * + * @code + * #if defined(__clang__) || defined(__GNUC__) + * #define Y_PRAGMA_NO_WSHADOW \ + * Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") + * #elif defined(_MSC_VER) + * #define Y_PRAGMA_NO_WSHADOW \ + * Y_PRAGMA("warning(disable:4456 4457") + * #else + * #define Y_PRAGMA_NO_WSHADOW + * #endif + * @endcode + */ +#if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA(x) _Pragma(x) #elif defined(_MSC_VER) #define Y_PRAGMA(x) __pragma(x) -#else +#else #define Y_PRAGMA(x) -#endif - -/** - * @def Y_PRAGMA_DIAGNOSTIC_PUSH - * - * Cross-compiler pragma to save diagnostic settings - * - * @see - * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html - * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx - * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas - * - * @code - * Y_PRAGMA_DIAGNOSTIC_PUSH - * @endcode - */ -#if defined(__clang__) || defined(__GNUC__) +#endif + +/** + * @def Y_PRAGMA_DIAGNOSTIC_PUSH + * + * Cross-compiler pragma to save diagnostic settings + * + * @see + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html + * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx + * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas + * + * @code + * Y_PRAGMA_DIAGNOSTIC_PUSH + * @endcode + */ +#if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_DIAGNOSTIC_PUSH \ Y_PRAGMA("GCC diagnostic push") -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #define Y_PRAGMA_DIAGNOSTIC_PUSH \ Y_PRAGMA(warning(push)) -#else +#else #define Y_PRAGMA_DIAGNOSTIC_PUSH -#endif - -/** - * @def Y_PRAGMA_DIAGNOSTIC_POP - * - * Cross-compiler pragma to restore diagnostic settings - * - * @see - * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html - * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx - * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas - * - * @code - * Y_PRAGMA_DIAGNOSTIC_POP - * @endcode - */ -#if defined(__clang__) || defined(__GNUC__) +#endif + +/** + * @def Y_PRAGMA_DIAGNOSTIC_POP + * + * Cross-compiler pragma to restore diagnostic settings + * + * @see + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html + * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx + * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas + * + * @code + * Y_PRAGMA_DIAGNOSTIC_POP + * @endcode + */ +#if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_DIAGNOSTIC_POP \ Y_PRAGMA("GCC diagnostic pop") -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #define Y_PRAGMA_DIAGNOSTIC_POP \ Y_PRAGMA(warning(pop)) -#else +#else #define Y_PRAGMA_DIAGNOSTIC_POP -#endif - -/** - * @def Y_PRAGMA_NO_WSHADOW - * - * Cross-compiler pragma to disable warnings about shadowing variables - * - * @code - * Y_PRAGMA_DIAGNOSTIC_PUSH - * Y_PRAGMA_NO_WSHADOW - * - * // some code which use variable shadowing, e.g.: - * - * for (int i = 0; i < 100; ++i) { - * Use(i); - * - * for (int i = 42; i < 100500; ++i) { // this i is shadowing previous i - * AnotherUse(i); - * } - * } - * - * Y_PRAGMA_DIAGNOSTIC_POP - * @endcode - */ -#if defined(__clang__) || defined(__GNUC__) +#endif + +/** + * @def Y_PRAGMA_NO_WSHADOW + * + * Cross-compiler pragma to disable warnings about shadowing variables + * + * @code + * Y_PRAGMA_DIAGNOSTIC_PUSH + * Y_PRAGMA_NO_WSHADOW + * + * // some code which use variable shadowing, e.g.: + * + * for (int i = 0; i < 100; ++i) { + * Use(i); + * + * for (int i = 42; i < 100500; ++i) { // this i is shadowing previous i + * AnotherUse(i); + * } + * } + * + * Y_PRAGMA_DIAGNOSTIC_POP + * @endcode + */ +#if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_WSHADOW \ Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #define Y_PRAGMA_NO_WSHADOW \ Y_PRAGMA(warning(disable : 4456 4457)) -#else +#else #define Y_PRAGMA_NO_WSHADOW -#endif - -/** - * @ def Y_PRAGMA_NO_UNUSED_FUNCTION - * - * Cross-compiler pragma to disable warnings about unused functions - * - * @see - * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html - * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function - * MSVC: there is no such warning - * - * @code - * Y_PRAGMA_DIAGNOSTIC_PUSH - * Y_PRAGMA_NO_UNUSED_FUNCTION - * - * // some code which introduces a function which later will not be used, e.g.: - * - * void Foo() { - * } - * - * int main() { - * return 0; // Foo() never called - * } - * - * Y_PRAGMA_DIAGNOSTIC_POP - * @endcode - */ -#if defined(__clang__) || defined(__GNUC__) +#endif + +/** + * @ def Y_PRAGMA_NO_UNUSED_FUNCTION + * + * Cross-compiler pragma to disable warnings about unused functions + * + * @see + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function + * MSVC: there is no such warning + * + * @code + * Y_PRAGMA_DIAGNOSTIC_PUSH + * Y_PRAGMA_NO_UNUSED_FUNCTION + * + * // some code which introduces a function which later will not be used, e.g.: + * + * void Foo() { + * } + * + * int main() { + * return 0; // Foo() never called + * } + * + * Y_PRAGMA_DIAGNOSTIC_POP + * @endcode + */ +#if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_UNUSED_FUNCTION \ Y_PRAGMA("GCC diagnostic ignored \"-Wunused-function\"") -#else +#else #define Y_PRAGMA_NO_UNUSED_FUNCTION -#endif +#endif /** * @ def Y_PRAGMA_NO_UNUSED_PARAMETER @@ -514,42 +514,42 @@ _YandexAbort(); #define Y_PRAGMA_NO_UNUSED_PARAMETER #endif -/** - * @def Y_PRAGMA_NO_DEPRECATED - * - * Cross compiler pragma to disable warnings and errors about deprecated - * - * @see - * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html - * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wdeprecated - * MSVC: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2017 - * - * @code - * Y_PRAGMA_DIAGNOSTIC_PUSH - * Y_PRAGMA_NO_DEPRECATED - * - * [deprecated] void foo() { - * // ... - * } - * - * int main() { - * foo(); - * return 0; - * } - * - * Y_PRAGMA_DIAGNOSTIC_POP - * @endcode - */ +/** + * @def Y_PRAGMA_NO_DEPRECATED + * + * Cross compiler pragma to disable warnings and errors about deprecated + * + * @see + * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wdeprecated + * MSVC: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2017 + * + * @code + * Y_PRAGMA_DIAGNOSTIC_PUSH + * Y_PRAGMA_NO_DEPRECATED + * + * [deprecated] void foo() { + * // ... + * } + * + * int main() { + * foo(); + * return 0; + * } + * + * Y_PRAGMA_DIAGNOSTIC_POP + * @endcode + */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_DEPRECATED \ Y_PRAGMA("GCC diagnostic ignored \"-Wdeprecated\"") -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #define Y_PRAGMA_NO_DEPRECATED \ Y_PRAGMA(warning(disable : 4996)) -#else +#else #define Y_PRAGMA_NO_DEPRECATED -#endif - +#endif + // Memory sanitizer sometimes doesn't correctly set parameter shadow of constant functions. #if (defined(__clang__) || defined(__GNUC__)) && !defined(_msan_enabled_) /** @@ -584,23 +584,23 @@ _YandexAbort(); #if !defined(Y_PURE_FUNCTION) #define Y_PURE_FUNCTION #endif - -/** - * @ def Y_HAVE_INT128 - * - * Defined when the compiler supports __int128 extension - * - * @code - * - * #if defined(Y_HAVE_INT128) - * __int128 myVeryBigInt = 12345678901234567890; - * #endif - * - * @endcode - */ -#if defined(__SIZEOF_INT128__) + +/** + * @ def Y_HAVE_INT128 + * + * Defined when the compiler supports __int128 extension + * + * @code + * + * #if defined(Y_HAVE_INT128) + * __int128 myVeryBigInt = 12345678901234567890; + * #endif + * + * @endcode + */ +#if defined(__SIZEOF_INT128__) #define Y_HAVE_INT128 1 -#endif +#endif /** * XRAY macro must be passed to compiler if XRay is enabled. diff --git a/util/system/compiler_ut.cpp b/util/system/compiler_ut.cpp index 5b500e9529..f93b1c0850 100644 --- a/util/system/compiler_ut.cpp +++ b/util/system/compiler_ut.cpp @@ -1,24 +1,24 @@ -#include "compiler.h" - +#include "compiler.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TCompilerTest) { Y_UNIT_TEST(TestPragmaNoWshadow) { - Y_PRAGMA_DIAGNOSTIC_PUSH - Y_PRAGMA_NO_WSHADOW - - // define two variables with similar names, latest must shadow first - // and there will be no warning for this - - for (int i = 0; i < 1; ++i) { - for (int i = 100500; i < 100501; ++i) { - UNIT_ASSERT_EQUAL(i, 100500); - } - } - - Y_PRAGMA_DIAGNOSTIC_POP - } - + Y_PRAGMA_DIAGNOSTIC_PUSH + Y_PRAGMA_NO_WSHADOW + + // define two variables with similar names, latest must shadow first + // and there will be no warning for this + + for (int i = 0; i < 1; ++i) { + for (int i = 100500; i < 100501; ++i) { + UNIT_ASSERT_EQUAL(i, 100500); + } + } + + Y_PRAGMA_DIAGNOSTIC_POP + } + Y_PRAGMA_DIAGNOSTIC_PUSH Y_PRAGMA_NO_UNUSED_PARAMETER @@ -35,38 +35,38 @@ Y_UNIT_TEST_SUITE(TCompilerTest) { } Y_UNIT_TEST(TestHaveInt128) { -#ifdef Y_HAVE_INT128 - // will be compiled without errors - unsigned __int128 a = 1; - __int128 b = 1; - UNIT_ASSERT_EQUAL(a, 1); - UNIT_ASSERT_EQUAL(b, 1); - UNIT_ASSERT_EQUAL(sizeof(a), sizeof(b)); - - // and we can set a type alias for __int128 and unsigned __int128 without compiler errors - using TMyInt128 = __int128; - using TMyUnsignedInt128 = unsigned __int128; - - TMyInt128 i128value; - TMyUnsignedInt128 ui128value; - Y_UNUSED(i128value); - Y_UNUSED(ui128value); - -#endif - } - - // define deprecated function +#ifdef Y_HAVE_INT128 + // will be compiled without errors + unsigned __int128 a = 1; + __int128 b = 1; + UNIT_ASSERT_EQUAL(a, 1); + UNIT_ASSERT_EQUAL(b, 1); + UNIT_ASSERT_EQUAL(sizeof(a), sizeof(b)); + + // and we can set a type alias for __int128 and unsigned __int128 without compiler errors + using TMyInt128 = __int128; + using TMyUnsignedInt128 = unsigned __int128; + + TMyInt128 i128value; + TMyUnsignedInt128 ui128value; + Y_UNUSED(i128value); + Y_UNUSED(ui128value); + +#endif + } + + // define deprecated function [[deprecated]] void Bar() { - return; - } - - Y_UNIT_TEST(TestNoDeprecated) { - Y_PRAGMA_DIAGNOSTIC_PUSH - Y_PRAGMA_NO_DEPRECATED - - // will be compiled without errors + return; + } + + Y_UNIT_TEST(TestNoDeprecated) { + Y_PRAGMA_DIAGNOSTIC_PUSH + Y_PRAGMA_NO_DEPRECATED + + // will be compiled without errors Bar(); - - Y_PRAGMA_DIAGNOSTIC_POP - } -} + + Y_PRAGMA_DIAGNOSTIC_POP + } +} diff --git a/util/system/condvar.cpp b/util/system/condvar.cpp index 707db52c0b..62f3d22356 100644 --- a/util/system/condvar.cpp +++ b/util/system/condvar.cpp @@ -27,11 +27,11 @@ namespace { using TWaitEvents = TIntrusiveList<TWaitEvent>; public: - inline ~TCondVarImpl() { + inline ~TCondVarImpl() { Y_ASSERT(Events_.Empty()); } - inline void Signal() noexcept { + inline void Signal() noexcept { with_lock (Lock_) { if (!Events_.Empty()) { Events_.PopFront()->Signal(); @@ -39,7 +39,7 @@ namespace { } } - inline void BroadCast() noexcept { + inline void BroadCast() noexcept { with_lock (Lock_) { //TODO while (!Events_.Empty()) { @@ -48,7 +48,7 @@ namespace { } } - inline bool WaitD(TMutex& m, TInstant deadLine) noexcept { + inline bool WaitD(TMutex& m, TInstant deadLine) noexcept { TWaitEvent event; with_lock (Lock_) { @@ -86,17 +86,17 @@ public: } } - inline ~TImpl() { + inline ~TImpl() { int ret = pthread_cond_destroy(&Cond_); Y_VERIFY(ret == 0, "pthread_cond_destroy failed: %s", LastSystemErrorText(ret)); } - inline void Signal() noexcept { + inline void Signal() noexcept { int ret = pthread_cond_signal(&Cond_); Y_VERIFY(ret == 0, "pthread_cond_signal failed: %s", LastSystemErrorText(ret)); } - inline bool WaitD(TMutex& lock, TInstant deadLine) noexcept { + inline bool WaitD(TMutex& lock, TInstant deadLine) noexcept { if (deadLine == TInstant::Max()) { int ret = pthread_cond_wait(&Cond_, (pthread_mutex_t*)lock.Handle()); Y_VERIFY(ret == 0, "pthread_cond_wait failed: %s", LastSystemErrorText(ret)); @@ -117,7 +117,7 @@ public: } } - inline void BroadCast() noexcept { + inline void BroadCast() noexcept { int ret = pthread_cond_broadcast(&Cond_); Y_VERIFY(ret == 0, "pthread_cond_broadcast failed: %s", LastSystemErrorText(ret)); } @@ -134,14 +134,14 @@ TCondVar::TCondVar() TCondVar::~TCondVar() = default; -void TCondVar::BroadCast() noexcept { +void TCondVar::BroadCast() noexcept { Impl_->BroadCast(); } -void TCondVar::Signal() noexcept { +void TCondVar::Signal() noexcept { Impl_->Signal(); } -bool TCondVar::WaitD(TMutex& mutex, TInstant deadLine) noexcept { +bool TCondVar::WaitD(TMutex& mutex, TInstant deadLine) noexcept { return Impl_->WaitD(mutex, deadLine); } diff --git a/util/system/condvar.h b/util/system/condvar.h index b18e48432b..569162717c 100644 --- a/util/system/condvar.h +++ b/util/system/condvar.h @@ -11,10 +11,10 @@ class TCondVar { public: TCondVar(); - ~TCondVar(); + ~TCondVar(); - void BroadCast() noexcept; - void Signal() noexcept; + void BroadCast() noexcept; + void Signal() noexcept; /* * returns false if failed by timeout @@ -46,7 +46,7 @@ public: /* * infinite wait */ - inline void WaitI(TMutex& m) noexcept { + inline void WaitI(TMutex& m) noexcept { WaitD(m, TInstant::Max()); } @@ -56,7 +56,7 @@ public: } //deprecated - inline void Wait(TMutex& m) noexcept { + inline void Wait(TMutex& m) noexcept { WaitI(m); } diff --git a/util/system/context.cpp b/util/system/context.cpp index 18684e4054..ad99309088 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -52,7 +52,7 @@ extern "C" void __mylongjmp(__myjmp_buf env, int val) __attribute__((__noreturn_ extern "C" int __mysetjmp(__myjmp_buf env) __attribute__((__returns_twice__)); namespace { - class TStackType { + class TStackType { public: inline TStackType(TArrayRef<char> range) noexcept #if defined(STACK_GROW_DOWN) @@ -64,14 +64,14 @@ namespace { ReAlign(); } - inline ~TStackType() = default; + inline ~TStackType() = default; - inline void ReAlign() noexcept { + inline void ReAlign() noexcept { Data_ = AlignStackPtr(Data_); } template <class T> - inline void Push(T t) noexcept { + inline void Push(T t) noexcept { #if defined(STACK_GROW_DOWN) Data_ -= sizeof(T); *((T*)Data_) = t; @@ -81,12 +81,12 @@ namespace { #endif } - inline char* StackPtr() noexcept { + inline char* StackPtr() noexcept { return Data_; } private: - static inline char* AlignStackPtr(char* ptr) noexcept { + static inline char* AlignStackPtr(char* ptr) noexcept { #if defined(STACK_GROW_DOWN) return AlignDown(ptr, STACK_ALIGN); #else @@ -98,15 +98,15 @@ namespace { char* Data_; }; - static inline void*& JmpBufReg(__myjmp_buf& buf, size_t n) noexcept { + static inline void*& JmpBufReg(__myjmp_buf& buf, size_t n) noexcept { return (((void**)(void*)(buf))[n]); } - static inline void*& JmpBufStackReg(__myjmp_buf& buf) noexcept { + static inline void*& JmpBufStackReg(__myjmp_buf& buf) noexcept { return JmpBufReg(buf, STACK_CNT); } - static inline void*& JmpBufProgrReg(__myjmp_buf& buf) noexcept { + static inline void*& JmpBufProgrReg(__myjmp_buf& buf) noexcept { return JmpBufReg(buf, PROGR_CNT); } @@ -156,7 +156,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) : San_(c) #endif { - TStackType stack(c.Stack); + TStackType stack(c.Stack); /* * arg, and align data @@ -194,7 +194,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) JmpBufFrameReg(Buf_) = nullptr; } -void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { +void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { if (Y_LIKELY(__mysetjmp(Buf_) == 0)) { #if defined(_asan_enabled_) || defined(_tsan_enabled_) next->San_.BeforeSwitch(&San_); @@ -231,7 +231,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) Y_ENSURE(Fiber_, TStringBuf("fiber error")); } -TContMachineContext::~TContMachineContext() { +TContMachineContext::~TContMachineContext() { if (MainFiber_) { ConvertFiberToThread(); } else { @@ -239,7 +239,7 @@ TContMachineContext::~TContMachineContext() { } } -void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { +void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { SwitchToFiber(next->Fiber_); } #endif @@ -262,7 +262,7 @@ struct TContMachineContext::TImpl { Thread->Start(); } - inline ~TImpl() { + inline ~TImpl() { if (Thread) { Finish = true; Signal(); @@ -270,7 +270,7 @@ struct TContMachineContext::TImpl { } } - inline void SwitchTo(TImpl* next) noexcept { + inline void SwitchTo(TImpl* next) noexcept { next->Signal(); Wait(); } @@ -286,11 +286,11 @@ struct TContMachineContext::TImpl { TL->DoRun(); } - inline void Signal() noexcept { + inline void Signal() noexcept { Event.Signal(); } - inline void Wait() noexcept { + inline void Wait() noexcept { Event.Wait(); if (Finish) { @@ -315,10 +315,10 @@ TContMachineContext::TContMachineContext(const TContClosure& c) { } -TContMachineContext::~TContMachineContext() { +TContMachineContext::~TContMachineContext() { } -void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { +void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { Impl_->SwitchTo(next->Impl_.Get()); } #endif diff --git a/util/system/context.h b/util/system/context.h index 9f16663f66..d2a349bfc5 100644 --- a/util/system/context.h +++ b/util/system/context.h @@ -78,10 +78,10 @@ public: makecontext(&Ctx_, (ucontext_func_t)ContextTrampoLine, 1, c.TrampoLine); } - inline ~TContMachineContext() { + inline ~TContMachineContext() { } - inline void SwitchTo(TContMachineContext* next) noexcept { + inline void SwitchTo(TContMachineContext* next) noexcept { swapcontext(&Ctx_, &next->Ctx_); } @@ -98,9 +98,9 @@ public: TContMachineContext(); TContMachineContext(const TContClosure& c); - ~TContMachineContext(); + ~TContMachineContext(); - void SwitchTo(TContMachineContext* next) noexcept; + void SwitchTo(TContMachineContext* next) noexcept; private: THolder<TImpl> Impl_; @@ -112,9 +112,9 @@ class TContMachineContext { public: TContMachineContext(); TContMachineContext(const TContClosure& c); - ~TContMachineContext(); + ~TContMachineContext(); - void SwitchTo(TContMachineContext* next) noexcept; + void SwitchTo(TContMachineContext* next) noexcept; private: void* Fiber_; @@ -133,7 +133,7 @@ public: inline ~TContMachineContext() = default; - void SwitchTo(TContMachineContext* next) noexcept; + void SwitchTo(TContMachineContext* next) noexcept; private: __myjmp_buf Buf_; @@ -153,7 +153,7 @@ private: }; #endif -static inline size_t MachineContextSize() noexcept { +static inline size_t MachineContextSize() noexcept { return sizeof(TContMachineContext); } diff --git a/util/system/context_ut.cpp b/util/system/context_ut.cpp index 1c75718134..45cb0249f7 100644 --- a/util/system/context_ut.cpp +++ b/util/system/context_ut.cpp @@ -22,7 +22,7 @@ Y_UNIT_TEST_SUITE(TestContext) { char Buf[1000000]; }; - static TDeque<TW> w; + static TDeque<TW> w; auto& tw = w.emplace_back(&f); diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp index 532780e835..f59c54b0cb 100644 --- a/util/system/direct_io.cpp +++ b/util/system/direct_io.cpp @@ -46,7 +46,7 @@ namespace { }; } -TDirectIOBufferedFile::TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen /*= 1 << 17*/) +TDirectIOBufferedFile::TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen /*= 1 << 17*/) : File(path, oMode) , Alignment(0) , DataLen(0) diff --git a/util/system/direct_io.h b/util/system/direct_io.h index 4a9e80f3c7..6a3325a960 100644 --- a/util/system/direct_io.h +++ b/util/system/direct_io.h @@ -11,7 +11,7 @@ // - Supports writing odd sized files by turning off direct IO for the last chunk. class TDirectIOBufferedFile { public: - TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17); + TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17); ~TDirectIOBufferedFile(); void FlushData(); diff --git a/util/system/direct_io_ut.cpp b/util/system/direct_io_ut.cpp index 8293cc3573..839c3de7ca 100644 --- a/util/system/direct_io_ut.cpp +++ b/util/system/direct_io_ut.cpp @@ -12,7 +12,7 @@ static const char* FileName_("./test.file"); Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { Y_UNIT_TEST(TestDirectFile) { TDirectIOBufferedFile file(FileName_, RdWr | Direct | Seq | CreateAlways, 1 << 15); - TVector<ui64> data((1 << 15) + 1); + TVector<ui64> data((1 << 15) + 1); TVector<ui64> readResult(data.size()); for (auto& i : data) { i = RandomNumber<ui64>(); diff --git a/util/system/dynlib.cpp b/util/system/dynlib.cpp index 7a3a2d4a29..9d2541c25f 100644 --- a/util/system/dynlib.cpp +++ b/util/system/dynlib.cpp @@ -25,7 +25,7 @@ using HINSTANCE = void*; #define DLLSYM(hndl, name) dlsym(hndl, name) #endif -inline TString DLLERR() { +inline TString DLLERR() { #ifdef _unix_ return dlerror(); #endif @@ -38,7 +38,7 @@ inline TString DLLERR() { return "DLLERR() unknown error"; while (cnt && isspace(msg[cnt - 1])) --cnt; - TString err(msg, 0, cnt); + TString err(msg, 0, cnt); LocalFree(msg); return err; #endif @@ -67,13 +67,13 @@ public: return new TImpl(path, flags); } - inline ~TImpl() { + inline ~TImpl() { if (Module && Unloadable) { DLLCLOSE(Module); } } - inline void* SymOptional(const char* name) noexcept { + inline void* SymOptional(const char* name) noexcept { return (void*)DLLSYM(Module, name); } @@ -96,10 +96,10 @@ private: bool Unloadable; }; -TDynamicLibrary::TDynamicLibrary() noexcept { +TDynamicLibrary::TDynamicLibrary() noexcept { } -TDynamicLibrary::TDynamicLibrary(const TString& path, int flags) { +TDynamicLibrary::TDynamicLibrary(const TString& path, int flags) { Open(path.data(), flags); } @@ -109,11 +109,11 @@ void TDynamicLibrary::Open(const char* path, int flags) { Impl_.Reset(TImpl::SafeCreate(path, flags)); } -void TDynamicLibrary::Close() noexcept { +void TDynamicLibrary::Close() noexcept { Impl_.Destroy(); } -void* TDynamicLibrary::SymOptional(const char* name) noexcept { +void* TDynamicLibrary::SymOptional(const char* name) noexcept { if (!IsLoaded()) { return nullptr; } @@ -129,7 +129,7 @@ void* TDynamicLibrary::Sym(const char* name) { return Impl_->Sym(name); } -bool TDynamicLibrary::IsLoaded() const noexcept { +bool TDynamicLibrary::IsLoaded() const noexcept { return (bool)Impl_.Get(); } diff --git a/util/system/dynlib.h b/util/system/dynlib.h index 6c4a1b0dd5..66eaf4a5c1 100644 --- a/util/system/dynlib.h +++ b/util/system/dynlib.h @@ -3,7 +3,7 @@ #include "defaults.h" #include <util/generic/ptr.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name)) #define Y_GET_FUNC_OPTIONAL(dll, name) FUNC_##name((dll).SymOptional(#name)) @@ -22,15 +22,15 @@ class TDynamicLibrary { public: - TDynamicLibrary() noexcept; - TDynamicLibrary(const TString& path, int flags = DEFAULT_DLLOPEN_FLAGS); - ~TDynamicLibrary(); + TDynamicLibrary() noexcept; + TDynamicLibrary(const TString& path, int flags = DEFAULT_DLLOPEN_FLAGS); + ~TDynamicLibrary(); void Open(const char* path, int flags = DEFAULT_DLLOPEN_FLAGS); - void Close() noexcept; - void* SymOptional(const char* name) noexcept; + void Close() noexcept; + void* SymOptional(const char* name) noexcept; void* Sym(const char* name); - bool IsLoaded() const noexcept; + bool IsLoaded() const noexcept; void SetUnloadable(bool unloadable); // Set to false to avoid unloading on destructor private: @@ -44,11 +44,11 @@ class TExternalSymbol { private: TLib* PLib; TDynamicLibrary* DLib; - TString lname; - TString vname; + TString lname; + TString vname; public: - TExternalSymbol() noexcept { + TExternalSymbol() noexcept { PLib = nullptr; DLib = nullptr; } @@ -70,7 +70,7 @@ public: } return *this; } - ~TExternalSymbol() { + ~TExternalSymbol() { delete DLib; } // set the symbol from dynamic source @@ -90,30 +90,30 @@ public: vname = vtbl_name; } // set the symbol from static source - void SetSym(TLib* pl) noexcept { + void SetSym(TLib* pl) noexcept { if (DLib == nullptr && PLib == nullptr) PLib = pl; } - void Close() noexcept { + void Close() noexcept { delete DLib; DLib = 0; PLib = 0; lname.remove(); vname.remove(); } - TLib* Symbol() const noexcept { + TLib* Symbol() const noexcept { return PLib; } - const TString& LibName() const noexcept { + const TString& LibName() const noexcept { return lname; } - const TString& VtblName() const noexcept { + const TString& VtblName() const noexcept { return vname; } - bool IsStatic() const noexcept { + bool IsStatic() const noexcept { return DLib == nullptr && PLib != nullptr; } - bool IsDynamic() const noexcept { + bool IsDynamic() const noexcept { return DLib && DLib->IsLoaded() && PLib != nullptr; } }; diff --git a/util/system/env.cpp b/util/system/env.cpp index 779aa6e4fb..ead9b566a5 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -1,19 +1,19 @@ #include "env.h" -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/yexception.h> #ifdef _win_ #include <util/generic/vector.h> #include "winint.h" -#else +#else #include <cerrno> #include <cstdlib> #endif /** - * On Windows there may be many copies of enviroment variables, there at least two known, one is - * manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of + * On Windows there may be many copies of enviroment variables, there at least two known, one is + * manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of * functions used to manipulate them. * * Relevant links: @@ -21,35 +21,35 @@ * - https://a.yandex-team.ru/review/108892/details */ -TString GetEnv(const TString& key, const TString& def) { +TString GetEnv(const TString& key, const TString& def) { #ifdef _win_ size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0); - - if (len == 0) { + + if (len == 0) { if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { return def; } - return TString{}; - } - - TVector<char> buffer(len); - size_t bufferSize; - do { - bufferSize = buffer.size(); + return TString{}; + } + + TVector<char> buffer(len); + size_t bufferSize; + do { + bufferSize = buffer.size(); len = GetEnvironmentVariableA(key.data(), buffer.data(), static_cast<DWORD>(bufferSize)); - if (len > bufferSize) { - buffer.resize(len); - } - } while (len > bufferSize); - - return TString(buffer.data(), len); + if (len > bufferSize) { + buffer.resize(len); + } + } while (len > bufferSize); + + return TString(buffer.data(), len); #else const char* env = getenv(key.data()); - return env ? TString(env) : def; + return env ? TString(env) : def; #endif } -void SetEnv(const TString& key, const TString& value) { +void SetEnv(const TString& key, const TString& value) { bool isOk = false; int errorCode = 0; #ifdef _win_ diff --git a/util/system/env.h b/util/system/env.h index 0b77070ab7..e2ccdd1e95 100644 --- a/util/system/env.h +++ b/util/system/env.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/string.h> +#include <util/generic/string.h> /** * Search the environment list provided by the host environment for associated variable. @@ -16,7 +16,7 @@ * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. * @see SetEnv */ -TString GetEnv(const TString& key, const TString& def = TString()); +TString GetEnv(const TString& key, const TString& def = TString()); /** * Add or change environment variable provided by the host environment. @@ -29,4 +29,4 @@ TString GetEnv(const TString& key, const TString& def = TString()); * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. * @see GetEnv */ -void SetEnv(const TString& key, const TString& value); +void SetEnv(const TString& key, const TString& value); diff --git a/util/system/env_ut.cpp b/util/system/env_ut.cpp index 3139394bc7..e03cc01658 100644 --- a/util/system/env_ut.cpp +++ b/util/system/env_ut.cpp @@ -1,31 +1,31 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include "env.h" Y_UNIT_TEST_SUITE(EnvTest) { Y_UNIT_TEST(GetSetEnvTest) { - TString key = "util_GETENV_TestVar"; - TString value = "Some value for env var"; - TString def = "Some default value for env var"; + TString key = "util_GETENV_TestVar"; + TString value = "Some value for env var"; + TString def = "Some default value for env var"; // first of all, it should be clear - UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); + UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(key, def), def); SetEnv(key, value); // set and see what value we get here UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), value); UNIT_ASSERT_VALUES_EQUAL(GetEnv(key, def), value); // set empty value - SetEnv(key, TString()); - UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); - - // check for long values, see IGNIETFERRO-214 - TString longKey = "util_GETENV_TestVarLong"; - TString longValue{1500, 't'}; - UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); - SetEnv(longKey, longValue); - UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), longValue); - SetEnv(longKey, TString()); - UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); + SetEnv(key, TString()); + UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); + + // check for long values, see IGNIETFERRO-214 + TString longKey = "util_GETENV_TestVarLong"; + TString longValue{1500, 't'}; + UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); + SetEnv(longKey, longValue); + UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), longValue); + SetEnv(longKey, TString()); + UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); } } diff --git a/util/system/error.cpp b/util/system/error.cpp index eb0806fe5d..f778ec42cb 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -47,7 +47,7 @@ int LastSystemError() { #if defined(_win_) namespace { struct TErrString { - inline TErrString() noexcept { + inline TErrString() noexcept { data[0] = 0; } diff --git a/util/system/event.cpp b/util/system/event.cpp index 6f70a37e05..79b3cdb291 100644 --- a/util/system/event.cpp +++ b/util/system/event.cpp @@ -19,19 +19,19 @@ public: cond = CreateEvent(nullptr, rmode == rManual ? true : false, false, nullptr); } - inline ~TEvImpl() { + inline ~TEvImpl() { CloseHandle(cond); } - inline void Reset() noexcept { + inline void Reset() noexcept { ResetEvent(cond); } - inline void Signal() noexcept { + inline void Signal() noexcept { SetEvent(cond); } - inline bool WaitD(TInstant deadLine) noexcept { + inline bool WaitD(TInstant deadLine) noexcept { if (deadLine == TInstant::Max()) { return WaitForSingleObject(cond, INFINITE) == WAIT_OBJECT_0; } @@ -51,7 +51,7 @@ public: { } - inline void Signal() noexcept { + inline void Signal() noexcept { if (Manual && AtomicGet(Signaled)) { return; // shortcut } @@ -67,11 +67,11 @@ public: } } - inline void Reset() noexcept { + inline void Reset() noexcept { AtomicSet(Signaled, 0); } - inline bool WaitD(TInstant deadLine) noexcept { + inline bool WaitD(TInstant deadLine) noexcept { if (Manual && AtomicGet(Signaled)) { return true; // shortcut } diff --git a/util/system/event.h b/util/system/event.h index 3e9378fbee..cab2fc478a 100644 --- a/util/system/event.h +++ b/util/system/event.h @@ -24,34 +24,34 @@ public: ~TSystemEvent(); - void Reset() noexcept; - void Signal() noexcept; + void Reset() noexcept; + void Signal() noexcept; /* * return true if signaled, false if timed out. */ - bool WaitD(TInstant deadLine) noexcept; + bool WaitD(TInstant deadLine) noexcept; /* * return true if signaled, false if timed out. */ - inline bool WaitT(TDuration timeOut) noexcept { + inline bool WaitT(TDuration timeOut) noexcept { return WaitD(timeOut.ToDeadLine()); } /* * wait infinite time */ - inline void WaitI() noexcept { + inline void WaitI() noexcept { WaitD(TInstant::Max()); } //return true if signaled, false if timed out. - inline bool Wait(ui32 timer) noexcept { + inline bool Wait(ui32 timer) noexcept { return WaitT(TDuration::MilliSeconds(timer)); } - inline bool Wait() noexcept { + inline bool Wait() noexcept { WaitI(); return true; diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp index 3877c912e7..33198af58b 100644 --- a/util/system/execpath.cpp +++ b/util/system/execpath.cpp @@ -32,8 +32,8 @@ #include "fs.h" #if defined(_freebsd_) -static inline bool GoodPath(const TString& path) { - return path.find('/') != TString::npos; +static inline bool GoodPath(const TString& path) { + return path.find('/') != TString::npos; } static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { @@ -51,12 +51,12 @@ static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { return errno; } -static inline TString FreeBSDGetExecPath() { +static inline TString FreeBSDGetExecPath() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; TTempBuf buf; int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); if (r == 0) { - return TString(buf.Data(), buf.Filled() - 1); + return TString(buf.Data(), buf.Filled() - 1); } else if (r == ENOTSUP) { // older FreeBSD version /* * BSD analogue for /proc/self is /proc/curproc. @@ -66,24 +66,24 @@ static inline TString FreeBSDGetExecPath() { TString path("/proc/curproc/file"); return NFs::ReadLink(path); } else { - return TString(); + return TString(); } } -static inline TString FreeBSDGetArgv0() { +static inline TString FreeBSDGetArgv0() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, getpid()}; TTempBuf buf; int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); if (r == 0) { - return TString(buf.Data()); + return TString(buf.Data()); } else if (r == ENOTSUP) { - return TString(); + return TString(); } else { ythrow yexception() << "FreeBSDGetArgv0() failed: " << LastSystemErrorText(); } } -static inline bool FreeBSDGuessExecPath(const TString& guessPath, TString& execPath) { +static inline bool FreeBSDGuessExecPath(const TString& guessPath, TString& execPath) { if (NFs::Exists(guessPath)) { // now it should work for real execPath = FreeBSDGetExecPath(); @@ -94,13 +94,13 @@ static inline bool FreeBSDGuessExecPath(const TString& guessPath, TString& execP return false; } -static inline bool FreeBSDGuessExecBasePath(const TString& guessBasePath, TString& execPath) { - return FreeBSDGuessExecPath(TString(guessBasePath) + "/" + getprogname(), execPath); +static inline bool FreeBSDGuessExecBasePath(const TString& guessBasePath, TString& execPath) { + return FreeBSDGuessExecPath(TString(guessBasePath) + "/" + getprogname(), execPath); } #endif -static TString GetExecPathImpl() { +static TString GetExecPathImpl() { #if defined(_solaris_) return execname(); #elif defined(_darwin_) @@ -132,7 +132,7 @@ static TString GetExecPathImpl() { return NFs::ReadLink(path); // TODO(yoda): check if the filename ends with " (deleted)" #elif defined(_freebsd_) - TString execPath = FreeBSDGetExecPath(); + TString execPath = FreeBSDGetExecPath(); if (GoodPath(execPath)) { return execPath; } @@ -185,12 +185,12 @@ namespace { return SingletonWithPriority<TExecPathsHolder, 1>(); } - TString ExecPath; + TString ExecPath; TString PersistentExecPath; }; } -const TString& GetExecPath() { +const TString& GetExecPath() { return TExecPathsHolder::Instance()->ExecPath; } diff --git a/util/system/execpath.h b/util/system/execpath.h index 451551ac79..4b914b8e85 100644 --- a/util/system/execpath.h +++ b/util/system/execpath.h @@ -3,7 +3,7 @@ #include <util/generic/fwd.h> // NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297 -const TString& GetExecPath(); +const TString& GetExecPath(); /** * Get openable path to the binary currently being executed. diff --git a/util/system/execpath_ut.cpp b/util/system/execpath_ut.cpp index df64d08e2f..16b01466f5 100644 --- a/util/system/execpath_ut.cpp +++ b/util/system/execpath_ut.cpp @@ -7,7 +7,7 @@ Y_UNIT_TEST_SUITE(TExecPathTest) { Y_UNIT_TEST(TestIt) { - TString execPath = GetExecPath(); + TString execPath = GetExecPath(); TString persistentExecPath = GetPersistentExecPath(); try { diff --git a/util/system/fasttime.cpp b/util/system/fasttime.cpp index d885592a81..057a814f0a 100644 --- a/util/system/fasttime.cpp +++ b/util/system/fasttime.cpp @@ -130,35 +130,35 @@ namespace { { } - inline void Add(const A& a, const B& b) noexcept { + inline void Add(const A& a, const B& b) noexcept { Add(TSample(a, b)); } - inline void Add(const TSample& s) noexcept { + inline void Add(const TSample& s) noexcept { S_[(C_++) % N] = s; if (C_ > 1) { ReCalc(); } } - inline B Predict(A a) const noexcept { + inline B Predict(A a) const noexcept { return A_ + a * B_; } - inline size_t Size() const noexcept { + inline size_t Size() const noexcept { return C_; } - inline bool Enough() const noexcept { + inline bool Enough() const noexcept { return Size() >= N; } - inline A LastX() const noexcept { + inline A LastX() const noexcept { return S_[(C_ - 1) % N].first; } private: - inline void ReCalc() noexcept { + inline void ReCalc() noexcept { const size_t n = Min(N, C_); double sx = 0; diff --git a/util/system/file.cpp b/util/system/file.cpp index e4af4bacde..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -17,7 +17,7 @@ #include <util/random/random.h> #include <util/generic/size_literals.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/ylimits.h> #include <util/generic/yexception.h> @@ -63,7 +63,7 @@ static bool IsStupidFlagCombination(EOpenMode oMode) { return (oMode & (CreateAlways | ForAppend)) == (CreateAlways | ForAppend) || (oMode & (TruncExisting | ForAppend)) == (TruncExisting | ForAppend) || (oMode & (CreateNew | ForAppend)) == (CreateNew | ForAppend); } -TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { +TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { ui32 fcMode = 0; EOpenMode createMode = oMode & MaskCreation; Y_VERIFY(!IsStupidFlagCombination(oMode), "oMode %d makes no sense", static_cast<int>(oMode)); @@ -267,7 +267,7 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { #endif } -bool TFileHandle::Close() noexcept { +bool TFileHandle::Close() noexcept { bool isOk = true; #ifdef _win_ if (Fd_ != INVALID_FHANDLE) { @@ -294,7 +294,7 @@ bool TFileHandle::Close() noexcept { return isOk; } -static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept { +static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept { if (h == INVALID_FHANDLE) { return -1L; } @@ -319,15 +319,15 @@ static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept { #endif } -i64 TFileHandle::GetPosition() const noexcept { +i64 TFileHandle::GetPosition() const noexcept { return DoSeek(Fd_, 0, sCur); } -i64 TFileHandle::Seek(i64 offset, SeekDir origin) noexcept { +i64 TFileHandle::Seek(i64 offset, SeekDir origin) noexcept { return DoSeek(Fd_, offset, origin); } -i64 TFileHandle::GetLength() const noexcept { +i64 TFileHandle::GetLength() const noexcept { // XXX: returns error code, but does not set errno if (!IsOpen()) { return -1L; @@ -335,7 +335,7 @@ i64 TFileHandle::GetLength() const noexcept { return GetFileLength(Fd_); } -bool TFileHandle::Resize(i64 length) noexcept { +bool TFileHandle::Resize(i64 length) noexcept { if (!IsOpen()) { return false; } @@ -363,7 +363,7 @@ bool TFileHandle::Resize(i64 length) noexcept { #endif } -bool TFileHandle::Reserve(i64 length) noexcept { +bool TFileHandle::Reserve(i64 length) noexcept { // FIXME this should reserve disk space with fallocate if (!IsOpen()) { return false; @@ -412,7 +412,7 @@ bool TFileHandle::ShrinkToFit() noexcept { #endif } -bool TFileHandle::Flush() noexcept { +bool TFileHandle::Flush() noexcept { if (!IsOpen()) { return false; } @@ -443,7 +443,7 @@ bool TFileHandle::Flush() noexcept { #endif } -bool TFileHandle::FlushData() noexcept { +bool TFileHandle::FlushData() noexcept { #if defined(_linux_) if (!IsOpen()) { return false; @@ -458,7 +458,7 @@ bool TFileHandle::FlushData() noexcept { #endif } -i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept { +i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept { // FIXME size and return must be 64-bit if (!IsOpen()) { return -1; @@ -480,7 +480,7 @@ i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept { #endif } -i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept { +i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept { if (!IsOpen()) { return -1; } @@ -501,7 +501,7 @@ i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept { #endif } -i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept { +i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept { #if defined(_win_) OVERLAPPED io; Zero(io); @@ -526,7 +526,7 @@ i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept #endif } -i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept { +i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept { #if defined(_win_) OVERLAPPED io; Zero(io); @@ -548,7 +548,7 @@ i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const no #endif } -FHANDLE TFileHandle::Duplicate() const noexcept { +FHANDLE TFileHandle::Duplicate() const noexcept { if (!IsOpen()) { return INVALID_FHANDLE; } @@ -597,7 +597,7 @@ int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept { #endif } -bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept { +bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept { #if defined(_unix_) while (dup2(fh.Fd_, Fd_) == -1) { if (errno != EINTR) { @@ -621,7 +621,7 @@ bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept { #endif } -int TFileHandle::Flock(int op) noexcept { +int TFileHandle::Flock(int op) noexcept { return ::Flock(Fd_, op); } @@ -775,7 +775,7 @@ bool TFileHandle::FlushCache(i64 offset, i64 length, bool wait) noexcept { #endif } -TString DecodeOpenMode(ui32 mode0) { +TString DecodeOpenMode(ui32 mode0) { ui32 mode = mode0; TStringBuilder r; @@ -843,13 +843,13 @@ TString DecodeOpenMode(ui32 mode0) { class TFile::TImpl: public TAtomicRefCount<TImpl> { public: - inline TImpl(FHANDLE fd, const TString& fname = TString()) + inline TImpl(FHANDLE fd, const TString& fname = TString()) : Handle_(fd) , FileName_(fname) { } - inline TImpl(const TString& fName, EOpenMode oMode) + inline TImpl(const TString& fName, EOpenMode oMode) : Handle_(fName, oMode) , FileName_(fName) { @@ -866,15 +866,15 @@ public: } } - const TString& GetName() const noexcept { + const TString& GetName() const noexcept { return FileName_; } - void SetName(const TString& newName) { + void SetName(const TString& newName) { FileName_ = newName; } - const TFileHandle& GetHandle() const noexcept { + const TFileHandle& GetHandle() const noexcept { return Handle_; } @@ -1084,7 +1084,7 @@ public: private: TFileHandle Handle_; - TString FileName_; + TString FileName_; }; TFile::TFile() @@ -1097,12 +1097,12 @@ TFile::TFile(FHANDLE fd) { } -TFile::TFile(FHANDLE fd, const TString& name) +TFile::TFile(FHANDLE fd, const TString& name) : Impl_(new TImpl(fd, name)) { } -TFile::TFile(const TString& fName, EOpenMode oMode) +TFile::TFile(const TString& fName, EOpenMode oMode) : Impl_(new TImpl(fName, oMode)) { } @@ -1113,23 +1113,23 @@ void TFile::Close() { Impl_->Close(); } -const TString& TFile::GetName() const noexcept { +const TString& TFile::GetName() const noexcept { return Impl_->GetName(); } -i64 TFile::GetPosition() const noexcept { +i64 TFile::GetPosition() const noexcept { return Impl_->GetHandle().GetPosition(); } -i64 TFile::GetLength() const noexcept { +i64 TFile::GetLength() const noexcept { return Impl_->GetHandle().GetLength(); } -bool TFile::IsOpen() const noexcept { +bool TFile::IsOpen() const noexcept { return Impl_->GetHandle().IsOpen(); } -FHANDLE TFile::GetHandle() const noexcept { +FHANDLE TFile::GetHandle() const noexcept { return Impl_->GetHandle(); } @@ -1237,12 +1237,12 @@ void TFile::LinkTo(const TFile& f) const { } } -TFile TFile::Temporary(const TString& prefix) { +TFile TFile::Temporary(const TString& prefix) { //TODO - handle impossible case of name collision return TFile(prefix + ToString(MicroSeconds()) + "-" + ToString(RandomNumber<ui64>()), CreateNew | RdWr | Seq | Temp | Transient); } -TFile TFile::ForAppend(const TString& path) { +TFile TFile::ForAppend(const TString& path) { return TFile(path, OpenAlways | WrOnly | Seq | ::ForAppend); } @@ -1283,7 +1283,7 @@ TFile Duplicate(int fd) { #endif } -bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept { +bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept { int ret = -1; #if HAVE_POSIX_FADVISE diff --git a/util/system/file.h b/util/system/file.h index efe1e59b4a..9502e159b6 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -52,7 +52,7 @@ enum EOpenModeFlag { Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) Y_DECLARE_OPERATORS_FOR_FLAGS(EOpenMode) -TString DecodeOpenMode(ui32 openMode); +TString DecodeOpenMode(ui32 openMode); enum SeekDir { sSet = 0, @@ -62,68 +62,68 @@ enum SeekDir { class TFileHandle: public TNonCopyable { public: - constexpr TFileHandle() = default; - + constexpr TFileHandle() = default; + /// Warning: takes ownership of fd, so closes it in destructor. - inline TFileHandle(FHANDLE fd) noexcept + inline TFileHandle(FHANDLE fd) noexcept : Fd_(fd) { } - inline TFileHandle(TFileHandle&& other) noexcept + inline TFileHandle(TFileHandle&& other) noexcept : Fd_(other.Fd_) { other.Fd_ = INVALID_FHANDLE; } - TFileHandle(const TString& fName, EOpenMode oMode) noexcept; + TFileHandle(const TString& fName, EOpenMode oMode) noexcept; - inline ~TFileHandle() { + inline ~TFileHandle() { Close(); } - bool Close() noexcept; + bool Close() noexcept; - inline FHANDLE Release() noexcept { + inline FHANDLE Release() noexcept { FHANDLE ret = Fd_; Fd_ = INVALID_FHANDLE; return ret; } - inline void Swap(TFileHandle& r) noexcept { + inline void Swap(TFileHandle& r) noexcept { DoSwap(Fd_, r.Fd_); } - inline operator FHANDLE() const noexcept { + inline operator FHANDLE() const noexcept { return Fd_; } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return Fd_ != INVALID_FHANDLE; } - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; + i64 GetPosition() const noexcept; + i64 GetLength() const noexcept; - i64 Seek(i64 offset, SeekDir origin) noexcept; - bool Resize(i64 length) noexcept; - bool Reserve(i64 length) noexcept; + i64 Seek(i64 offset, SeekDir origin) noexcept; + bool Resize(i64 length) noexcept; + bool Reserve(i64 length) noexcept; bool FallocateNoResize(i64 length) noexcept; bool ShrinkToFit() noexcept; - bool Flush() noexcept; + bool Flush() noexcept; //flush data only, without file metadata - bool FlushData() noexcept; - i32 Read(void* buffer, ui32 byteCount) noexcept; - i32 Write(const void* buffer, ui32 byteCount) noexcept; - i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept; - i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept; - int Flock(int op) noexcept; - - FHANDLE Duplicate() const noexcept; + bool FlushData() noexcept; + i32 Read(void* buffer, ui32 byteCount) noexcept; + i32 Write(const void* buffer, ui32 byteCount) noexcept; + i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept; + i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept; + int Flock(int op) noexcept; + + FHANDLE Duplicate() const noexcept; int Duplicate2Posix(int dstHandle) const noexcept; //dup2 - like semantics, return true on success - bool LinkTo(const TFileHandle& fh) const noexcept; + bool LinkTo(const TFileHandle& fh) const noexcept; //very low-level methods bool SetDirect(); @@ -141,7 +141,7 @@ public: bool FlushCache(i64 offset = 0, i64 length = 0, bool wait = true) noexcept; private: - FHANDLE Fd_ = INVALID_FHANDLE; + FHANDLE Fd_ = INVALID_FHANDLE; }; class TFile { @@ -149,17 +149,17 @@ public: TFile(); /// Takes ownership of handle, so closes it when the last holder of descriptor dies. explicit TFile(FHANDLE fd); - TFile(FHANDLE fd, const TString& fname); - TFile(const TString& fName, EOpenMode oMode); - ~TFile(); + TFile(FHANDLE fd, const TString& fname); + TFile(const TString& fName, EOpenMode oMode); + ~TFile(); void Close(); - const TString& GetName() const noexcept; - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; - bool IsOpen() const noexcept; - FHANDLE GetHandle() const noexcept; + const TString& GetName() const noexcept; + i64 GetPosition() const noexcept; + i64 GetLength() const noexcept; + bool IsOpen() const noexcept; + FHANDLE GetHandle() const noexcept; i64 Seek(i64 offset, SeekDir origin); void Resize(i64 length); @@ -211,8 +211,8 @@ public: //flush unwritten data in this range and optionally wait for completion void FlushCache(i64 offset = 0, i64 length = 0, bool wait = true); - static TFile Temporary(const TString& prefix); - static TFile ForAppend(const TString& path); + static TFile Temporary(const TString& prefix); + static TFile ForAppend(const TString& path); private: class TImpl; @@ -222,4 +222,4 @@ private: TFile Duplicate(FILE*); TFile Duplicate(int); -bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept; +bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept; diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 8681611514..941e6a50f3 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -53,7 +53,7 @@ public: f2.Write("67890", 5); } - UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp2.Name()).ReadAll(), "1234567890"); + UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp2.Name()).ReadAll(), "1234567890"); } inline void TestAppend() { @@ -72,7 +72,7 @@ public: f.Write("89", 2); } - UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "123456786789"); + UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "123456786789"); } inline void TestReWrite() { @@ -90,7 +90,7 @@ public: f.Write("6789", 4); } - UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "67895678"); + UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "67895678"); } inline void TestResize() { @@ -111,7 +111,7 @@ public: UNIT_ASSERT_EQUAL(file.GetPosition(), 3); } - const TString data = TUnbufferedFileInput(tmp.Name()).ReadAll(); + const TString data = TUnbufferedFileInput(tmp.Name()).ReadAll(); UNIT_ASSERT_EQUAL(data.length(), 12); UNIT_ASSERT(data.StartsWith("12345")); } @@ -120,7 +120,7 @@ public: UNIT_TEST_SUITE_REGISTRATION(TFileTest); void TFileTest::TestOpen() { - TString res; + TString res; TFile f1; try { diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 2065868199..7454a4cb94 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -53,7 +53,7 @@ namespace { return *Singleton<TSysInfo>(); } - static inline size_t CalcGranularity() noexcept { + static inline size_t CalcGranularity() noexcept { #if defined(_win_) SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); @@ -75,7 +75,7 @@ TString TMemoryMapCommon::UnknownFileName() { return "Unknown_file_name"; } -static inline i64 DownToGranularity(i64 offset) noexcept { +static inline i64 DownToGranularity(i64 offset) noexcept { return offset & ~((i64)(GRANULARITY - 1)); } @@ -161,7 +161,7 @@ public: } } - inline TImpl(FILE* f, EOpenMode om, TString dbgName) + inline TImpl(FILE* f, EOpenMode om, TString dbgName) : File_(Duplicate(f)) , DbgName_(std::move(dbgName)) , Length_(File_.GetLength()) @@ -171,7 +171,7 @@ public: CreateMapping(); } - inline TImpl(const TString& name, EOpenMode om) + inline TImpl(const TString& name, EOpenMode om) : File_(name, (om & oRdWr) ? OpenExisting | RdWr : OpenExisting | RdOnly) , DbgName_(name) , Length_(File_.GetLength()) @@ -181,7 +181,7 @@ public: CreateMapping(); } - inline TImpl(const TString& name, i64 length, EOpenMode om) + inline TImpl(const TString& name, i64 length, EOpenMode om) : File_(name, (om & oRdWr) ? OpenExisting | RdWr : OpenExisting | RdOnly) , DbgName_(name) , Length_(length) @@ -196,7 +196,7 @@ public: CreateMapping(); } - inline TImpl(const TFile& file, EOpenMode om, TString dbgName) + inline TImpl(const TFile& file, EOpenMode om, TString dbgName) : File_(file) , DbgName_(File_.GetName() ? File_.GetName() : std::move(dbgName)) , Length_(File_.GetLength()) @@ -206,7 +206,7 @@ public: CreateMapping(); } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return File_.IsOpen() #if defined(_win_) && Mapping_ != nullptr @@ -304,7 +304,7 @@ public: #endif } - inline ~TImpl() { + inline ~TImpl() { #if defined(_win_) if (Mapping_) { ::CloseHandle(Mapping_); // != FALSE @@ -317,15 +317,15 @@ public: #endif } - inline i64 Length() const noexcept { + inline i64 Length() const noexcept { return Length_; } - inline TFile GetFile() const noexcept { + inline TFile GetFile() const noexcept { return File_; } - inline TString GetDbgName() const { + inline TString GetDbgName() const { return DbgName_; } @@ -335,7 +335,7 @@ public: private: TFile File_; - TString DbgName_; // This string is never used to actually open a file, only in exceptions + TString DbgName_; // This string is never used to actually open a file, only in exceptions i64 Length_; EOpenMode Mode_; @@ -346,37 +346,37 @@ private: #endif }; -TMemoryMap::TMemoryMap(const TString& name) +TMemoryMap::TMemoryMap(const TString& name) : Impl_(new TImpl(name, EOpenModeFlag::oRdOnly)) { } -TMemoryMap::TMemoryMap(const TString& name, EOpenMode om) +TMemoryMap::TMemoryMap(const TString& name, EOpenMode om) : Impl_(new TImpl(name, om)) { } -TMemoryMap::TMemoryMap(const TString& name, i64 length, EOpenMode om) +TMemoryMap::TMemoryMap(const TString& name, i64 length, EOpenMode om) : Impl_(new TImpl(name, length, om)) { } -TMemoryMap::TMemoryMap(FILE* f, TString dbgName) +TMemoryMap::TMemoryMap(FILE* f, TString dbgName) : Impl_(new TImpl(f, EOpenModeFlag::oRdOnly, std::move(dbgName))) { } -TMemoryMap::TMemoryMap(FILE* f, EOpenMode om, TString dbgName) +TMemoryMap::TMemoryMap(FILE* f, EOpenMode om, TString dbgName) : Impl_(new TImpl(f, om, std::move(dbgName))) { } -TMemoryMap::TMemoryMap(const TFile& file, TString dbgName) +TMemoryMap::TMemoryMap(const TFile& file, TString dbgName) : Impl_(new TImpl(file, EOpenModeFlag::oRdOnly, std::move(dbgName))) { } -TMemoryMap::TMemoryMap(const TFile& file, EOpenMode om, TString dbgName) +TMemoryMap::TMemoryMap(const TFile& file, EOpenMode om, TString dbgName) : Impl_(new TImpl(file, om, std::move(dbgName))) { } @@ -419,11 +419,11 @@ void TMemoryMap::Evict() { Impl_->Evict(); } -i64 TMemoryMap::Length() const noexcept { +i64 TMemoryMap::Length() const noexcept { return Impl_->Length(); } -bool TMemoryMap::IsOpen() const noexcept { +bool TMemoryMap::IsOpen() const noexcept { return Impl_->IsOpen(); } @@ -435,41 +435,41 @@ TMemoryMap::EOpenMode TMemoryMap::GetMode() const noexcept { return Impl_->GetMode(); } -TFile TMemoryMap::GetFile() const noexcept { +TFile TMemoryMap::GetFile() const noexcept { return Impl_->GetFile(); } -TFileMap::TFileMap(const TMemoryMap& map) noexcept +TFileMap::TFileMap(const TMemoryMap& map) noexcept : Map_(map) { } -TFileMap::TFileMap(const TString& name) +TFileMap::TFileMap(const TString& name) : Map_(name) { } -TFileMap::TFileMap(const TString& name, EOpenMode om) +TFileMap::TFileMap(const TString& name, EOpenMode om) : Map_(name, om) { } -TFileMap::TFileMap(const TString& name, i64 length, EOpenMode om) +TFileMap::TFileMap(const TString& name, i64 length, EOpenMode om) : Map_(name, length, om) { } -TFileMap::TFileMap(FILE* f, EOpenMode om, TString dbgName) +TFileMap::TFileMap(FILE* f, EOpenMode om, TString dbgName) : Map_(f, om, dbgName) { } -TFileMap::TFileMap(const TFile& file, EOpenMode om, TString dbgName) +TFileMap::TFileMap(const TFile& file, EOpenMode om, TString dbgName) : Map_(file, om, dbgName) { } -TFileMap::TFileMap(const TFileMap& fm) noexcept +TFileMap::TFileMap(const TFileMap& fm) noexcept : Map_(fm.Map_) { } @@ -516,7 +516,7 @@ void TFileMap::Unmap() { } } -TFileMap::~TFileMap() { +TFileMap::~TFileMap() { try { // explicit Unmap() is required because in oNotGreedy mode the Map_ object doesn't own the mapped area Unmap(); diff --git a/util/system/filemap.h b/util/system/filemap.h index 3f80fe1ded..11be64bff4 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -9,7 +9,7 @@ #include <util/generic/utility.h> #include <util/generic/yexception.h> #include <util/generic/flags.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <new> #include <cstdio> @@ -21,19 +21,19 @@ namespace NPrivate { struct TMemoryMapCommon { struct TMapResult { - inline size_t MappedSize() const noexcept { + inline size_t MappedSize() const noexcept { return Size - Head; } - inline void* MappedData() const noexcept { + inline void* MappedData() const noexcept { return Ptr ? (void*)((char*)Ptr + Head) : nullptr; } - inline bool IsMapped() const noexcept { + inline bool IsMapped() const noexcept { return Ptr != nullptr; } - inline void Reset() noexcept { + inline void Reset() noexcept { Ptr = nullptr; Size = 0; Head = 0; @@ -43,7 +43,7 @@ struct TMemoryMapCommon { size_t Size; i32 Head; - TMapResult(void) noexcept { + TMapResult(void) noexcept { Reset(); } }; @@ -70,15 +70,15 @@ Y_DECLARE_OPERATORS_FOR_FLAGS(TMemoryMapCommon::EOpenMode) class TMemoryMap: public TMemoryMapCommon { public: - explicit TMemoryMap(const TString& name); - explicit TMemoryMap(const TString& name, EOpenMode om); - TMemoryMap(const TString& name, i64 length, EOpenMode om); + explicit TMemoryMap(const TString& name); + explicit TMemoryMap(const TString& name, EOpenMode om); + TMemoryMap(const TString& name, i64 length, EOpenMode om); TMemoryMap(FILE* f, TString dbgName = UnknownFileName()); TMemoryMap(FILE* f, EOpenMode om, TString dbgName = UnknownFileName()); TMemoryMap(const TFile& file, TString dbgName = UnknownFileName()); TMemoryMap(const TFile& file, EOpenMode om, TString dbgName = UnknownFileName()); - ~TMemoryMap(); + ~TMemoryMap(); TMapResult Map(i64 offset, size_t size); bool Unmap(TMapResult region); @@ -86,11 +86,11 @@ public: void ResizeAndReset(i64 size); TMapResult ResizeAndRemap(i64 offset, size_t size); - i64 Length() const noexcept; - bool IsOpen() const noexcept; + i64 Length() const noexcept; + bool IsOpen() const noexcept; bool IsWritable() const noexcept; EOpenMode GetMode() const noexcept; - TFile GetFile() const noexcept; + TFile GetFile() const noexcept; void SetSequential(); void Evict(void* ptr, size_t len); @@ -108,15 +108,15 @@ private: class TFileMap: public TMemoryMapCommon { public: - TFileMap(const TMemoryMap& map) noexcept; - TFileMap(const TString& name); - TFileMap(const TString& name, EOpenMode om); - TFileMap(const TString& name, i64 length, EOpenMode om); + TFileMap(const TMemoryMap& map) noexcept; + TFileMap(const TString& name); + TFileMap(const TString& name, EOpenMode om); + TFileMap(const TString& name, i64 length, EOpenMode om); TFileMap(FILE* f, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName()); TFileMap(const TFile& file, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName()); - TFileMap(const TFileMap& fm) noexcept; + TFileMap(const TFileMap& fm) noexcept; - ~TFileMap(); + ~TFileMap(); TMapResult Map(i64 offset, size_t size); TMapResult ResizeAndRemap(i64 offset, size_t size); @@ -138,11 +138,11 @@ public: FlushAsync(Ptr(), MappedSize()); } - inline i64 Length() const noexcept { + inline i64 Length() const noexcept { return Map_.Length(); } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return Map_.IsOpen(); } @@ -154,15 +154,15 @@ public: return Map_.GetMode(); } - inline void* Ptr() const noexcept { + inline void* Ptr() const noexcept { return Region_.MappedData(); } - inline size_t MappedSize() const noexcept { + inline size_t MappedSize() const noexcept { return Region_.MappedSize(); } - TFile GetFile() const noexcept { + TFile GetFile() const noexcept { return Map_.GetFile(); } @@ -241,7 +241,7 @@ public: Dummy_.Destroy(); Dummy_.Reset(new (DummyData()) T(n_Dummy)); } - inline char* DummyData() const noexcept { + inline char* DummyData() const noexcept { return AlignUp((char*)DummyData_); } inline const T& Dummy() const { @@ -260,22 +260,22 @@ public: return 0 == Size_; } /// for STL compatibility only, Begin() usage is recommended - const T* begin() const noexcept { + const T* begin() const noexcept { return Begin(); } - const T* Begin() const noexcept { + const T* Begin() const noexcept { return Ptr_; } /// for STL compatibility only, End() usage is recommended - const T* end() const noexcept { + const T* end() const noexcept { return End_; } - const T* End() const noexcept { + const T* End() const noexcept { return End_; } private: - void DoInit(const TString& fileName) { + void DoInit(const TString& fileName) { DataHolder_->Map(0, DataHolder_->Length()); if (DataHolder_->Length() % sizeof(T)) { Term(); @@ -308,10 +308,10 @@ public: char* Data(ui32 pos = 0) const { return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr); } - char* Begin() const noexcept { + char* Begin() const noexcept { return (char*)Ptr(); } - char* End() const noexcept { + char* End() const noexcept { return Begin() + MappedSize(); } size_t MappedSize() const { diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 158be2bd58..73f109dc88 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -301,7 +301,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { - TString text = exc.what(); // exception should contain failed file name + TString text = exc.what(); // exception should contain failed file name UNIT_ASSERT(text.find(TMemoryMapCommon::UnknownFileName()) != TString::npos); fclose(f); } @@ -312,8 +312,8 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { - TString text = exc.what(); // exception should contain failed file name - UNIT_ASSERT(text.find(FileName_) != TString::npos); + TString text = exc.what(); // exception should contain failed file name + UNIT_ASSERT(text.find(FileName_) != TString::npos); } NFs::Remove(FileName_); } diff --git a/util/system/fs.cpp b/util/system/fs.cpp index 33ff900888..d2611a8ccc 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -16,7 +16,7 @@ #include <util/system/fstat.h> #include <util/folder/path.h> -bool NFs::Remove(const TString& path) { +bool NFs::Remove(const TString& path) { #if defined(_win_) return NFsPrivate::WinRemove(path); #else @@ -24,7 +24,7 @@ bool NFs::Remove(const TString& path) { #endif } -void NFs::RemoveRecursive(const TString& path) { +void NFs::RemoveRecursive(const TString& path) { static const TStringBuf errStr = "error while removing "; if (!NFs::Exists(path)) { @@ -53,7 +53,7 @@ void NFs::RemoveRecursive(const TString& path) { } } -bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) { +bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) { #if defined(_win_) Y_UNUSED(mode); return NFsPrivate::WinMakeDirectory(path); @@ -62,7 +62,7 @@ bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) { #endif } -bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate) { +bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate) { if (NFs::Exists(path) && TFileStat(path).IsDir()) { if (alwaysCreate) { ythrow TIoException() << "path " << path << " already exists" @@ -84,7 +84,7 @@ bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, boo } } -bool NFs::Rename(const TString& oldPath, const TString& newPath) { +bool NFs::Rename(const TString& oldPath, const TString& newPath) { #if defined(_win_) return NFsPrivate::WinRename(oldPath, newPath); #else @@ -92,13 +92,13 @@ bool NFs::Rename(const TString& oldPath, const TString& newPath) { #endif } -void NFs::HardLinkOrCopy(const TString& existingPath, 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) { +bool NFs::HardLink(const TString& existingPath, const TString& newPath) { #if defined(_win_) return NFsPrivate::WinHardLink(existingPath, newPath); #elif defined(_unix_) @@ -106,7 +106,7 @@ bool NFs::HardLink(const TString& existingPath, const TString& newPath) { #endif } -bool NFs::SymLink(const TString& targetPath, const TString& linkPath) { +bool NFs::SymLink(const TString& targetPath, const TString& linkPath) { #if defined(_win_) return NFsPrivate::WinSymLink(targetPath, linkPath); #elif defined(_unix_) @@ -114,7 +114,7 @@ bool NFs::SymLink(const TString& targetPath, const TString& linkPath) { #endif } -TString NFs::ReadLink(const TString& path) { +TString NFs::ReadLink(const TString& path) { #if defined(_win_) return NFsPrivate::WinReadLink(path); #elif defined(_unix_) @@ -125,28 +125,28 @@ TString NFs::ReadLink(const TString& path) { ythrow yexception() << "can't read link " << path << ", errno = " << errno; } if (r < (ssize_t)buf.Size()) { - return TString(buf.Data(), r); + return TString(buf.Data(), r); } buf = TTempBuf(buf.Size() * 2); } #endif } -void NFs::Cat(const TString& dstPath, const TString& srcPath) { - TUnbufferedFileInput src(srcPath); - TUnbufferedFileOutput dst(TFile(dstPath, ForAppend | WrOnly | Seq)); +void NFs::Cat(const TString& dstPath, const TString& srcPath) { + TUnbufferedFileInput src(srcPath); + TUnbufferedFileOutput dst(TFile(dstPath, ForAppend | WrOnly | Seq)); TransferData(&src, &dst); } -void NFs::Copy(const TString& existingPath, const TString& newPath) { - TUnbufferedFileInput src(existingPath); - TUnbufferedFileOutput dst(TFile(newPath, CreateAlways | WrOnly | Seq)); +void NFs::Copy(const TString& existingPath, const TString& newPath) { + TUnbufferedFileInput src(existingPath); + TUnbufferedFileOutput dst(TFile(newPath, CreateAlways | WrOnly | Seq)); TransferData(&src, &dst); } -bool NFs::Exists(const TString& path) { +bool NFs::Exists(const TString& path) { #if defined(_win_) return NFsPrivate::WinExists(path); #elif defined(_unix_) @@ -154,7 +154,7 @@ bool NFs::Exists(const TString& path) { #endif } -TString NFs::CurrentWorkingDirectory() { +TString NFs::CurrentWorkingDirectory() { #if defined(_win_) return NFsPrivate::WinCurrentWorkingDirectory(); #elif defined(_unix_) @@ -167,7 +167,7 @@ TString NFs::CurrentWorkingDirectory() { #endif } -void NFs::SetCurrentWorkingDirectory(TString path) { +void NFs::SetCurrentWorkingDirectory(TString path) { #ifdef _win_ bool ok = NFsPrivate::WinSetCurrentWorkingDirectory(path); #else diff --git a/util/system/fs.h b/util/system/fs.h index a412f6cb15..237daf2d2d 100644 --- a/util/system/fs.h +++ b/util/system/fs.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/flags.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/yexception.h> namespace NFs { @@ -28,27 +28,27 @@ namespace NFs { /// @param[in] path Path to file or directory /// @returns true on success or false otherwise /// LastSystemError() is set in case of failure - bool Remove(const TString& path); + bool Remove(const TString& path); /// Remove a file or directory with contents /// /// @param[in] path Path to file or directory /// @throws - void RemoveRecursive(const TString& path); + void RemoveRecursive(const TString& path); /// Creates directory /// /// @param[in] path Path to the directory /// @param[in] mode Access permissions field; NOTE: ignored on win /// @returns true on success or false otherwise - bool MakeDirectory(const TString& path, EFilePermissions mode); + bool MakeDirectory(const TString& path, EFilePermissions mode); /// Creates directory /// /// @param[in] path Path to the directory /// @returns true on success or false otherwise /// NOTE: access permissions is set to 0777 - inline bool MakeDirectory(const TString& path) { + inline bool MakeDirectory(const TString& path) { return MakeDirectory(path, FP_COMMON_FILE); } @@ -58,14 +58,14 @@ namespace NFs { /// @param[in] mode Access permissions field; NOTE: ignored on win /// @param[in] alwaysCreate Throw if path already exists or failed to create /// @returns true if target path created or exists (and directory) - bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate); + bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate); /// Creates directory and all non-existings parents /// /// @param[in] path Path to be created /// @param[in] mode Access permissions field; NOTE: ignored on win /// @returns true if target path created or exists (and directory) - inline bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode) { + inline bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode) { return MakeDirectoryRecursive(path, mode, false); } @@ -73,7 +73,7 @@ namespace NFs { /// /// @param[in] path Path to be created /// @returns true if target path created or exists (and directory) - inline bool MakeDirectoryRecursive(const TString& path) { + inline bool MakeDirectoryRecursive(const TString& path) { return MakeDirectoryRecursive(path, FP_COMMON_FILE, false); } @@ -84,14 +84,14 @@ namespace NFs { /// @param[in] newPath New path of file or directory /// @returns true on success or false otherwise /// LastSystemError() is set in case of failure - bool Rename(const TString& oldPath, const TString& newPath); + bool Rename(const TString& oldPath, const TString& newPath); /// Creates a new directory entry for a file /// or creates a new one with the same content /// /// @param[in] existingPath Path to an existing file /// @param[in] newPath New path of file - void HardLinkOrCopy(const TString& existingPath, const TString& newPath); + void HardLinkOrCopy(const TString& existingPath, const TString& newPath); /// Creates a new directory entry for a file /// @@ -99,7 +99,7 @@ namespace NFs { /// @param[in] newPath New path of file /// @returns true if new link was created or false otherwise /// LastSystemError() is set in case of failure - bool HardLink(const TString& existingPath, const TString& newPath); + bool HardLink(const TString& existingPath, const TString& newPath); /// Creates a symlink to a file /// @@ -107,47 +107,47 @@ namespace NFs { /// @param[in] linkPath Path of symlink /// @returns true if new link was created or false otherwise /// LastSystemError() is set in case of failure - bool SymLink(const TString& targetPath, const TString& linkPath); + bool SymLink(const TString& targetPath, const TString& linkPath); /// Reads value of a symbolic link /// /// @param[in] path Path to a symlink /// @returns File path that a symlink points to - TString ReadLink(const TString& path); + TString ReadLink(const TString& path); /// Append contents of a file to a new file /// /// @param[in] dstPath Path to a destination file /// @param[in] srcPath Path to a source file - void Cat(const TString& dstPath, const TString& srcPath); + void Cat(const TString& dstPath, const TString& srcPath); /// Copy contents of a file to a new file /// /// @param[in] existingPath Path to an existing file /// @param[in] newPath New path of file - void Copy(const TString& existingPath, const TString& newPath); + void Copy(const TString& existingPath, const TString& newPath); /// Returns path to the current working directory /// /// Note: is not threadsafe - TString CurrentWorkingDirectory(); + TString CurrentWorkingDirectory(); /// Changes current working directory /// /// @param[in] path Path for new cwd /// Note: is not threadsafe - void SetCurrentWorkingDirectory(TString path); + void SetCurrentWorkingDirectory(TString path); /// Checks if file exists /// /// @param[in] path Path to check - bool Exists(const TString& path); + bool Exists(const TString& path); /// Ensures that file exists /// /// @param[in] path Path to check /// @returns input argument - inline const TString& EnsureExists(const TString& path) { + inline const TString& EnsureExists(const TString& path) { Y_ENSURE_EX(Exists(path), TFileError{} << "Path " << path << " does not exists (checked from cwd:" << NFs::CurrentWorkingDirectory() << ")"); return path; } diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index 1b3baff09f..de071ebf55 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -56,7 +56,7 @@ void TFsTest::TestCreateRemove() { UNIT_ASSERT_EXCEPTION(NFs::MakeDirectoryRecursive(subdir1, NFs::FP_COMMON_FILE, true), TIoException); TFsPath file1 = dir1 / "f1.txt"; - TFsPath file2 = subdir1 + TString("_f2.txt"); + TFsPath file2 = subdir1 + TString("_f2.txt"); TFsPath file3 = subdir1 / "f2.txt"; Touch(file1); Touch(file2); @@ -70,7 +70,7 @@ void TFsTest::TestCreateRemove() { UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1 / "subdir1" / "subdir2", NFs::FP_COMMON_FILE, false)); UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1, NFs::FP_COMMON_FILE, false)); - TString longUtf8Name = ""; + TString longUtf8Name = ""; while (longUtf8Name.size() < 255) { longUtf8Name = longUtf8Name + "fф"; } @@ -191,7 +191,7 @@ void TFsTest::TestHardlink() { RunHardlinkTest("tempfile_абвг", "hardlinkfile_абвг"); //utf-8 names } -static void RunSymLinkTest(TString fileLocalName, TString symLinkName) { +static void RunSymLinkTest(TString fileLocalName, TString symLinkName) { // if previous running was failed TFsPath subDir = "tempsubdir"; TFsPath srcFile = subDir / fileLocalName; @@ -222,8 +222,8 @@ static void RunSymLinkTest(TString fileLocalName, TString symLinkName) { UNIT_ASSERT(NFs::SymLink(subDir, linkD1)); UNIT_ASSERT(NFs::SymLink("../dir2", linkD2)); UNIT_ASSERT(NFs::SymLink("../dir3", dangling)); - UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(linkD2), TString("..") + LOCSLASH_S "dir2"); - UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(dangling), TString("..") + LOCSLASH_S "dir3"); + UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(linkD2), TString("..") + LOCSLASH_S "dir2"); + UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(dangling), TString("..") + LOCSLASH_S "dir3"); { TFile file(linkD1 / fileLocalName, OpenExisting | RdOnly); UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7); @@ -311,7 +311,7 @@ void TFsTest::TestEnsureExists() { UNIT_ASSERT_EXCEPTION(NFs::EnsureExists(nonExists), TFileError); TStringBuilder expected; - TString got; + TString got; try { NFs::EnsureExists(nonExists); expected << __LOCATION__; diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp index 79f7c43ecd..a410ccac06 100644 --- a/util/system/fs_win.cpp +++ b/util/system/fs_win.cpp @@ -9,7 +9,7 @@ #include <winioctl.h> namespace NFsPrivate { - static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) { + static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) { wstr.resize(str.size()); size_t written = 0; if (!UTF8ToWide(str.data(), str.size(), wstr.begin(), written)) @@ -19,14 +19,14 @@ namespace NFsPrivate { return (const WCHAR*)wstr.data(); } - static TString WCHARToUTF8(const LPWSTR wstr, size_t len) { + static TString WCHARToUTF8(const LPWSTR wstr, size_t len) { static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)"); return WideToUTF8((wchar16*)wstr, len); } HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle) { - TUtf16String wstr; + TUtf16String wstr; LPCWSTR wname = UTF8ToWCHAR(fName, wstr); if (!wname) { ::SetLastError(ERROR_INVALID_NAME); @@ -39,8 +39,8 @@ namespace NFsPrivate { return ::CreateFileW(wname, accessMode, shareMode, &secAttrs, createMode, attributes, nullptr); } - bool WinRename(const TString& oldPath, const TString& newPath) { - TUtf16String op, np; + bool WinRename(const TString& oldPath, const TString& newPath) { + TUtf16String op, np; LPCWSTR opPtr = UTF8ToWCHAR(oldPath, op); LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); if (!opPtr || !npPtr) { @@ -51,8 +51,8 @@ namespace NFsPrivate { return MoveFileExW(opPtr, npPtr, MOVEFILE_REPLACE_EXISTING) != 0; } - bool WinRemove(const TString& path) { - TUtf16String wstr; + bool WinRemove(const TString& path) { + TUtf16String wstr; LPCWSTR wname = UTF8ToWCHAR(path, wstr); if (!wname) { ::SetLastError(ERROR_INVALID_NAME); @@ -68,16 +68,16 @@ namespace NFsPrivate { return false; } - bool WinSymLink(const TString& targetName, const TString& linkName) { - TString tName(targetName); + bool WinSymLink(const TString& targetName, const TString& linkName) { + TString tName(targetName); { size_t pos; - while ((pos = tName.find('/')) != TString::npos) + while ((pos = tName.find('/')) != TString::npos) tName.replace(pos, 1, LOCSLASH_S); } - TUtf16String tstr; + TUtf16String tstr; LPCWSTR wname = UTF8ToWCHAR(tName, tstr); - TUtf16String lstr; + TUtf16String lstr; LPCWSTR lname = UTF8ToWCHAR(linkName, lstr); // we can't create a dangling link to a dir in this way @@ -85,14 +85,14 @@ namespace NFsPrivate { if (attr == INVALID_FILE_ATTRIBUTES) { TTempBuf result; if (GetFullPathNameW(lname, result.Size(), (LPWSTR)result.Data(), 0) != 0) { - TString fullPath = WideToUTF8(TWtringBuf((const wchar16*)result.Data())); + TString fullPath = WideToUTF8(TWtringBuf((const wchar16*)result.Data())); TStringBuf linkDir(fullPath); linkDir.RNextTok('\\'); if (linkDir) { - TString fullTarget(tName); + TString fullTarget(tName); resolvepath(fullTarget, TString{linkDir}); - TUtf16String fullTargetW; + TUtf16String fullTargetW; LPCWSTR ptrFullTarget = UTF8ToWCHAR(fullTarget, fullTargetW); attr = ::GetFileAttributesW(ptrFullTarget); } @@ -101,8 +101,8 @@ namespace NFsPrivate { return 0 != CreateSymbolicLinkW(lname, wname, attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0); } - bool WinHardLink(const TString& existingPath, const TString& newPath) { - TUtf16String ep, np; + bool WinHardLink(const TString& existingPath, const TString& newPath) { + TUtf16String ep, np; LPCWSTR epPtr = UTF8ToWCHAR(existingPath, ep); LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); if (!epPtr || !npPtr) { @@ -113,13 +113,13 @@ namespace NFsPrivate { return (CreateHardLinkW(npPtr, epPtr, nullptr) != 0); } - bool WinExists(const TString& path) { - TUtf16String buf; + bool WinExists(const TString& path) { + TUtf16String buf; LPCWSTR ptr = UTF8ToWCHAR(path, buf); return ::GetFileAttributesW(ptr) != INVALID_FILE_ATTRIBUTES; } - TString WinCurrentWorkingDirectory() { + TString WinCurrentWorkingDirectory() { TTempBuf result; LPWSTR buf = reinterpret_cast<LPWSTR>(result.Data()); int r = GetCurrentDirectoryW(result.Size() / sizeof(WCHAR), buf); @@ -128,8 +128,8 @@ namespace NFsPrivate { return WCHARToUTF8(buf, r); } - bool WinSetCurrentWorkingDirectory(const TString& path) { - TUtf16String wstr; + bool WinSetCurrentWorkingDirectory(const TString& path) { + TUtf16String wstr; LPCWSTR wname = UTF8ToWCHAR(path, wstr); if (!wname) { ::SetLastError(ERROR_INVALID_NAME); @@ -138,8 +138,8 @@ namespace NFsPrivate { return SetCurrentDirectoryW(wname); } - bool WinMakeDirectory(const TString path) { - TUtf16String buf; + bool WinMakeDirectory(const TString path) { + TUtf16String buf; LPCWSTR ptr = UTF8ToWCHAR(path, buf); return CreateDirectoryW(ptr, (LPSECURITY_ATTRIBUTES) nullptr); } @@ -180,7 +180,7 @@ namespace NFsPrivate { // the end of edited part of <Ntifs.h> - TString WinReadLink(const TString& name) { + TString WinReadLink(const TString& name) { TFileHandle h = CreateFileWithUtf8Name(name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, true); TTempBuf buf; @@ -199,7 +199,7 @@ namespace NFsPrivate { return WideToUTF8(str, len); } //this reparse point is unsupported in arcadia - return TString(); + return TString(); } else { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { buf = TTempBuf(buf.Size() * 2); diff --git a/util/system/fs_win.h b/util/system/fs_win.h index b32bb0fefe..8086129828 100644 --- a/util/system/fs_win.h +++ b/util/system/fs_win.h @@ -4,26 +4,26 @@ #include "defaults.h" #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h> namespace NFsPrivate { - bool WinRename(const TString& oldPath, const TString& newPath); + bool WinRename(const TString& oldPath, const TString& newPath); - bool WinSymLink(const TString& targetName, const TString& linkName); + bool WinSymLink(const TString& targetName, const TString& linkName); - bool WinHardLink(const TString& existingPath, const TString& newPath); + bool WinHardLink(const TString& existingPath, const TString& newPath); - TString WinReadLink(const TString& path); + TString WinReadLink(const TString& path); HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle); - bool WinRemove(const TString& path); + bool WinRemove(const TString& path); - bool WinExists(const TString& path); + bool WinExists(const TString& path); - TString WinCurrentWorkingDirectory(); + TString WinCurrentWorkingDirectory(); - bool WinSetCurrentWorkingDirectory(const TString& path); + bool WinSetCurrentWorkingDirectory(const TString& path); - bool WinMakeDirectory(const TString path); + bool WinMakeDirectory(const TString path); } diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 1fc66b4f70..81e98cbc6b 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -124,7 +124,7 @@ TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) { MakeFromFileName(fileName.GetPath().data(), nofollow); } -TFileStat::TFileStat(const TString& fileName, bool nofollow) { +TFileStat::TFileStat(const TString& fileName, bool nofollow) { MakeFromFileName(fileName.data(), nofollow); } @@ -210,6 +210,6 @@ i64 GetFileLength(const char* name) { #endif } -i64 GetFileLength(const TString& name) { +i64 GetFileLength(const TString& name) { return GetFileLength(name.data()); } diff --git a/util/system/fstat.h b/util/system/fstat.h index e1505e6041..64e79e1b55 100644 --- a/util/system/fstat.h +++ b/util/system/fstat.h @@ -32,7 +32,7 @@ public: explicit TFileStat(const TFile& f); explicit TFileStat(FHANDLE f); TFileStat(const TFsPath& fileName, bool nofollow = false); - TFileStat(const TString& fileName, bool nofollow = false); + TFileStat(const TString& fileName, bool nofollow = false); TFileStat(const char* fileName, bool nofollow = false); friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept; @@ -44,4 +44,4 @@ private: i64 GetFileLength(FHANDLE fd); i64 GetFileLength(const char* name); -i64 GetFileLength(const TString& name); +i64 GetFileLength(const TString& name); diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index ed126eaead..160ecd936e 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -10,7 +10,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) { Y_UNIT_TEST(FileTest) { - TString fileName = "f1.txt"; + TString fileName = "f1.txt"; TFileStat oFs; { TFile file(fileName.data(), OpenAlways | WrOnly); diff --git a/util/system/guard.h b/util/system/guard.h index 19c4491424..efc091d5f8 100644 --- a/util/system/guard.h +++ b/util/system/guard.h @@ -8,14 +8,14 @@ struct TCommonLockOps { t->Acquire(); } - static inline void Release(T* t) noexcept { + static inline void Release(T* t) noexcept { t->Release(); } }; template <class T> struct TTryLockOps: public TCommonLockOps<T> { - static inline bool TryAcquire(T* t) noexcept { + static inline bool TryAcquire(T* t) noexcept { return t->TryAcquire(); } }; @@ -24,7 +24,7 @@ struct TTryLockOps: public TCommonLockOps<T> { template <class TOps> struct TInverseLockOps: public TOps { template <class T> - static inline void Acquire(T* t) noexcept { + static inline void Acquire(T* t) noexcept { TOps::Release(t); } @@ -45,32 +45,32 @@ public: Init(t); } - inline TGuard(TGuard&& g) noexcept + inline TGuard(TGuard&& g) noexcept : T_(g.T_) { g.T_ = nullptr; } - inline ~TGuard() { + inline ~TGuard() { Release(); } - inline void Release() noexcept { + inline void Release() noexcept { if (WasAcquired()) { TOps::Release(T_); T_ = nullptr; } } - explicit inline operator bool() const noexcept { + explicit inline operator bool() const noexcept { return WasAcquired(); } - inline bool WasAcquired() const noexcept { + inline bool WasAcquired() const noexcept { return T_ != nullptr; } - inline T* GetMutex() const noexcept { + inline T* GetMutex() const noexcept { return T_; } @@ -129,11 +129,11 @@ static inline TInverseGuard<T> Unguard(const T& mutex) { template <class T, class TOps = TTryLockOps<T>> class TTryGuard: public TNonCopyable { public: - inline TTryGuard(const T& t) noexcept { + inline TTryGuard(const T& t) noexcept { Init(&t); } - inline TTryGuard(const T* t) noexcept { + inline TTryGuard(const T* t) noexcept { Init(t); } @@ -143,27 +143,27 @@ public: g.T_ = nullptr; } - inline ~TTryGuard() { + inline ~TTryGuard() { Release(); } - inline void Release() noexcept { + inline void Release() noexcept { if (WasAcquired()) { TOps::Release(T_); T_ = nullptr; } } - inline bool WasAcquired() const noexcept { + inline bool WasAcquired() const noexcept { return T_ != nullptr; } - explicit inline operator bool() const noexcept { + explicit inline operator bool() const noexcept { return WasAcquired(); } private: - inline void Init(const T* t) noexcept { + inline void Init(const T* t) noexcept { T_ = nullptr; T* tMutable = const_cast<T*>(t); if (TOps::TryAcquire(tMutable)) { diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 397f64bae9..386f646d6b 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -29,7 +29,7 @@ namespace { HostName = hostNameBuf.Data(); } - TString HostName; + TString HostName; }; struct TFQDNHostNameHolder { @@ -60,11 +60,11 @@ namespace { FQDNHostName.to_lower(); } - TString FQDNHostName; + TString FQDNHostName; }; } -const TString& HostName() { +const TString& HostName() { return (Singleton<THostNameHolder>())->HostName; } @@ -72,7 +72,7 @@ const char* GetHostName() { return HostName().data(); } -const TString& FQDNHostName() { +const TString& FQDNHostName() { return (Singleton<TFQDNHostNameHolder>())->FQDNHostName; } @@ -80,8 +80,8 @@ const char* GetFQDNHostName() { return FQDNHostName().data(); } -bool IsFQDN(const TString& name) { - TString absName = name; +bool IsFQDN(const TString& name) { + TString absName = name; if (!absName.EndsWith('.')) { absName.append("."); } diff --git a/util/system/hostname.h b/util/system/hostname.h index bf8c90fac8..0839ee2b59 100644 --- a/util/system/hostname.h +++ b/util/system/hostname.h @@ -3,8 +3,8 @@ #include <util/generic/fwd.h> const char* GetHostName(); -const TString& HostName(); +const TString& HostName(); const char* GetFQDNHostName(); -const TString& FQDNHostName(); -bool IsFQDN(const TString& name); +const TString& FQDNHostName(); +bool IsFQDN(const TString& name); diff --git a/util/system/info.cpp b/util/system/info.cpp index 9d66c38f0c..cf6681e89a 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -176,7 +176,7 @@ size_t NSystemInfo::CachedNumberOfCpus() { return NCpus; } -size_t NSystemInfo::GetPageSize() noexcept { +size_t NSystemInfo::GetPageSize() noexcept { #if defined(_win_) SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); diff --git a/util/system/info.h b/util/system/info.h index 8894f8e6bb..73ebe48a9a 100644 --- a/util/system/info.h +++ b/util/system/info.h @@ -6,7 +6,7 @@ namespace NSystemInfo { size_t NumberOfCpus(); size_t CachedNumberOfCpus(); size_t LoadAverage(double* la, size_t len); - size_t GetPageSize() noexcept; + size_t GetPageSize() noexcept; size_t TotalMemorySize(); size_t MaxOpenFiles(); } diff --git a/util/system/madvise.cpp b/util/system/madvise.cpp index ababb94f3f..58c894e3ef 100644 --- a/util/system/madvise.cpp +++ b/util/system/madvise.cpp @@ -35,7 +35,7 @@ namespace { } #else if (-1 == madvise(begin, size, flag)) { - TString err(LastSystemErrorText()); + TString err(LastSystemErrorText()); ythrow yexception() << "madvise(" << begin << ", " << size << ", " << flag << ")" << " returned error: " << err; } diff --git a/util/system/mem_info.cpp b/util/system/mem_info.cpp index 49e906f006..aa51ae3b16 100644 --- a/util/system/mem_info.cpp +++ b/util/system/mem_info.cpp @@ -115,7 +115,7 @@ namespace NMemInfo { } else { path = TStringBuilder() << TStringBuf("/proc/") << pid << TStringBuf("/statm"); } - const TString stats = TUnbufferedFileInput(path).ReadAll(); + const TString stats = TUnbufferedFileInput(path).ReadAll(); TStringBuf statsiter(stats); @@ -136,7 +136,7 @@ namespace NMemInfo { errno = 0; if (sysctl((int*)mib, 4, &proc, &size, nullptr, 0) == -1) { int err = errno; - TString errtxt = LastSystemErrorText(err); + TString errtxt = LastSystemErrorText(err); ythrow yexception() << "sysctl({CTL_KERN,KERN_PROC,KERN_PROC_PID,pid},4,proc,&size,NULL,0) returned -1, errno: " << err << " (" << errtxt << ")" << Endl; } @@ -151,7 +151,7 @@ namespace NMemInfo { if (r != sizeof(taskInfo)) { int err = errno; - TString errtxt = LastSystemErrorText(err); + TString errtxt = LastSystemErrorText(err); ythrow yexception() << "proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &taskInfo, sizeof(taskInfo)) returned " << r << ", errno: " << err << " (" << errtxt << ")" << Endl; } result.VMS = taskInfo.pti_virtual_size; diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 4b7096cd12..4041402db9 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -33,7 +33,7 @@ public: } } - inline ~T() { + inline ~T() { int result = pthread_mutexattr_destroy(&Attr); Y_VERIFY(result == 0, "mutexattr destroy(%s)", LastSystemErrorText(result)); } @@ -46,7 +46,7 @@ public: #endif } - inline ~TImpl() { + inline ~TImpl() { #if defined(_win_) DeleteCriticalSection(&Obj); #else @@ -55,7 +55,7 @@ public: #endif } - inline void Acquire() noexcept { + inline void Acquire() noexcept { #if defined(_win_) EnterCriticalSection(&Obj); #else @@ -87,7 +87,7 @@ public: } #endif // _win_ - inline bool TryAcquire() noexcept { + inline bool TryAcquire() noexcept { #if defined(_win_) return TryEnterCriticalSectionInt(&Obj); #else @@ -99,7 +99,7 @@ public: #endif } - inline void Release() noexcept { + inline void Release() noexcept { #if defined(_win_) LeaveCriticalSection(&Obj); #else @@ -108,7 +108,7 @@ public: #endif } - inline void* Handle() const noexcept { + inline void* Handle() const noexcept { return (void*)&Obj; } diff --git a/util/system/mutex.h b/util/system/mutex.h index 02cd05586c..032630d134 100644 --- a/util/system/mutex.h +++ b/util/system/mutex.h @@ -8,14 +8,14 @@ class TFakeMutex: public TNonCopyable { public: - inline void Acquire() noexcept { + inline void Acquire() noexcept { } - inline bool TryAcquire() noexcept { + inline bool TryAcquire() noexcept { return true; } - inline void Release() noexcept { + inline void Release() noexcept { } inline void lock() noexcept { @@ -39,9 +39,9 @@ public: TMutex(TMutex&&); ~TMutex(); - void Acquire() noexcept; - bool TryAcquire() noexcept; - void Release() noexcept; + void Acquire() noexcept; + bool TryAcquire() noexcept; + void Release() noexcept; inline void lock() noexcept { Acquire(); @@ -56,7 +56,7 @@ public: } //return opaque pointer to real handler - void* Handle() const noexcept; + void* Handle() const noexcept; private: class TImpl; diff --git a/util/system/pipe.cpp b/util/system/pipe.cpp index fb3d8229a0..a543bd7472 100644 --- a/util/system/pipe.cpp +++ b/util/system/pipe.cpp @@ -3,7 +3,7 @@ #include <util/stream/output.h> #include <util/generic/yexception.h> -ssize_t TPipeHandle::Read(void* buffer, size_t byteCount) const noexcept { +ssize_t TPipeHandle::Read(void* buffer, size_t byteCount) const noexcept { #ifdef _win_ return recv(Fd_, (char*)buffer, byteCount, 0); #else @@ -11,7 +11,7 @@ ssize_t TPipeHandle::Read(void* buffer, size_t byteCount) const noexcept { #endif } -ssize_t TPipeHandle::Write(const void* buffer, size_t byteCount) const noexcept { +ssize_t TPipeHandle::Write(const void* buffer, size_t byteCount) const noexcept { #ifdef _win_ return send(Fd_, (const char*)buffer, byteCount, 0); #else @@ -19,7 +19,7 @@ ssize_t TPipeHandle::Write(const void* buffer, size_t byteCount) const noexcept #endif } -bool TPipeHandle::Close() noexcept { +bool TPipeHandle::Close() noexcept { bool ok = true; if (Fd_ != INVALID_PIPEHANDLE) { #ifdef _win_ @@ -94,7 +94,7 @@ public: } } - TPipeHandle& GetHandle() noexcept { + TPipeHandle& GetHandle() noexcept { return Handle_; } @@ -134,11 +134,11 @@ void TPipe::Close() { Impl_->Close(); } -PIPEHANDLE TPipe::GetHandle() const noexcept { +PIPEHANDLE TPipe::GetHandle() const noexcept { return Impl_->GetHandle(); } -bool TPipe::IsOpen() const noexcept { +bool TPipe::IsOpen() const noexcept { return Impl_->IsOpen(); } diff --git a/util/system/pipe.h b/util/system/pipe.h index 92dd33362f..75d0360049 100644 --- a/util/system/pipe.h +++ b/util/system/pipe.h @@ -17,42 +17,42 @@ using PIPEHANDLE = SOCKET; /// Pipe-like object: pipe on POSIX and socket on windows class TPipeHandle: public TNonCopyable { public: - inline TPipeHandle() noexcept + inline TPipeHandle() noexcept : Fd_(INVALID_PIPEHANDLE) { } - inline TPipeHandle(PIPEHANDLE fd) noexcept + inline TPipeHandle(PIPEHANDLE fd) noexcept : Fd_(fd) { } - inline ~TPipeHandle() { + inline ~TPipeHandle() { Close(); } - bool Close() noexcept; + bool Close() noexcept; - inline PIPEHANDLE Release() noexcept { + inline PIPEHANDLE Release() noexcept { PIPEHANDLE ret = Fd_; Fd_ = INVALID_PIPEHANDLE; return ret; } - inline void Swap(TPipeHandle& r) noexcept { + inline void Swap(TPipeHandle& r) noexcept { DoSwap(Fd_, r.Fd_); } - inline operator PIPEHANDLE() const noexcept { + inline operator PIPEHANDLE() const noexcept { return Fd_; } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return Fd_ != INVALID_PIPEHANDLE; } - ssize_t Read(void* buffer, size_t byteCount) const noexcept; - ssize_t Write(const void* buffer, size_t byteCount) const noexcept; + ssize_t Read(void* buffer, size_t byteCount) const noexcept; + ssize_t Write(const void* buffer, size_t byteCount) const noexcept; // Only CloseOnExec is supported static void Pipe(TPipeHandle& reader, TPipeHandle& writer, EOpenMode mode = 0); @@ -66,12 +66,12 @@ public: TPipe(); /// Takes ownership of handle, so closes it when the last holder of descriptor dies. explicit TPipe(PIPEHANDLE fd); - ~TPipe(); + ~TPipe(); void Close(); - bool IsOpen() const noexcept; - PIPEHANDLE GetHandle() const noexcept; + bool IsOpen() const noexcept; + PIPEHANDLE GetHandle() const noexcept; size_t Read(void* buf, size_t len) const; size_t Write(const void* buf, size_t len) const; diff --git a/util/system/progname.cpp b/util/system/progname.cpp index 237f7e3082..2c29119320 100644 --- a/util/system/progname.cpp +++ b/util/system/progname.cpp @@ -13,11 +13,11 @@ namespace { { } - TString ProgName; + TString ProgName; }; } -const TString& GetProgramName() { +const TString& GetProgramName() { return Singleton<TProgramNameHolder>()->ProgName; } diff --git a/util/system/progname.h b/util/system/progname.h index b02cdf230d..e5e2a0eee2 100644 --- a/util/system/progname.h +++ b/util/system/progname.h @@ -9,5 +9,5 @@ void SetProgramName(const char* argv0); SetProgramName(argv[0]); \ } while (0) -/// guaranted return the same immutable instance of TString -const TString& GetProgramName(); +/// guaranted return the same immutable instance of TString +const TString& GetProgramName(); diff --git a/util/system/progname_ut.cpp b/util/system/progname_ut.cpp index d058647fac..11f3d9308b 100644 --- a/util/system/progname_ut.cpp +++ b/util/system/progname_ut.cpp @@ -4,11 +4,11 @@ Y_UNIT_TEST_SUITE(TProgramNameTest) { Y_UNIT_TEST(TestIt) { - TString progName = GetProgramName(); + TString progName = GetProgramName(); try { UNIT_ASSERT( - progName.find("ut_util") != TString::npos || progName.find("util-system_ut") != TString::npos || progName.find("util-system-ut") != TString::npos); + progName.find("ut_util") != TString::npos || progName.find("util-system_ut") != TString::npos || progName.find("util-system-ut") != TString::npos); } catch (...) { Cerr << progName << Endl; diff --git a/util/system/protect.cpp b/util/system/protect.cpp index 8786f00eab..bbb8d410df 100644 --- a/util/system/protect.cpp +++ b/util/system/protect.cpp @@ -1,7 +1,7 @@ #include "protect.h" #include <util/generic/yexception.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/stream/output.h> #include "yassert.h" @@ -15,7 +15,7 @@ #endif static TString ModeToString(const EProtectMemory mode) { - TString strMode; + TString strMode; if (mode == PM_NONE) { return "PM_NONE"; } diff --git a/util/system/rwlock.cpp b/util/system/rwlock.cpp index 8785f006d6..bb3dcbf188 100644 --- a/util/system/rwlock.cpp +++ b/util/system/rwlock.cpp @@ -14,17 +14,17 @@ class TRWMutex::TImpl { public: TImpl(); - ~TImpl(); + ~TImpl(); - void AcquireRead() noexcept; - bool TryAcquireRead() noexcept; - void ReleaseRead() noexcept; + void AcquireRead() noexcept; + bool TryAcquireRead() noexcept; + void ReleaseRead() noexcept; - void AcquireWrite() noexcept; - bool TryAcquireWrite() noexcept; - void ReleaseWrite() noexcept; + void AcquireWrite() noexcept; + bool TryAcquireWrite() noexcept; + void ReleaseWrite() noexcept; - void Release() noexcept; + void Release() noexcept; private: TMutex Lock_; @@ -40,12 +40,12 @@ TRWMutex::TImpl::TImpl() { } -TRWMutex::TImpl::~TImpl() { +TRWMutex::TImpl::~TImpl() { Y_VERIFY(State_ == 0, "failure, State_ != 0"); Y_VERIFY(BlockedWriters_ == 0, "failure, BlockedWriters_ != 0"); } -void TRWMutex::TImpl::AcquireRead() noexcept { +void TRWMutex::TImpl::AcquireRead() noexcept { with_lock (Lock_) { while (BlockedWriters_ || State_ < 0) { ReadCond_.Wait(Lock_); @@ -57,7 +57,7 @@ void TRWMutex::TImpl::AcquireRead() noexcept { ReadCond_.Signal(); } -bool TRWMutex::TImpl::TryAcquireRead() noexcept { +bool TRWMutex::TImpl::TryAcquireRead() noexcept { with_lock (Lock_) { if (BlockedWriters_ || State_ < 0) { return false; @@ -69,7 +69,7 @@ bool TRWMutex::TImpl::TryAcquireRead() noexcept { return true; } -void TRWMutex::TImpl::ReleaseRead() noexcept { +void TRWMutex::TImpl::ReleaseRead() noexcept { Lock_.Acquire(); if (--State_ > 0) { @@ -82,7 +82,7 @@ void TRWMutex::TImpl::ReleaseRead() noexcept { } } -void TRWMutex::TImpl::AcquireWrite() noexcept { +void TRWMutex::TImpl::AcquireWrite() noexcept { with_lock (Lock_) { while (State_ != 0) { ++BlockedWriters_; @@ -94,7 +94,7 @@ void TRWMutex::TImpl::AcquireWrite() noexcept { } } -bool TRWMutex::TImpl::TryAcquireWrite() noexcept { +bool TRWMutex::TImpl::TryAcquireWrite() noexcept { with_lock (Lock_) { if (State_ != 0) { return false; @@ -106,7 +106,7 @@ bool TRWMutex::TImpl::TryAcquireWrite() noexcept { return true; } -void TRWMutex::TImpl::ReleaseWrite() noexcept { +void TRWMutex::TImpl::ReleaseWrite() noexcept { Lock_.Acquire(); State_ = 0; @@ -119,7 +119,7 @@ void TRWMutex::TImpl::ReleaseWrite() noexcept { } } -void TRWMutex::TImpl::Release() noexcept { +void TRWMutex::TImpl::Release() noexcept { Lock_.Acquire(); if (State_ > 0) { @@ -147,17 +147,17 @@ void TRWMutex::TImpl::Release() noexcept { class TRWMutex::TImpl { public: TImpl(); - ~TImpl(); + ~TImpl(); - void AcquireRead() noexcept; - bool TryAcquireRead() noexcept; - void ReleaseRead() noexcept; + void AcquireRead() noexcept; + bool TryAcquireRead() noexcept; + void ReleaseRead() noexcept; - void AcquireWrite() noexcept; - bool TryAcquireWrite() noexcept; - void ReleaseWrite() noexcept; + void AcquireWrite() noexcept; + bool TryAcquireWrite() noexcept; + void ReleaseWrite() noexcept; - void Release() noexcept; + void Release() noexcept; private: pthread_rwlock_t Lock_; @@ -170,44 +170,44 @@ TRWMutex::TImpl::TImpl() { } } -TRWMutex::TImpl::~TImpl() { +TRWMutex::TImpl::~TImpl() { const int result = pthread_rwlock_destroy(&Lock_); Y_VERIFY(result == 0, "rwlock destroy failed (%s)", LastSystemErrorText(result)); } -void TRWMutex::TImpl::AcquireRead() noexcept { +void TRWMutex::TImpl::AcquireRead() noexcept { const int result = pthread_rwlock_rdlock(&Lock_); Y_VERIFY(result == 0, "rwlock rdlock failed (%s)", LastSystemErrorText(result)); } -bool TRWMutex::TImpl::TryAcquireRead() noexcept { +bool TRWMutex::TImpl::TryAcquireRead() noexcept { const int result = pthread_rwlock_tryrdlock(&Lock_); Y_VERIFY(result == 0 || result == EBUSY, "rwlock tryrdlock failed (%s)", LastSystemErrorText(result)); return result == 0; } -void TRWMutex::TImpl::ReleaseRead() noexcept { +void TRWMutex::TImpl::ReleaseRead() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock (read) unlock failed (%s)", LastSystemErrorText(result)); } -void TRWMutex::TImpl::AcquireWrite() noexcept { +void TRWMutex::TImpl::AcquireWrite() noexcept { const int result = pthread_rwlock_wrlock(&Lock_); Y_VERIFY(result == 0, "rwlock wrlock failed (%s)", LastSystemErrorText(result)); } -bool TRWMutex::TImpl::TryAcquireWrite() noexcept { +bool TRWMutex::TImpl::TryAcquireWrite() noexcept { const int result = pthread_rwlock_trywrlock(&Lock_); Y_VERIFY(result == 0 || result == EBUSY, "rwlock trywrlock failed (%s)", LastSystemErrorText(result)); return result == 0; } -void TRWMutex::TImpl::ReleaseWrite() noexcept { +void TRWMutex::TImpl::ReleaseWrite() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock (write) unlock failed (%s)", LastSystemErrorText(result)); } -void TRWMutex::TImpl::Release() noexcept { +void TRWMutex::TImpl::Release() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock unlock failed (%s)", LastSystemErrorText(result)); } @@ -221,30 +221,30 @@ TRWMutex::TRWMutex() TRWMutex::~TRWMutex() = default; -void TRWMutex::AcquireRead() noexcept { +void TRWMutex::AcquireRead() noexcept { Impl_->AcquireRead(); } -bool TRWMutex::TryAcquireRead() noexcept { +bool TRWMutex::TryAcquireRead() noexcept { return Impl_->TryAcquireRead(); } -void TRWMutex::ReleaseRead() noexcept { +void TRWMutex::ReleaseRead() noexcept { Impl_->ReleaseRead(); } -void TRWMutex::AcquireWrite() noexcept { +void TRWMutex::AcquireWrite() noexcept { Impl_->AcquireWrite(); } -bool TRWMutex::TryAcquireWrite() noexcept { +bool TRWMutex::TryAcquireWrite() noexcept { return Impl_->TryAcquireWrite(); } -void TRWMutex::ReleaseWrite() noexcept { +void TRWMutex::ReleaseWrite() noexcept { Impl_->ReleaseWrite(); } -void TRWMutex::Release() noexcept { +void TRWMutex::Release() noexcept { Impl_->Release(); } diff --git a/util/system/rwlock.h b/util/system/rwlock.h index b476837c92..0bb9b3fe1c 100644 --- a/util/system/rwlock.h +++ b/util/system/rwlock.h @@ -8,17 +8,17 @@ class TRWMutex { public: TRWMutex(); - ~TRWMutex(); + ~TRWMutex(); - void AcquireRead() noexcept; - bool TryAcquireRead() noexcept; - void ReleaseRead() noexcept; + void AcquireRead() noexcept; + bool TryAcquireRead() noexcept; + void ReleaseRead() noexcept; - void AcquireWrite() noexcept; - bool TryAcquireWrite() noexcept; - void ReleaseWrite() noexcept; + void AcquireWrite() noexcept; + bool TryAcquireWrite() noexcept; + void ReleaseWrite() noexcept; - void Release() noexcept; + void Release() noexcept; private: class TImpl; @@ -27,36 +27,36 @@ private: template <class T> struct TReadGuardOps { - static inline void Acquire(T* t) noexcept { + static inline void Acquire(T* t) noexcept { t->AcquireRead(); } - static inline void Release(T* t) noexcept { + static inline void Release(T* t) noexcept { t->ReleaseRead(); } }; template <class T> struct TTryReadGuardOps: public TReadGuardOps<T> { - static inline bool TryAcquire(T* t) noexcept { + static inline bool TryAcquire(T* t) noexcept { return t->TryAcquireRead(); } }; template <class T> struct TWriteGuardOps { - static inline void Acquire(T* t) noexcept { + static inline void Acquire(T* t) noexcept { t->AcquireWrite(); } - static inline void Release(T* t) noexcept { + static inline void Release(T* t) noexcept { t->ReleaseWrite(); } }; template <class T> struct TTryWriteGuardOps: public TWriteGuardOps<T> { - static inline bool TryAcquire(T* t) noexcept { + static inline bool TryAcquire(T* t) noexcept { return t->TryAcquireWrite(); } }; diff --git a/util/system/sem.cpp b/util/system/sem.cpp index 885ad8a255..4a93b903b5 100644 --- a/util/system/sem.cpp +++ b/util/system/sem.cpp @@ -104,7 +104,7 @@ namespace { #endif } - inline ~TSemaphoreImpl() { + inline ~TSemaphoreImpl() { #ifdef _win_ ::CloseHandle(Handle); #else @@ -119,7 +119,7 @@ namespace { #endif } - inline void Release() noexcept { + inline void Release() noexcept { #ifdef _win_ ::ReleaseSemaphore(Handle, 1, 0); #else @@ -135,7 +135,7 @@ namespace { //The UNIX semaphore object does not support a timed "wait", and //hence to maintain consistancy, for win32 case we use INFINITE or 0 timeout. - inline void Acquire() noexcept { + inline void Acquire() noexcept { #ifdef _win_ Y_VERIFY(::WaitForSingleObject(Handle, INFINITE) == WAIT_OBJECT_0, "can not acquire semaphore"); #else @@ -149,7 +149,7 @@ namespace { #endif } - inline bool TryAcquire() noexcept { + inline bool TryAcquire() noexcept { #ifdef _win_ // zero-second time-out interval // WAIT_OBJECT_0: current free count > 0 @@ -169,8 +169,8 @@ namespace { #if defined(_unix_) /* - Disable errors/warnings about deprecated sem_* in Darwin -*/ + Disable errors/warnings about deprecated sem_* in Darwin +*/ #ifdef _darwin_ Y_PRAGMA_DIAGNOSTIC_PUSH Y_PRAGMA_NO_DEPRECATED @@ -182,19 +182,19 @@ namespace { } } - inline ~TPosixSemaphore() { + inline ~TPosixSemaphore() { Y_VERIFY(sem_destroy(&S_) == 0, "semaphore destroy failed"); } - inline void Acquire() noexcept { + inline void Acquire() noexcept { Y_VERIFY(sem_wait(&S_) == 0, "semaphore acquire failed"); } - inline void Release() noexcept { + inline void Release() noexcept { Y_VERIFY(sem_post(&S_) == 0, "semaphore release failed"); } - inline bool TryAcquire() noexcept { + inline bool TryAcquire() noexcept { if (sem_trywait(&S_)) { Y_VERIFY(errno == EAGAIN, "semaphore try wait failed"); @@ -227,15 +227,15 @@ TSemaphore::TSemaphore(const char* name, ui32 maxFreeCount) TSemaphore::~TSemaphore() = default; -void TSemaphore::Release() noexcept { +void TSemaphore::Release() noexcept { Impl_->Release(); } -void TSemaphore::Acquire() noexcept { +void TSemaphore::Acquire() noexcept { Impl_->Acquire(); } -bool TSemaphore::TryAcquire() noexcept { +bool TSemaphore::TryAcquire() noexcept { return Impl_->TryAcquire(); } @@ -248,10 +248,10 @@ public: } }; #else -class TFastSemaphore::TImpl: public TString, public TSemaphoreImpl { +class TFastSemaphore::TImpl: public TString, public TSemaphoreImpl { public: inline TImpl(ui32 n) - : TString(ToString(RandomNumber<ui64>())) + : TString(ToString(RandomNumber<ui64>())) , TSemaphoreImpl(c_str(), n) { } @@ -265,14 +265,14 @@ TFastSemaphore::TFastSemaphore(ui32 maxFreeCount) TFastSemaphore::~TFastSemaphore() = default; -void TFastSemaphore::Release() noexcept { +void TFastSemaphore::Release() noexcept { Impl_->Release(); } -void TFastSemaphore::Acquire() noexcept { +void TFastSemaphore::Acquire() noexcept { Impl_->Acquire(); } -bool TFastSemaphore::TryAcquire() noexcept { +bool TFastSemaphore::TryAcquire() noexcept { return Impl_->TryAcquire(); } diff --git a/util/system/sem.h b/util/system/sem.h index 2dbc5e3db9..0c964ad6b6 100644 --- a/util/system/sem.h +++ b/util/system/sem.h @@ -8,17 +8,17 @@ class TSemaphore { public: TSemaphore(const char* name, ui32 maxFreeCount); - ~TSemaphore(); + ~TSemaphore(); //Increase the semaphore counter. - void Release() noexcept; + void Release() noexcept; //Keep a thread held while the semaphore counter is equal 0. - void Acquire() noexcept; + void Acquire() noexcept; //Try to enter the semaphore gate. A non-blocking variant of Acquire. //Returns 'true' if the semaphore counter decreased - bool TryAcquire() noexcept; + bool TryAcquire() noexcept; private: class TImpl; @@ -29,11 +29,11 @@ private: class TFastSemaphore { public: TFastSemaphore(ui32 maxFreeCount); - ~TFastSemaphore(); + ~TFastSemaphore(); - void Release() noexcept; - void Acquire() noexcept; - bool TryAcquire() noexcept; + void Release() noexcept; + void Acquire() noexcept; + bool TryAcquire() noexcept; private: class TImpl; diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index e8da24f7ef..b1989b5c8c 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -115,21 +115,21 @@ using REALPIPEHANDLE = HANDLE; class TRealPipeHandle : public TNonCopyable { public: - inline TRealPipeHandle() noexcept + inline TRealPipeHandle() noexcept : Fd_(INVALID_REALPIPEHANDLE) { } - inline TRealPipeHandle(REALPIPEHANDLE fd) noexcept + inline TRealPipeHandle(REALPIPEHANDLE fd) noexcept : Fd_(fd) { } - inline ~TRealPipeHandle() { + inline ~TRealPipeHandle() { Close(); } - bool Close() noexcept { + bool Close() noexcept { bool ok = true; if (Fd_ != INVALID_REALPIPEHANDLE) ok = CloseHandle(Fd_); @@ -137,31 +137,31 @@ public: return ok; } - inline REALPIPEHANDLE Release() noexcept { + inline REALPIPEHANDLE Release() noexcept { REALPIPEHANDLE ret = Fd_; Fd_ = INVALID_REALPIPEHANDLE; return ret; } - inline void Swap(TRealPipeHandle& r) noexcept { + inline void Swap(TRealPipeHandle& r) noexcept { DoSwap(Fd_, r.Fd_); } - inline operator REALPIPEHANDLE() const noexcept { + inline operator REALPIPEHANDLE() const noexcept { return Fd_; } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return Fd_ != INVALID_REALPIPEHANDLE; } - ssize_t Read(void* buffer, size_t byteCount) const noexcept { + ssize_t Read(void* buffer, size_t byteCount) const noexcept { DWORD doneBytes; if (!ReadFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) return -1; return doneBytes; } - ssize_t Write(const void* buffer, size_t byteCount) const noexcept { + ssize_t Write(const void* buffer, size_t byteCount) const noexcept { DWORD doneBytes; if (!WriteFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) return -1; @@ -191,17 +191,17 @@ class TShellCommand::TImpl : public TAtomicRefCount<TShellCommand::TImpl> { private: TPid Pid; - TString Command; - TList<TString> Arguments; - TString WorkDir; + TString Command; + TList<TString> Arguments; + TString WorkDir; TAtomic ExecutionStatus; // TShellCommand::ECommandStatus TMaybe<int> ExitCode; IInputStream* InputStream; IOutputStream* OutputStream; IOutputStream* ErrorStream; - TString CollectedOutput; - TString CollectedError; - TString InternalError; + TString CollectedOutput; + TString CollectedError; + TString InternalError; TThread* WatchThread; TMutex TerminateMutex; TFileHandle InputHandle; @@ -224,7 +224,7 @@ private: TShellCommandOptions::EHandleMode ErrorMode = TShellCommandOptions::HANDLE_STREAM; TShellCommandOptions::TUserOptions User; - THashMap<TString, TString> Environment; + THashMap<TString, TString> Environment; int Nice = 0; std::function<void()> FuncAfterFork = {}; @@ -280,7 +280,7 @@ private: #endif public: - inline TImpl(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options, const TString& workdir) + inline TImpl(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options, const TString& workdir) : Pid(0) , Command(ToString(cmd)) , Arguments(args) @@ -337,21 +337,21 @@ public: Arguments.push_back(ToString(argument)); } - inline const TString& GetOutput() const { + inline const TString& GetOutput() const { if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { ythrow yexception() << "You cannot retrieve output while process is running."; } return CollectedOutput; } - inline const TString& GetError() const { + inline const TString& GetError() const { if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { ythrow yexception() << "You cannot retrieve output while process is running."; } return CollectedError; } - inline const TString& GetInternalError() const { + inline const TString& GetInternalError() const { if (AtomicGet(ExecutionStatus) != SHELL_INTERNAL_ERROR) { ythrow yexception() << "Internal error hasn't occured so can't be retrieved."; } @@ -555,10 +555,10 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { } PROCESS_INFORMATION process_info; - // TString cmd = "cmd /U" + TUtf16String can be used to read unicode messages from cmd + // TString cmd = "cmd /U" + TUtf16String can be used to read unicode messages from cmd // /A - ansi charset /Q - echo off, /C - command, /Q - special quotes - TString qcmd = GetQuotedCommand(); - TString cmd = UseShell ? "cmd /A /Q /S /C \"" + qcmd + "\"" : qcmd; + TString qcmd = GetQuotedCommand(); + TString cmd = UseShell ? "cmd /A /Q /S /C \"" + qcmd + "\"" : qcmd; // winapi can modify command text, copy it Y_ENSURE_EX(cmd.size() < MAX_COMMAND_LINE, yexception() << "Command is too long (length=" << cmd.size() << ")"); @@ -574,7 +574,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { } void* lpEnvironment = nullptr; - TString env; + TString env; if (!Environment.empty()) { for (auto e = Environment.begin(); e != Environment.end(); ++e) { env += e->first + '=' + e->second + '\0'; @@ -627,21 +627,21 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { } #endif -void ShellQuoteArg(TString& dst, TStringBuf argument) { +void ShellQuoteArg(TString& dst, TStringBuf argument) { dst.append("\""); TStringBuf l, r; - while (argument.TrySplit('"', l, r)) { + while (argument.TrySplit('"', l, r)) { dst.append(l); dst.append("\\\""); - argument = r; + argument = r; } - dst.append(argument); + dst.append(argument); dst.append("\""); } -void ShellQuoteArgSp(TString& dst, TStringBuf argument) { +void ShellQuoteArgSp(TString& dst, TStringBuf argument) { dst.append(' '); - ShellQuoteArg(dst, argument); + ShellQuoteArg(dst, argument); } bool ArgNeedsQuotes(TStringBuf arg) noexcept { @@ -651,8 +651,8 @@ bool ArgNeedsQuotes(TStringBuf arg) noexcept { return arg.find_first_of(" \"\'\t&()*<>\\`^|") != TString::npos; } -TString TShellCommand::TImpl::GetQuotedCommand() const { - TString quoted = Command; /// @todo command itself should be quoted too +TString TShellCommand::TImpl::GetQuotedCommand() const { + TString quoted = Command; /// @todo command itself should be quoted too for (const auto& argument : Arguments) { // Don't add unnecessary quotes. It's especially important for the windows with a 32k command line length limit. if (QuoteArguments && ArgNeedsQuotes(argument)) { @@ -783,8 +783,8 @@ void TShellCommand::TImpl::Run() { } /* arguments holders */ - TString shellArg; - TVector<char*> qargv; + TString shellArg; + TVector<char*> qargv; /* Following "const_cast"s are safe: http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html @@ -807,8 +807,8 @@ void TShellCommand::TImpl::Run() { qargv.push_back(nullptr); - TVector<TString> envHolder; - TVector<char*> envp; + TVector<TString> envHolder; + TVector<char*> envp; if (!Environment.empty()) { for (auto& env : Environment) { envHolder.emplace_back(env.first + '=' + env.second); @@ -1121,14 +1121,14 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { TerminateIsRequired(pi); } -TShellCommand::TShellCommand(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options, - const TString& workdir) +TShellCommand::TShellCommand(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options, + const TString& workdir) : Impl(new TImpl(cmd, args, options, workdir)) { } -TShellCommand::TShellCommand(const TStringBuf cmd, const TShellCommandOptions& options, const TString& workdir) - : Impl(new TImpl(cmd, TList<TString>(), options, workdir)) +TShellCommand::TShellCommand(const TStringBuf cmd, const TShellCommandOptions& options, const TString& workdir) + : Impl(new TImpl(cmd, TList<TString>(), options, workdir)) { } @@ -1139,15 +1139,15 @@ TShellCommand& TShellCommand::operator<<(const TStringBuf argument) { return *this; } -const TString& TShellCommand::GetOutput() const { +const TString& TShellCommand::GetOutput() const { return Impl->GetOutput(); } -const TString& TShellCommand::GetError() const { +const TString& TShellCommand::GetError() const { return Impl->GetError(); } -const TString& TShellCommand::GetInternalError() const { +const TString& TShellCommand::GetInternalError() const { return Impl->GetInternalError(); } diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index c2e7a4701c..8730627fe5 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/noncopyable.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/list.h> #include <util/generic/hash.h> #include <util/generic/strbuf.h> @@ -17,9 +17,9 @@ class TShellCommandOptions { public: struct TUserOptions { - TString Name; + TString Name; #if defined(_win_) - TString Password; + TString Password; #endif #if defined(_unix_) /** @@ -38,7 +38,7 @@ public: }; public: - inline TShellCommandOptions() noexcept + inline TShellCommandOptions() noexcept : ClearSignalMask(false) , CloseAllFdsOnExec(false) , AsyncMode(false) @@ -59,7 +59,7 @@ public: { } - inline TShellCommandOptions& SetNice(int value) noexcept { + inline TShellCommandOptions& SetNice(int value) noexcept { Nice = value; return *this; @@ -318,7 +318,7 @@ public: IOutputStream* OutputStream; IOutputStream* ErrorStream; TUserOptions User; - THashMap<TString, TString> Environment; + THashMap<TString, TString> Environment; int Nice = 0; static const size_t DefaultSyncPollDelay = 1000; // ms @@ -351,10 +351,10 @@ public: * @param options execution options * @todo store entire options structure */ - TShellCommand(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options = TShellCommandOptions(), - const TString& workdir = TString()); - TShellCommand(const TStringBuf cmd, const TShellCommandOptions& options = TShellCommandOptions(), const TString& workdir = TString()); - ~TShellCommand(); + TShellCommand(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options = TShellCommandOptions(), + const TString& workdir = TString()); + TShellCommand(const TStringBuf cmd, const TShellCommandOptions& options = TShellCommandOptions(), const TString& workdir = TString()); + ~TShellCommand(); public: /** @@ -372,7 +372,7 @@ public: * * @return collected output */ - const TString& GetOutput() const; + const TString& GetOutput() const; /** * @brief return the collected error output from the command. @@ -380,7 +380,7 @@ public: * * @return collected error output */ - const TString& GetError() const; + const TString& GetError() const; /** * @brief return the internal error occured while watching @@ -389,7 +389,7 @@ public: * * @return error text */ - const TString& GetInternalError() const; + const TString& GetInternalError() const; /** * @brief get current status of command execution @@ -476,10 +476,10 @@ private: }; /// Appends to dst: quoted arg -void ShellQuoteArg(TString& dst, TStringBuf arg); +void ShellQuoteArg(TString& dst, TStringBuf arg); /// Appends to dst: space, quoted arg -void ShellQuoteArgSp(TString& dst, TStringBuf arg); +void ShellQuoteArgSp(TString& dst, TStringBuf arg); /// Returns true if arg should be quoted bool ArgNeedsQuotes(TStringBuf arg) noexcept; diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 71dd2f2e4d..9d849279d2 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -33,11 +33,11 @@ public: Stream_.Reserve(100); } - TString Str() const { + TString Str() const { with_lock (Lock_) { return Stream_.Str(); } - return TString(); // line for compiler + return TString(); // line for compiler } protected: @@ -61,7 +61,7 @@ private: Y_UNIT_TEST_SUITE(TShellQuoteTest) { Y_UNIT_TEST(TestQuoteArg) { - TString cmd; + TString cmd; ShellQuoteArg(cmd, "/pr f/krev/prev.exe"); ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\""); ShellQuoteArgSp(cmd, "-DVal=W Space"); @@ -170,8 +170,8 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { } Y_UNIT_TEST(TestQuotes) { TShellCommandOptions options; - TString input = TString("a\"a a"); - TString output; + TString input = TString("a\"a a"); + TString output; TStringOutput outputStream(output); options.SetOutputStream(&outputStream); TShellCommand cmd("echo", options); @@ -202,7 +202,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { // 'type con' and 'copy con con' want real console, not stdin, use sort Y_UNIT_TEST(TestInput) { TShellCommandOptions options; - TString input = (TString("a") * 2000).append(NL) * textSize; + TString input = (TString("a") * 2000).append(NL) * textSize; TStringInput inputStream(input); options.SetInputStream(&inputStream); TShellCommand cmd(catCommand, options); @@ -212,10 +212,10 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { } Y_UNIT_TEST(TestOutput) { TShellCommandOptions options; - TString input = (TString("a") * 2000).append(NL) * textSize; + TString input = (TString("a") * 2000).append(NL) * textSize; TStringInput inputStream(input); options.SetInputStream(&inputStream); - TString output; + TString output; TStringOutput outputStream(output); options.SetOutputStream(&outputStream); TShellCommand cmd(catCommand, options); @@ -297,7 +297,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { #if !defined(_win_) // this ut is unix-only, port to win using %TEMP% Y_UNIT_TEST(TestInterrupt) { - TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); + TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); TShellCommandOptions options; options.SetAsync(true); @@ -327,7 +327,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { rc = SigProcMask(SIG_SETMASK, &newmask, &oldmask); UNIT_ASSERT(rc == 0); - TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); + TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); TShellCommandOptions options; options.SetAsync(true); @@ -381,7 +381,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { } #endif Y_UNIT_TEST(TestInternalError) { - TString input = (TString("a") * 2000).append("\n"); + TString input = (TString("a") * 2000).append("\n"); TStringInput inputStream(input); TMemoryOutput outputStream(nullptr, 0); TShellCommandOptions options; diff --git a/util/system/spin_wait.cpp b/util/system/spin_wait.cpp index c2281a111d..e27045e74f 100644 --- a/util/system/spin_wait.cpp +++ b/util/system/spin_wait.cpp @@ -8,7 +8,7 @@ #include <util/generic/utility.h> template <class T> -static inline T RandomizeSleepTime(T t) noexcept { +static inline T RandomizeSleepTime(T t) noexcept { static TAtomic counter = 0; const T rndNum = IntHash((T)AtomicIncrement(counter)); diff --git a/util/system/spinlock.h b/util/system/spinlock.h index 85d8a281b8..af2630890a 100644 --- a/util/system/spinlock.h +++ b/util/system/spinlock.h @@ -14,7 +14,7 @@ public: return AtomicGet(Val_); } - inline bool TryAcquire() noexcept { + inline bool TryAcquire() noexcept { return AtomicTryLock(&Val_); } @@ -56,11 +56,11 @@ class TSpinLock: public TSpinLockBase { public: using TSpinLockBase::TSpinLockBase; - inline void Release() noexcept { + inline void Release() noexcept { ReleaseSpinLock(&Val_); } - inline void Acquire() noexcept { + inline void Acquire() noexcept { AcquireSpinLock(&Val_); } @@ -91,11 +91,11 @@ class TAdaptiveLock: public TSpinLockBase { public: using TSpinLockBase::TSpinLockBase; - inline void Release() noexcept { + inline void Release() noexcept { ReleaseAdaptiveLock(&Val_); } - inline void Acquire() noexcept { + inline void Acquire() noexcept { AcquireAdaptiveLock(&Val_); } @@ -112,15 +112,15 @@ public: template <> struct TCommonLockOps<TAtomic> { - static inline void Acquire(TAtomic* v) noexcept { + static inline void Acquire(TAtomic* v) noexcept { AcquireAdaptiveLock(v); } - static inline bool TryAcquire(TAtomic* v) noexcept { + static inline bool TryAcquire(TAtomic* v) noexcept { return AtomicTryLock(v); } - static inline void Release(TAtomic* v) noexcept { + static inline void Release(TAtomic* v) noexcept { ReleaseAdaptiveLock(v); } }; diff --git a/util/system/src_location.cpp b/util/system/src_location.cpp index 2d051f7be6..13ff1f24b3 100644 --- a/util/system/src_location.cpp +++ b/util/system/src_location.cpp @@ -7,7 +7,7 @@ template <> void Out<TSourceLocation>(IOutputStream& o, const TSourceLocation& t) { #if defined(_win_) - TString file(t.File); + TString file(t.File); std::replace(file.begin(), file.vend(), '\\', '/'); o << file; #else diff --git a/util/system/src_location_ut.cpp b/util/system/src_location_ut.cpp index 6924ce35b1..5b86cb86ef 100644 --- a/util/system/src_location_ut.cpp +++ b/util/system/src_location_ut.cpp @@ -4,7 +4,7 @@ #include <library/cpp/testing/unittest/registar.h> -static inline TString GenLoc() { +static inline TString GenLoc() { return TStringBuilder() << __LOCATION__; } diff --git a/util/system/src_root_ut.cpp b/util/system/src_root_ut.cpp index 30f3520eda..e9a675eb9a 100644 --- a/util/system/src_root_ut.cpp +++ b/util/system/src_root_ut.cpp @@ -6,7 +6,7 @@ Y_UNIT_TEST_SUITE(TestSourceRoot) { Y_UNIT_TEST(TestStrip) { // Reconstruct() converts "\" -> "/" on Windows - const TString path = TPathSplit(__SOURCE_FILE_IMPL__.As<TStringBuf>()).Reconstruct(); + const TString path = TPathSplit(__SOURCE_FILE_IMPL__.As<TStringBuf>()).Reconstruct(); UNIT_ASSERT_EQUAL(path, "util" LOCSLASH_S "system" LOCSLASH_S "src_root_ut.cpp"); } diff --git a/util/system/tempfile.cpp b/util/system/tempfile.cpp index 0e3e461102..a2e9f49eb1 100644 --- a/util/system/tempfile.cpp +++ b/util/system/tempfile.cpp @@ -6,7 +6,7 @@ TTempFileHandle::TTempFileHandle() { } -TTempFileHandle::TTempFileHandle(const TString& fname) +TTempFileHandle::TTempFileHandle(const TString& fname) : TTempFile(fname) , TFile(CreateFile()) { diff --git a/util/system/tempfile.h b/util/system/tempfile.h index e20f792371..de249c129d 100644 --- a/util/system/tempfile.h +++ b/util/system/tempfile.h @@ -4,31 +4,31 @@ #include "file.h" #include <util/folder/path.h> -#include <util/generic/string.h> +#include <util/generic/string.h> class TTempFile { public: - inline TTempFile(const TString& fname) + inline TTempFile(const TString& fname) : Name_(fname) { } - inline ~TTempFile() { + inline ~TTempFile() { NFs::Remove(Name()); } - inline const TString& Name() const noexcept { + inline const TString& Name() const noexcept { return Name_; } private: - const TString Name_; + const TString Name_; }; class TTempFileHandle: public TTempFile, public TFile { public: TTempFileHandle(); - TTempFileHandle(const TString& fname); + TTempFileHandle(const TString& fname); static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp"); static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp"); diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp index b5523fa788..e4a0923d0b 100644 --- a/util/system/tempfile_ut.cpp +++ b/util/system/tempfile_ut.cpp @@ -10,13 +10,13 @@ Y_UNIT_TEST_SUITE(TTempFileHandle) { Y_UNIT_TEST(Create) { - TString path; + TString path; { TTempFileHandle tmp; path = tmp.Name(); tmp.Write("hello world\n", 12); tmp.FlushData(); - UNIT_ASSERT_STRINGS_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "hello world\n"); + UNIT_ASSERT_STRINGS_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "hello world\n"); } UNIT_ASSERT(!NFs::Exists(path)); } diff --git a/util/system/thread.cpp b/util/system/thread.cpp index e9cb938302..6236746c2d 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -51,7 +51,7 @@ namespace { } } - inline size_t StackSize(const TParams& p) noexcept { + inline size_t StackSize(const TParams& p) noexcept { if (p.StackSize) { return FastClp2(p.StackSize); } @@ -83,11 +83,11 @@ namespace { { } - inline bool Running() const noexcept { + inline bool Running() const noexcept { return Handle != 0; } - inline TId SystemThreadId() const noexcept { + inline TId SystemThreadId() const noexcept { #if _WIN32_WINNT < 0x0502 return (TId)ThreadId; #else @@ -168,7 +168,7 @@ namespace { static_assert(sizeof(H_) == sizeof(TId), "expect sizeof(H_) == sizeof(TId)"); } - inline TId SystemThreadId() const noexcept { + inline TId SystemThreadId() const noexcept { return (TId)H_; } @@ -183,7 +183,7 @@ namespace { PCHECK(pthread_detach(H_), "can not detach thread"); } - inline bool Running() const noexcept { + inline bool Running() const noexcept { return (bool)H_; } @@ -257,7 +257,7 @@ public: { } - inline TId Id() const noexcept { + inline TId Id() const noexcept { return ThreadIdHashFunction(SystemThreadId()); } @@ -285,7 +285,7 @@ TThread::TThread(TPrivateCtor, THolder<TCallableBase> callable) { } -TThread::~TThread() { +TThread::~TThread() { Join(); } @@ -312,11 +312,11 @@ void TThread::Detach() { } } -bool TThread::Running() const noexcept { +bool TThread::Running() const noexcept { return Impl_ && Impl_->Running(); } -TThread::TId TThread::Id() const noexcept { +TThread::TId TThread::Id() const noexcept { if (Running()) { return Impl_->Id(); } @@ -324,7 +324,7 @@ TThread::TId TThread::Id() const noexcept { return ImpossibleThreadId(); } -TThread::TId TThread::CurrentThreadId() noexcept { +TThread::TId TThread::CurrentThreadId() noexcept { return SystemCurrentThreadId(); } @@ -352,7 +352,7 @@ TThread::TId TThread::CurrentThreadNumericId() noexcept { #endif } -TThread::TId TThread::ImpossibleThreadId() noexcept { +TThread::TId TThread::ImpossibleThreadId() noexcept { return Max<TThread::TId>(); } diff --git a/util/system/thread.h b/util/system/thread.h index 5702b549fa..a6e8abdb5b 100644 --- a/util/system/thread.h +++ b/util/system/thread.h @@ -5,7 +5,7 @@ /// @see SystemThreadFactory() #include <util/generic/ptr.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include "defaults.h" #include "progname.h" @@ -53,19 +53,19 @@ public: { } - inline TParams& SetName(const TString& name) noexcept { + inline TParams& SetName(const TString& name) noexcept { Name = name; return *this; } - inline TParams& SetStackSize(size_t size) noexcept { + inline TParams& SetStackSize(size_t size) noexcept { StackSize = size; return *this; } - inline TParams& SetStackPointer(void* ptr) noexcept { + inline TParams& SetStackPointer(void* ptr) noexcept { StackPointer = ptr; return *this; @@ -92,17 +92,17 @@ public: { } - ~TThread(); + ~TThread(); void Start(); void* Join(); void Detach(); - bool Running() const noexcept; - TId Id() const noexcept; + bool Running() const noexcept; + TId Id() const noexcept; - static TId ImpossibleThreadId() noexcept; - static TId CurrentThreadId() noexcept; + static TId ImpossibleThreadId() noexcept; + static TId CurrentThreadId() noexcept; /* * Returns numeric thread id, as visible in e. g. htop. diff --git a/util/system/thread.i b/util/system/thread.i index 086befc238..8cba505473 100644 --- a/util/system/thread.i +++ b/util/system/thread.i @@ -24,7 +24,7 @@ #include <util/digest/numeric.h> -static inline size_t SystemCurrentThreadIdImpl() noexcept { +static inline size_t SystemCurrentThreadIdImpl() noexcept { #if defined(_unix_) return (size_t)pthread_self(); #elif defined(_win_) @@ -35,7 +35,7 @@ static inline size_t SystemCurrentThreadIdImpl() noexcept { } template <class T> -static inline T ThreadIdHashFunction(T t) noexcept { +static inline T ThreadIdHashFunction(T t) noexcept { /* * we must permute threadid bits, because some strange platforms(such Linux) * have strange threadid numeric properties @@ -47,6 +47,6 @@ static inline T ThreadIdHashFunction(T t) noexcept { return IntHash(t); } -static inline size_t SystemCurrentThreadId() noexcept { +static inline size_t SystemCurrentThreadId() noexcept { return ThreadIdHashFunction(SystemCurrentThreadIdImpl()); } diff --git a/util/system/tls.cpp b/util/system/tls.cpp index 9fdafc5b54..c2f1a04a14 100644 --- a/util/system/tls.cpp +++ b/util/system/tls.cpp @@ -6,7 +6,7 @@ #include <util/generic/hash.h> #include <util/generic/intrlist.h> #include <util/generic/singleton.h> -#include <util/generic/vector.h> +#include <util/generic/vector.h> #if defined(_unix_) #include <pthread.h> @@ -46,17 +46,17 @@ namespace { { } - inline ~TStoredValue() { + inline ~TStoredValue() { if (Dtor_ && Data_) { Dtor_(Data_); } } - inline void Set(void* ptr) noexcept { + inline void Set(void* ptr) noexcept { Data_ = ptr; } - inline void* Get() const noexcept { + inline void* Get() const noexcept { return Data_; } @@ -92,8 +92,8 @@ namespace { } private: - TVector<TStoredValue*> Values_; - THashMap<size_t, TStoredValue*> FarValues_; + TVector<TStoredValue*> Values_; + THashMap<size_t, TStoredValue*> FarValues_; TIntrusiveListWithAutoDelete<TStoredValue, TDelete> Storage_; }; @@ -126,7 +126,7 @@ namespace { Y_VERIFY(!pthread_key_create(&Key_, Dtor), "pthread_key_create failed"); } - inline ~TMasterTls() override { + inline ~TMasterTls() override { //explicitly call dtor for main thread Dtor(pthread_getspecific(Key_)); @@ -197,7 +197,7 @@ namespace { } } - inline void Cleanup() noexcept { + inline void Cleanup() noexcept { with_lock (Lock_) { Datas_.erase(TThread::CurrentThreadId()); } @@ -210,7 +210,7 @@ namespace { private: using TPTSRef = THolder<TPerThreadStorage>; TMutex Lock_; - THashMap<TThread::TId, TPTSRef> Datas_; + THashMap<TThread::TId, TPTSRef> Datas_; }; } @@ -255,6 +255,6 @@ void TKey::Set(void* ptr) const { Impl_->Set(ptr); } -void TKey::Cleanup() noexcept { +void TKey::Cleanup() noexcept { TImpl::Cleanup(); } diff --git a/util/system/tls.h b/util/system/tls.h index 29b5e1994b..3c4f56dbeb 100644 --- a/util/system/tls.h +++ b/util/system/tls.h @@ -158,12 +158,12 @@ namespace NTls { public: TKey(TDtor dtor); TKey(TKey&&) noexcept; - ~TKey(); + ~TKey(); void* Get() const; void Set(void* ptr) const; - static void Cleanup() noexcept; + static void Cleanup() noexcept; private: class TImpl; @@ -171,7 +171,7 @@ namespace NTls { }; struct TCleaner { - inline ~TCleaner() { + inline ~TCleaner() { TKey::Cleanup(); } }; @@ -292,16 +292,16 @@ namespace NTls { } template <class T> -static inline T& TlsRef(NTls::TValue<T>& v) noexcept { +static inline T& TlsRef(NTls::TValue<T>& v) noexcept { return v; } template <class T> -static inline const T& TlsRef(const NTls::TValue<T>& v) noexcept { +static inline const T& TlsRef(const NTls::TValue<T>& v) noexcept { return v; } template <class T> -static inline T& TlsRef(T& v) noexcept { +static inline T& TlsRef(T& v) noexcept { return v; } diff --git a/util/system/tls_ut.cpp b/util/system/tls_ut.cpp index ad3db72a12..e84d34b42a 100644 --- a/util/system/tls_ut.cpp +++ b/util/system/tls_ut.cpp @@ -31,7 +31,7 @@ Y_UNIT_TEST_SUITE(TTestTLS) { { } - void* ThreadProc() noexcept override { + void* ThreadProc() noexcept override { for (size_t i = 0; i < 100000; ++i) { P[i].Do(); } diff --git a/util/system/type_name.h b/util/system/type_name.h index 76997db26f..b6619aba3f 100644 --- a/util/system/type_name.h +++ b/util/system/type_name.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/string/subst.h> #include <typeindex> diff --git a/util/system/user.cpp b/util/system/user.cpp index ac6772f458..83e89ea0a8 100644 --- a/util/system/user.cpp +++ b/util/system/user.cpp @@ -13,7 +13,7 @@ #include <unistd.h> #endif -TString GetUsername() { +TString GetUsername() { for (const auto& var : {"LOGNAME", "USER", "LNAME", "USERNAME"}) { TString val = GetEnv(var); if (val) { @@ -32,13 +32,13 @@ TString GetUsername() { else ythrow TSystemError(err) << " GetUserName failed"; } else { - return TString(nameBuf.Data(), (size_t)(len - 1)); + return TString(nameBuf.Data(), (size_t)(len - 1)); } #elif defined(_bionic_) const passwd* pwd = getpwuid(geteuid()); if (pwd) { - return TString(pwd->pw_name); + return TString(pwd->pw_name); } ythrow TSystemError() << TStringBuf(" getpwuid failed"); diff --git a/util/system/user.h b/util/system/user.h index 6d02d7ca48..be348d1cee 100644 --- a/util/system/user.h +++ b/util/system/user.h @@ -2,4 +2,4 @@ #include <util/generic/fwd.h> -TString GetUsername(); +TString GetUsername(); diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index dc64badf1b..127e7c261e 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -30,7 +30,7 @@ SRCS( system/backtrace_ut.cpp system/byteorder_ut.cpp system/compat_ut.cpp - system/compiler_ut.cpp + system/compiler_ut.cpp system/context_ut.cpp system/condvar_ut.cpp system/cpu_id_ut.cpp @@ -66,7 +66,7 @@ SRCS( system/spinlock_ut.cpp system/src_root_ut.cpp system/src_location_ut.cpp - system/shmat_ut.cpp + system/shmat_ut.cpp system/tempfile_ut.cpp system/thread_ut.cpp system/tls_ut.cpp diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp index cb006eec70..0f586648b7 100644 --- a/util/system/yassert.cpp +++ b/util/system/yassert.cpp @@ -8,7 +8,7 @@ #include <util/datetime/base.h> #include <util/generic/singleton.h> #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/stream/output.h> #include <util/stream/str.h> #include <util/string/printf.h> @@ -38,13 +38,13 @@ namespace NPrivate { [[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept; } -void ::NPrivate::Panic(const TStaticBuf& file, int line, const char* function, const char* expr, const char* format, ...) noexcept { +void ::NPrivate::Panic(const TStaticBuf& file, int line, const char* function, const char* expr, const char* format, ...) noexcept { try { // We care of panic of first failed thread only // Otherwise stderr could contain multiple messages and stack traces shuffled auto guard = Guard(*Singleton<TPanicLockHolder>()); - TString errorMsg; + TString errorMsg; va_list args; va_start(args, format); // format has " " prefix to mute GCC warning on empty format @@ -65,7 +65,7 @@ namespace NPrivate { TStringBuf errorMsg{errorMessage, errorMessageSize}; const TString now = TInstant::Now().ToStringLocal(); - TString r; + TString r; TStringOutput o(r); if (expr) { o << "VERIFY failed (" << now << "): " << errorMsg << Endl; diff --git a/util/system/yield.cpp b/util/system/yield.cpp index 0da3c2f573..b327b37b1a 100644 --- a/util/system/yield.cpp +++ b/util/system/yield.cpp @@ -8,7 +8,7 @@ #include <sched.h> #endif -void SchedYield() noexcept { +void SchedYield() noexcept { #if defined(_unix_) sched_yield(); #else @@ -16,7 +16,7 @@ void SchedYield() noexcept { #endif } -void ThreadYield() noexcept { +void ThreadYield() noexcept { #if defined(_freebsd_) pthread_yield(); #else diff --git a/util/system/yield.h b/util/system/yield.h index 7886ac0522..9965fb52b5 100644 --- a/util/system/yield.h +++ b/util/system/yield.h @@ -1,4 +1,4 @@ #pragma once -void SchedYield() noexcept; -void ThreadYield() noexcept; +void SchedYield() noexcept; +void ThreadYield() noexcept; |