diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (patch) | |
tree | cb7a9f4a92c0d4cc5a86eeed49ad71e810953c1f | |
parent | 83a8efcf3af051e3dd59c00d1d5dafc96412ec1e (diff) | |
download | ydb-00afc96e9c0298054b7386fa7fb9e3cc3d67b974.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 1 of 2.
95 files changed, 1426 insertions, 1426 deletions
diff --git a/build/plugins/swig.py b/build/plugins/swig.py index 32a37204a6..7734a28533 100644 --- a/build/plugins/swig.py +++ b/build/plugins/swig.py @@ -67,7 +67,7 @@ class Swig(iw.CustomCommand): if self._swig_lang in ['jni_cpp', 'java']: self._out_header = os.path.splitext(self._main_out)[0] + '.h' - if (not unit.get('USE_SYSTEM_JDK')) and (unit.get('OS_ANDROID') != "yes"): + if (not unit.get('USE_SYSTEM_JDK')) and (unit.get('OS_ANDROID') != "yes"): unit.onpeerdir(['contrib/libs/jdk']) self._package = 'ru.yandex.' + os.path.dirname(self._path).replace('$S/', '').replace('$B/', '').replace('/', '.').replace('-', '_') diff --git a/contrib/libs/cxxsupp/libcxx/include/type_traits b/contrib/libs/cxxsupp/libcxx/include/type_traits index 8c91522074..f1b66fb994 100644 --- a/contrib/libs/cxxsupp/libcxx/include/type_traits +++ b/contrib/libs/cxxsupp/libcxx/include/type_traits @@ -1392,8 +1392,8 @@ template <class _Tp, class _Up> struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type, typename __uncvref<_Up>::type> {}; -// C++20, enabled for C++17 in Arcadia -#if _LIBCPP_STD_VER > 14 +// C++20, enabled for C++17 in Arcadia +#if _LIBCPP_STD_VER > 14 // remove_cvref - same as __uncvref template <class _Tp> struct remove_cvref : public __uncvref<_Tp> {}; diff --git a/contrib/libs/fastlz/ya.make b/contrib/libs/fastlz/ya.make index 7f31ac0bec..05690497a5 100644 --- a/contrib/libs/fastlz/ya.make +++ b/contrib/libs/fastlz/ya.make @@ -17,7 +17,7 @@ NO_COMPILER_WARNINGS() SRCS( fastlz.c - rename.h + rename.h ) END() diff --git a/contrib/libs/libidn/win/unistd.h b/contrib/libs/libidn/win/unistd.h index a0351cff2b..5e74c95924 100644 --- a/contrib/libs/libidn/win/unistd.h +++ b/contrib/libs/libidn/win/unistd.h @@ -1,14 +1,14 @@ -#ifndef _LIBIDN_WIN_UNISTD_H -#define _LIBIDN_WIN_UNISTD_H - -#ifndef _SSIZE_T_DEFINED -# if defined(_WIN64) -# define _SSIZE_T_DEFINED -# define ssize_t __int64 -# else -# define _SSIZE_T_DEFINED -# define ssize_t int -# endif -#endif - -#endif // _LIBIDN_WIN_UNISTD_H +#ifndef _LIBIDN_WIN_UNISTD_H +#define _LIBIDN_WIN_UNISTD_H + +#ifndef _SSIZE_T_DEFINED +# if defined(_WIN64) +# define _SSIZE_T_DEFINED +# define ssize_t __int64 +# else +# define _SSIZE_T_DEFINED +# define ssize_t int +# endif +#endif + +#endif // _LIBIDN_WIN_UNISTD_H diff --git a/contrib/libs/lz4/ya.make b/contrib/libs/lz4/ya.make index 282dfe3920..99b2535dcf 100644 --- a/contrib/libs/lz4/ya.make +++ b/contrib/libs/lz4/ya.make @@ -34,4 +34,4 @@ SRCS( lz4hc.c ) -END() +END() diff --git a/contrib/libs/ya.make b/contrib/libs/ya.make index 9c4640fdcf..df6d7bba13 100644 --- a/contrib/libs/ya.make +++ b/contrib/libs/ya.make @@ -244,7 +244,7 @@ RECURSE( numa nvidia odpi - onnx + onnx opencl-headers opencv opencv/modules diff --git a/library/README.md b/library/README.md index fc418bef7b..00201a3f0f 100644 --- a/library/README.md +++ b/library/README.md @@ -23,7 +23,7 @@ library 7. The library **MUST** be accompanied by `README.md` file and a brief description of the project. 8. The library **MUST** be accompanied by unit-tests. - + 9. CPU- or/and RAM-bound algorithms **SHOULD** provide benchmarks. 10. There **MUST** be no trade secrets of Yandex in `library/`: anything that can cause harm on publishing as OpenSource. For example: diff --git a/library/cpp/binsaver/bin_saver.h b/library/cpp/binsaver/bin_saver.h index 412424889f..88de676e8f 100644 --- a/library/cpp/binsaver/bin_saver.h +++ b/library/cpp/binsaver/bin_saver.h @@ -10,8 +10,8 @@ #include <util/generic/list.h> #include <util/generic/maybe.h> #include <util/generic/bitmap.h> -#include <util/generic/variant.h> -#include <util/generic/ylimits.h> +#include <util/generic/variant.h> +#include <util/generic/ylimits.h> #include <util/memory/blob.h> #include <util/digest/murmur.h> @@ -404,13 +404,13 @@ public: template <class T1, size_t N> int Add(const chunk_id, std::array<T1, N>* pData) { if (HasNonTrivialSerializer<T1>(0u)) { - for (size_t i = 0; i < N; ++i) - Add(1, &(*pData)[i]); - } else { + for (size_t i = 0; i < N; ++i) + Add(1, &(*pData)[i]); + } else { DataChunk((void*)pData->data(), pData->size() * sizeof(T1)); - } - return 0; - } + } + return 0; + } template <size_t N> int Add(const chunk_id, std::bitset<N>* pData) { @@ -451,46 +451,46 @@ public: return 0; } - template <class TVariantClass> - struct TLoadFromTypeFromListHelper { - template <class T0, class... TTail> - static void Do(IBinSaver& binSaver, ui32 typeIndex, TVariantClass* pData) { - if constexpr (sizeof...(TTail) == 0) { - Y_ASSERT(typeIndex == 0); - T0 chunk; - binSaver.Add(2, &chunk); - *pData = std::move(chunk); - } else { - if (typeIndex == 0) { - Do<T0>(binSaver, 0, pData); - } else { - Do<TTail...>(binSaver, typeIndex - 1, pData); - } - } - } - }; - - template <class... TVariantTypes> + template <class TVariantClass> + struct TLoadFromTypeFromListHelper { + template <class T0, class... TTail> + static void Do(IBinSaver& binSaver, ui32 typeIndex, TVariantClass* pData) { + if constexpr (sizeof...(TTail) == 0) { + Y_ASSERT(typeIndex == 0); + T0 chunk; + binSaver.Add(2, &chunk); + *pData = std::move(chunk); + } else { + if (typeIndex == 0) { + Do<T0>(binSaver, 0, pData); + } else { + Do<TTail...>(binSaver, typeIndex - 1, pData); + } + } + } + }; + + template <class... TVariantTypes> int Add(const chunk_id, std::variant<TVariantTypes...>* pData) { static_assert(std::variant_size_v<std::variant<TVariantTypes...>> < Max<ui32>()); - - ui32 index; - if (IsReading()) { - Add(1, &index); + + ui32 index; + if (IsReading()) { + Add(1, &index); TLoadFromTypeFromListHelper<std::variant<TVariantTypes...>>::template Do<TVariantTypes...>( - *this, - index, - pData - ); - } else { - index = pData->index(); // type cast is safe because of static_assert check above - Add(1, &index); + *this, + index, + pData + ); + } else { + index = pData->index(); // type cast is safe because of static_assert check above + Add(1, &index); std::visit([&](auto& dst) -> void { Add(2, &dst); }, *pData); - } - return 0; - } - - + } + return 0; + } + + void AddPolymorphicBase(chunk_id, IObjectBase* pObject) { (*pObject) & (*this); } @@ -504,9 +504,9 @@ public: else StoreObject(pData->GetBarePtr()); } - template <class T, class TPolicy> - int Add(const chunk_id, TMaybe<T, TPolicy>* pData) { - TMaybe<T, TPolicy>& data = *pData; + template <class T, class TPolicy> + int Add(const chunk_id, TMaybe<T, TPolicy>* pData) { + TMaybe<T, TPolicy>& data = *pData; if (IsReading()) { bool defined = false; Add(1, &defined); @@ -585,23 +585,23 @@ struct TRegisterSaveLoadType { #define REGISTER_SAVELOAD_CLASS(N, name) \ BASIC_REGISTER_CLASS(name) \ static TRegisterSaveLoadType<name> init##name##N(N); - + // using TObj/TRef on forward declared templ class will not work // but multiple registration with same id is allowed #define REGISTER_SAVELOAD_TEMPL1_CLASS(N, className, T) \ static TRegisterSaveLoadType<className<T>> init##className##T##N(N); - + #define REGISTER_SAVELOAD_TEMPL2_CLASS(N, className, T1, T2) \ typedef className<T1, T2> temp##className##T1##_##T2##temp; \ static TRegisterSaveLoadType<className<T1, T2>> init##className##T1##_##T2##N(N); - + #define REGISTER_SAVELOAD_TEMPL3_CLASS(N, className, T1, T2, T3) \ typedef className<T1, T2, T3> temp##className##T1##_##T2##_##T3##temp; \ static TRegisterSaveLoadType<className<T1, T2, T3>> init##className##T1##_##T2##_##T3##N(N); - + #define REGISTER_SAVELOAD_NM_CLASS(N, nmspace, className) \ BASIC_REGISTER_CLASS(nmspace::className) \ - static TRegisterSaveLoadType<nmspace::className> init_##nmspace##_##name##N(N); + static TRegisterSaveLoadType<nmspace::className> init_##nmspace##_##name##N(N); #define REGISTER_SAVELOAD_NM2_CLASS(N, nmspace1, nmspace2, className) \ BASIC_REGISTER_CLASS(nmspace1::nmspace2::className) \ diff --git a/library/cpp/binsaver/ut/binsaver_ut.cpp b/library/cpp/binsaver/ut/binsaver_ut.cpp index 37eba5406f..a42d161947 100644 --- a/library/cpp/binsaver/ut/binsaver_ut.cpp +++ b/library/cpp/binsaver/ut/binsaver_ut.cpp @@ -80,51 +80,51 @@ UNIT_ASSERT(IBinSaver::HasNonTrivialSerializer<TVector<TCustomSerializer>>(0u)); Y_UNIT_TEST(TestStroka) { - TestBinSaverSerialization(TString("QWERTY")); + TestBinSaverSerialization(TString("QWERTY")); } Y_UNIT_TEST(TestMoveOnlyType) { - TestBinSaverSerializationToBuffer(TMoveOnlyType()); + TestBinSaverSerializationToBuffer(TMoveOnlyType()); } Y_UNIT_TEST(TestVectorStrok) { - TestBinSaverSerialization(TVector<TString>{"A", "B", "C"}); + TestBinSaverSerialization(TVector<TString>{"A", "B", "C"}); } Y_UNIT_TEST(TestCArray) { - TestBinSaverSerialization(TTypeWithArray()); + TestBinSaverSerialization(TTypeWithArray()); } Y_UNIT_TEST(TestSets) { - TestBinSaverSerialization(THashSet<TString>{"A", "B", "C"}); - TestBinSaverSerialization(TSet<TString>{"A", "B", "C"}); + TestBinSaverSerialization(THashSet<TString>{"A", "B", "C"}); + TestBinSaverSerialization(TSet<TString>{"A", "B", "C"}); } Y_UNIT_TEST(TestMaps) { - TestBinSaverSerialization(THashMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}}); - TestBinSaverSerialization(TMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}}); + TestBinSaverSerialization(THashMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}}); + TestBinSaverSerialization(TMap<TString, ui32>{{"A", 1}, {"B", 2}, {"C", 3}}); } Y_UNIT_TEST(TestBlob) { - TestBinSaverSerialization(TBlob::FromStringSingleThreaded("qwerty")); + TestBinSaverSerialization(TBlob::FromStringSingleThreaded("qwerty")); } -Y_UNIT_TEST(TestVariant) { - { +Y_UNIT_TEST(TestVariant) { + { using T = std::variant<TString, int>; - - TestBinSaverSerialization(T(TString(""))); - TestBinSaverSerialization(T(0)); - } - { + + TestBinSaverSerialization(T(TString(""))); + TestBinSaverSerialization(T(0)); + } + { using T = std::variant<TString, int, float>; - - TestBinSaverSerialization(T(TString("ask"))); - TestBinSaverSerialization(T(12)); - TestBinSaverSerialization(T(0.64f)); - } -} - + + TestBinSaverSerialization(T(TString("ask"))); + TestBinSaverSerialization(T(12)); + TestBinSaverSerialization(T(0.64f)); + } +} + Y_UNIT_TEST(TestPod) { struct TPod { ui32 A = 5; @@ -133,12 +133,12 @@ Y_UNIT_TEST(TestPod) { return A == other.A && B == other.B; } }; - TestBinSaverSerialization(TPod()); + TestBinSaverSerialization(TPod()); TPod custom; custom.A = 25; custom.B = 37; - TestBinSaverSerialization(custom); - TestBinSaverSerialization(TVector<TPod>{custom}); + TestBinSaverSerialization(custom); + TestBinSaverSerialization(TVector<TPod>{custom}); } Y_UNIT_TEST(TestSubPod) { @@ -158,12 +158,12 @@ Y_UNIT_TEST(TestSubPod) { return B == other.B; } }; - TestBinSaverSerialization(TPod()); + TestBinSaverSerialization(TPod()); TPod::TSub sub; sub.X = 1; TPod custom; custom.B = {sub}; - TestBinSaverSerialization(TVector<TPod>{custom}); + TestBinSaverSerialization(TVector<TPod>{custom}); } Y_UNIT_TEST(TestMemberAndOpIsMain) { @@ -192,7 +192,7 @@ Y_UNIT_TEST(TestMemberAndOpIsMain) { obj.S = "TString"; obj.A = 42; - TestBinSaverSerialization(obj); + TestBinSaverSerialization(obj); } } ; diff --git a/library/cpp/binsaver/ut/ya.make b/library/cpp/binsaver/ut/ya.make index 43dc20bff7..a60a2684f9 100644 --- a/library/cpp/binsaver/ut/ya.make +++ b/library/cpp/binsaver/ut/ya.make @@ -7,5 +7,5 @@ SRCS( ) PEERDIR(library/cpp/binsaver/ut_util) - + END() diff --git a/library/cpp/binsaver/ut_util/README.md b/library/cpp/binsaver/ut_util/README.md index 41641cd1e1..9f7e1b0b94 100644 --- a/library/cpp/binsaver/ut_util/README.md +++ b/library/cpp/binsaver/ut_util/README.md @@ -1 +1 @@ -Library for testing BinSaver serialization.
\ No newline at end of file +Library for testing BinSaver serialization.
\ No newline at end of file diff --git a/library/cpp/binsaver/ut_util/ut_util.cpp b/library/cpp/binsaver/ut_util/ut_util.cpp index 4cd8daa931..8e466a5acd 100644 --- a/library/cpp/binsaver/ut_util/ut_util.cpp +++ b/library/cpp/binsaver/ut_util/ut_util.cpp @@ -1 +1 @@ -#include "ut_util.h" +#include "ut_util.h" diff --git a/library/cpp/binsaver/ut_util/ut_util.h b/library/cpp/binsaver/ut_util/ut_util.h index 52e7bcf8e1..be8f89cc7c 100644 --- a/library/cpp/binsaver/ut_util/ut_util.h +++ b/library/cpp/binsaver/ut_util/ut_util.h @@ -1,71 +1,71 @@ -#pragma once - +#pragma once + #include <library/cpp/binsaver/bin_saver.h> #include <library/cpp/binsaver/mem_io.h> #include <library/cpp/binsaver/util_stream_io.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/vector.h> -#include <util/stream/buffer.h> - -#include <functional> - - -/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself - * comparerChecksInside == false means comparer returns if its arguments are equal - */ - -template <class T, class TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void UnitTestCheckWithComparer(const T& lhs, const T& rhs, const TComparer& comparer) { - if constexpr (comparerChecksInside) { - comparer(lhs, rhs); - } else { - UNIT_ASSERT(comparer(lhs, rhs)); - } -} - - -/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself - * comparerChecksInside == false means comparer returns true if its arguments are equal - */ - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerializationToBuffer(const T& original, const TComparer& comparer = TComparer()) { - TBufferOutput out; - { - TYaStreamOutput yaOut(out); - - IBinSaver f(yaOut, false, false); - f.Add(0, const_cast<T*>(&original)); - } - TBufferInput in(out.Buffer()); - T restored; - { - TYaStreamInput yaIn(in); - IBinSaver f(yaIn, true, false); - f.Add(0, &restored); - } - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); -} - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerializationToVector(const T& original, const TComparer& comparer = TComparer()) { - TVector<char> out; - SerializeToMem(&out, *const_cast<T*>(&original)); - T restored; - SerializeFromMem(&out, restored); - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); - - TVector<TVector<char>> out2D; - SerializeToMem(&out2D, *const_cast<T*>(&original)); - T restored2D; - SerializeFromMem(&out2D, restored2D); - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored2D, comparer); -} - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerialization(const T& original, const TComparer& comparer = TComparer()) { - TestBinSaverSerializationToBuffer<T, TComparer, comparerChecksInside>(original, comparer); - TestBinSaverSerializationToVector<T, TComparer, comparerChecksInside>(original, comparer); -} + +#include <util/generic/vector.h> +#include <util/stream/buffer.h> + +#include <functional> + + +/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself + * comparerChecksInside == false means comparer returns if its arguments are equal + */ + +template <class T, class TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void UnitTestCheckWithComparer(const T& lhs, const T& rhs, const TComparer& comparer) { + if constexpr (comparerChecksInside) { + comparer(lhs, rhs); + } else { + UNIT_ASSERT(comparer(lhs, rhs)); + } +} + + +/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself + * comparerChecksInside == false means comparer returns true if its arguments are equal + */ + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerializationToBuffer(const T& original, const TComparer& comparer = TComparer()) { + TBufferOutput out; + { + TYaStreamOutput yaOut(out); + + IBinSaver f(yaOut, false, false); + f.Add(0, const_cast<T*>(&original)); + } + TBufferInput in(out.Buffer()); + T restored; + { + TYaStreamInput yaIn(in); + IBinSaver f(yaIn, true, false); + f.Add(0, &restored); + } + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); +} + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerializationToVector(const T& original, const TComparer& comparer = TComparer()) { + TVector<char> out; + SerializeToMem(&out, *const_cast<T*>(&original)); + T restored; + SerializeFromMem(&out, restored); + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); + + TVector<TVector<char>> out2D; + SerializeToMem(&out2D, *const_cast<T*>(&original)); + T restored2D; + SerializeFromMem(&out2D, restored2D); + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored2D, comparer); +} + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerialization(const T& original, const TComparer& comparer = TComparer()) { + TestBinSaverSerializationToBuffer<T, TComparer, comparerChecksInside>(original, comparer); + TestBinSaverSerializationToVector<T, TComparer, comparerChecksInside>(original, comparer); +} diff --git a/library/cpp/binsaver/ut_util/ya.make b/library/cpp/binsaver/ut_util/ya.make index 7e60f13ef3..25c867f631 100644 --- a/library/cpp/binsaver/ut_util/ya.make +++ b/library/cpp/binsaver/ut_util/ya.make @@ -1,14 +1,14 @@ -LIBRARY() - -OWNER(gulin) - -SRCS( - ut_util.cpp -) - -PEERDIR( +LIBRARY() + +OWNER(gulin) + +SRCS( + ut_util.cpp +) + +PEERDIR( library/cpp/binsaver library/cpp/testing/unittest -) - -END() +) + +END() diff --git a/library/cpp/binsaver/util_stream_io.h b/library/cpp/binsaver/util_stream_io.h index d65d630b93..31d8df5351 100644 --- a/library/cpp/binsaver/util_stream_io.h +++ b/library/cpp/binsaver/util_stream_io.h @@ -4,11 +4,11 @@ #include <util/stream/input.h> #include <util/stream/output.h> -#include <util/stream/file.h> +#include <util/stream/file.h> class TYaStreamInput: public IBinaryStream { IInputStream& Stream; - + int WriteImpl(const void*, int) override { Y_ASSERT(0); return 0; @@ -41,13 +41,13 @@ inline void SerializeFromStream(IInputStream& stream, T& c) { template <class T> inline void SerializeFromFile(const TString& fileName, T& c) { - TIFStream in(fileName); - SerializeFromStream(in, c); -} - + TIFStream in(fileName); + SerializeFromStream(in, c); +} + class TYaStreamOutput: public IBinaryStream { IOutputStream& Stream; - + int WriteImpl(const void* what, int size) override { Stream.Write(what, (size_t)size); return size; @@ -78,9 +78,9 @@ inline void SerializeToArcadiaStream(IOutputStream& stream, T& c) { bs.Add(1, &c); } } - + template <class T> inline void SerializeToFile(const TString& fileName, T& c) { - TOFStream out(fileName); + TOFStream out(fileName); SerializeToArcadiaStream(out, c); -} +} diff --git a/library/cpp/charset/wide_ut.cpp b/library/cpp/charset/wide_ut.cpp index 78947d51ba..aa2902b99b 100644 --- a/library/cpp/charset/wide_ut.cpp +++ b/library/cpp/charset/wide_ut.cpp @@ -208,8 +208,8 @@ void TConversionTest::TestYandexEncoding() { UNIT_ASSERT(w == wideCyrillicAlphabet); w = UTF8ToWide(yandexCyrillicAlphabet, strlen(yandexCyrillicAlphabet), csYandex); UNIT_ASSERT(w == wideCyrillicAlphabet); - - const char* utf8NonBMP2 = "ab\xf4\x80\x89\x87n"; + + const char* utf8NonBMP2 = "ab\xf4\x80\x89\x87n"; wchar16 wNonBMPDummy2[] = {'a', 'b', 0xDBC0, 0xDE47, 'n'}; TestSurrogates(utf8NonBMP2, wNonBMPDummy2, Y_ARRAY_SIZE(wNonBMPDummy2), CODES_UTF8); diff --git a/library/cpp/containers/comptrie/ya.make b/library/cpp/containers/comptrie/ya.make index 81352da4b2..970a3bbf57 100644 --- a/library/cpp/containers/comptrie/ya.make +++ b/library/cpp/containers/comptrie/ya.make @@ -3,11 +3,11 @@ LIBRARY() OWNER(velavokr) SRCS( - array_with_size.h - chunked_helpers_trie.h - comptrie.h + array_with_size.h + chunked_helpers_trie.h + comptrie.h comptrie_packer.h - comptrie_trie.h + comptrie_trie.h first_symbol_iterator.h key_selector.h leaf_skipper.h diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h index 45859ed65a..445d070c69 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.h +++ b/library/cpp/deprecated/mapped_file/mapped_file.h @@ -59,7 +59,7 @@ public: return (Map_ ? Map_->MappedSize() : 0); } - void* getData(size_t pos = 0) const { + void* getData(size_t pos = 0) const { Y_ASSERT(!Map_ || (pos <= getSize())); return (Map_ ? (void*)((unsigned char*)Map_->Ptr() + pos) : nullptr); } diff --git a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp index afbd5b3358..d62d0bb18c 100644 --- a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp +++ b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp @@ -6,13 +6,13 @@ Y_UNIT_TEST_SUITE(TMappedFileTest) { static const char* FileName_("./mappped_file"); Y_UNIT_TEST(TestFileMapEmpty) { - TFile file(FileName_, CreateAlways | WrOnly); - file.Close(); + TFile file(FileName_, CreateAlways | WrOnly); + file.Close(); - TMappedFile map; - map.init(FileName_); + TMappedFile map; + map.init(FileName_); map.getData(0); - + NFs::Remove(FileName_); - } + } }; diff --git a/library/cpp/deprecated/split/delim_string_iter.h b/library/cpp/deprecated/split/delim_string_iter.h index 8e4ca171a0..3d47d23ad9 100644 --- a/library/cpp/deprecated/split/delim_string_iter.h +++ b/library/cpp/deprecated/split/delim_string_iter.h @@ -1,13 +1,13 @@ #pragma once - + #include <util/generic/algorithm.h> #include <util/generic/strbuf.h> #include <util/generic/yexception.h> #include <util/string/cast.h> #include <util/system/yassert.h> - + #include <iterator> - + class TDelimStringIter { public: using value_type = TStringBuf; @@ -20,7 +20,7 @@ public: : TDelimStringIter(TStringBuf(begin, strEnd), delim) { } - + inline TDelimStringIter(TStringBuf str, TStringBuf delim) : IsValid(true) , Str(str) @@ -33,7 +33,7 @@ public: : IsValid(false) { } - + inline explicit operator bool() const { return IsValid; } @@ -43,32 +43,32 @@ public: if (Current.end() != Str.end()) { Str.Skip(Current.length() + Delim.length()); UpdateCurrent(); - } else { + } else { Str.Clear(); Current.Clear(); - IsValid = false; - } - return *this; - } - + IsValid = false; + } + return *this; + } + inline void operator+=(size_t n) { for (; n > 0; --n) { - ++(*this); - } - } - + ++(*this); + } + } + inline bool operator==(const TDelimStringIter& rhs) const { return (IsValid == rhs.IsValid) && (!IsValid || (Current.begin() == rhs.Current.begin())); - } - + } + inline bool operator!=(const TDelimStringIter& rhs) const { return !(*this == rhs); - } - + } + inline TStringBuf operator*() const { return Current; - } - + } + inline const TStringBuf* operator->() const { return &Current; } @@ -76,23 +76,23 @@ public: // Get & advance template <class T> inline bool TryNext(T& t) { - if (IsValid) { + if (IsValid) { t = FromString<T>(Current); - operator++(); - return true; - } else { - return false; - } - } - + operator++(); + return true; + } else { + return false; + } + } + template <class T> inline TDelimStringIter& Next(T& t) // Get & advance - { - if (!TryNext(t)) - ythrow yexception() << "No valid field"; - return *this; - } - + { + if (!TryNext(t)) + ythrow yexception() << "No valid field"; + return *this; + } + template <class T> inline T GetNext() { T res; @@ -102,24 +102,24 @@ public: inline const char* GetBegin() const { return Current.begin(); - } - + } + inline const char* GetEnd() const { return Current.end(); - } - + } + inline bool Valid() const { - return IsValid; - } - + return IsValid; + } + // contents from next token to the end of string inline TStringBuf Cdr() const { return Str.SubStr(Current.length() + Delim.length()); - } - + } + inline TDelimStringIter IterEnd() const { return TDelimStringIter(); - } + } private: inline void UpdateCurrent() { @@ -134,8 +134,8 @@ private: TStringBuf Str; TStringBuf Current; TStringBuf Delim; -}; - +}; + //example: for (TStringBuf field: TDelimStroka(line, "@@")) { ... } struct TDelimStroka { TStringBuf S; @@ -158,15 +158,15 @@ struct TDelimStroka { inline TDelimStringIter begin_delim(const TString& str, TStringBuf delim) { return TDelimStringIter(str, delim); -} - +} + inline TDelimStringIter begin_delim(TStringBuf str, TStringBuf delim) { return TDelimStringIter(str.begin(), str.end(), delim); -} - +} + inline TDelimStringIter end_delim(const TString& /*str*/, TStringBuf /*delim*/) { return TDelimStringIter(); -} +} class TKeyValueDelimStringIter { public: diff --git a/library/cpp/lcs/ya.make b/library/cpp/lcs/ya.make index 3a7caafc88..1ddb171ece 100644 --- a/library/cpp/lcs/ya.make +++ b/library/cpp/lcs/ya.make @@ -10,4 +10,4 @@ SRCS( lcs_via_lis.cpp ) -END() +END() diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index fd2a906d6f..c005e8852f 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -262,7 +262,7 @@ static volatile int freeChunkCount; static void AddFreeChunk(uintptr_t chunkId) { chunkSizeIdx[chunkId] = -1; if (Y_UNLIKELY(freeChunkCount == FREE_CHUNK_ARR_BUF)) - NMalloc::AbortFromCorruptedAllocator("free chunks array overflowed"); + NMalloc::AbortFromCorruptedAllocator("free chunks array overflowed"); freeChunkArr[freeChunkCount++] = chunkId; } diff --git a/library/cpp/object_factory/object_factory.h b/library/cpp/object_factory/object_factory.h index 96cc11bcfd..57a9ee8f4e 100644 --- a/library/cpp/object_factory/object_factory.h +++ b/library/cpp/object_factory/object_factory.h @@ -11,7 +11,7 @@ namespace NObjectFactory { template <class TProduct, class... TArgs> class IFactoryObjectCreator { public: - virtual TProduct* Create(TArgs... args) const = 0; + virtual TProduct* Create(TArgs... args) const = 0; virtual ~IFactoryObjectCreator() { } }; @@ -34,8 +34,8 @@ namespace NObjectFactory { template <class TBaseProduct, class TDerivedProduct, class... TArgs> class TFactoryObjectCreator: public IFactoryObjectCreator<TBaseProduct, TArgs...> { - TDerivedProduct* Create(TArgs... args) const override { - return new TDerivedProduct(std::forward<TArgs>(args)...); + TDerivedProduct* Create(TArgs... args) const override { + return new TDerivedProduct(std::forward<TArgs>(args)...); } }; @@ -185,7 +185,7 @@ namespace NObjectFactory { public: TProduct* Create(const TKey& key, TArgs... args) const { IFactoryObjectCreator<TProduct, TArgs...>* creator = IObjectFactory<TProduct, TKey, TArgs...>::GetCreator(key); - return creator == nullptr ? nullptr : creator->Create(std::forward<TArgs>(args)...); + return creator == nullptr ? nullptr : creator->Create(std::forward<TArgs>(args)...); } static bool Has(const TKey& key) { @@ -193,7 +193,7 @@ namespace NObjectFactory { } static TProduct* Construct(const TKey& key, TArgs... args) { - return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); + return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); } template <class... Args> diff --git a/library/cpp/object_factory/object_factory_ut.cpp b/library/cpp/object_factory/object_factory_ut.cpp index 06fb0739ff..49e2ca2cec 100644 --- a/library/cpp/object_factory/object_factory_ut.cpp +++ b/library/cpp/object_factory/object_factory_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/object_factory/object_factory.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/noncopyable.h> +#include <util/generic/noncopyable.h> #include <util/generic/string.h> #include <util/generic/ptr.h> @@ -59,7 +59,7 @@ private: }; struct TDirectOrderCreator: public IFactoryObjectCreator<ICommonInterface, const TString&, float, TArgument&> { - ICommonInterface* Create(const TString& provider, float factor, TArgument& argument) const override { + ICommonInterface* Create(const TString& provider, float factor, TArgument& argument) const override { ++CallsCounter; return new TDirectOrder(provider, factor, argument); } @@ -73,65 +73,65 @@ using TTestFactory = TParametrizedObjectFactory<ICommonInterface, TString, const static TTestFactory::TRegistrator<TDirectOrder> Direct("direct", new TDirectOrderCreator); static TTestFactory::TRegistrator<TInverseOrder> Inverse("inverse"); - - -class IMoveableOnlyInterface { -public: - virtual ~IMoveableOnlyInterface() { - } - - virtual TString GetValue() const = 0; -}; - -class TMoveableOnly: public IMoveableOnlyInterface, public TMoveOnly { -public: - TMoveableOnly(TString&& value) - : Value(value) - {} - - TString GetValue() const override { - return Value; - } - -private: - const TString Value; -}; - - -using TMoveableOnlyFactory = TParametrizedObjectFactory<IMoveableOnlyInterface, TString, TString&&>; - -static TMoveableOnlyFactory::TRegistrator<TMoveableOnly> MoveableOnlyReg("move"); - - - -class TMoveableOnly2: public IMoveableOnlyInterface, public TMoveOnly { -public: - TMoveableOnly2(THolder<TString>&& value) - : Value(std::move(value)) - {} - - TString GetValue() const override { - return *Value; - } - -private: - const THolder<TString> Value; -}; - - -using TMoveableOnly2Factory = TParametrizedObjectFactory<IMoveableOnlyInterface, TString, THolder<TString>&&>; - -static TMoveableOnly2Factory::TRegistrator<TMoveableOnly2> MoveableOnly2Reg("move2"); - + + +class IMoveableOnlyInterface { +public: + virtual ~IMoveableOnlyInterface() { + } + + virtual TString GetValue() const = 0; +}; + +class TMoveableOnly: public IMoveableOnlyInterface, public TMoveOnly { +public: + TMoveableOnly(TString&& value) + : Value(value) + {} + + TString GetValue() const override { + return Value; + } + +private: + const TString Value; +}; + + +using TMoveableOnlyFactory = TParametrizedObjectFactory<IMoveableOnlyInterface, TString, TString&&>; + +static TMoveableOnlyFactory::TRegistrator<TMoveableOnly> MoveableOnlyReg("move"); + + + +class TMoveableOnly2: public IMoveableOnlyInterface, public TMoveOnly { +public: + TMoveableOnly2(THolder<TString>&& value) + : Value(std::move(value)) + {} + + TString GetValue() const override { + return *Value; + } + +private: + const THolder<TString> Value; +}; + + +using TMoveableOnly2Factory = TParametrizedObjectFactory<IMoveableOnlyInterface, TString, THolder<TString>&&>; + +static TMoveableOnly2Factory::TRegistrator<TMoveableOnly2> MoveableOnly2Reg("move2"); + class TDirectOrderDifferentSignature : public TDirectOrder { public: TDirectOrderDifferentSignature(const TString& provider, TArgument& argument) : TDirectOrder(provider, 0.01f, argument) { } - + }; - + struct TDirectOrderDSCreator: public IFactoryObjectCreator<ICommonInterface, const TString&, float, TArgument&> { ICommonInterface* Create(const TString& provider, float factor, TArgument& argument) const override { Y_UNUSED(factor); @@ -157,26 +157,26 @@ Y_UNIT_TEST_SUITE(TestObjectFactory) { UNIT_ASSERT_EQUAL(TDirectOrderCreator::CallsCounter, 1); } - - Y_UNIT_TEST(TestMoveableOnly) { - TString v = "value1"; - - THolder<IMoveableOnlyInterface> moveableOnly(TMoveableOnlyFactory::Construct("move", std::move(v))); - - UNIT_ASSERT(!!moveableOnly); - - UNIT_ASSERT(moveableOnly->GetValue() == "value1"); - } - - Y_UNIT_TEST(TestMoveableOnly2) { - THolder<TString> v = MakeHolder<TString>("value2"); - - THolder<IMoveableOnlyInterface> moveableOnly2(TMoveableOnly2Factory::Construct("move2", std::move(v))); - - UNIT_ASSERT(!!moveableOnly2); - - UNIT_ASSERT(moveableOnly2->GetValue() == "value2"); - } + + Y_UNIT_TEST(TestMoveableOnly) { + TString v = "value1"; + + THolder<IMoveableOnlyInterface> moveableOnly(TMoveableOnlyFactory::Construct("move", std::move(v))); + + UNIT_ASSERT(!!moveableOnly); + + UNIT_ASSERT(moveableOnly->GetValue() == "value1"); + } + + Y_UNIT_TEST(TestMoveableOnly2) { + THolder<TString> v = MakeHolder<TString>("value2"); + + THolder<IMoveableOnlyInterface> moveableOnly2(TMoveableOnly2Factory::Construct("move2", std::move(v))); + + UNIT_ASSERT(!!moveableOnly2); + + UNIT_ASSERT(moveableOnly2->GetValue() == "value2"); + } Y_UNIT_TEST(TestDifferentSignature) { TArgument directArg{"Name", nullptr}; diff --git a/library/cpp/packedtypes/packed.h b/library/cpp/packedtypes/packed.h index 88cff26ae2..044e53be34 100644 --- a/library/cpp/packedtypes/packed.h +++ b/library/cpp/packedtypes/packed.h @@ -1,10 +1,10 @@ #pragma once - + #include <library/cpp/streams/zc_memory_input/zc_memory_input.h> - + #include <util/stream/output.h> -#include <util/ysaveload.h> - +#include <util/ysaveload.h> + #include "longs.h" struct Stream_traits { @@ -38,57 +38,57 @@ struct Stream_traits { static int is_good(IOutputStream& /*out*/) { return 1; } -}; - +}; + struct TZCMemoryInput_traits { template <typename T> static T get(TZCMemoryInput& in) { T x; - in.ReadPOD(x); + in.ReadPOD(x); return x; - } - + } + static ui8 Y_FORCE_INLINE get_8(TZCMemoryInput& in) { return get<ui8>(in); - } - + } + static ui16 Y_FORCE_INLINE get_16(TZCMemoryInput& in) { return get<ui16>(in); - } - + } + static ui32 Y_FORCE_INLINE get_32(TZCMemoryInput& in) { return get<ui32>(in); } static int Y_FORCE_INLINE is_good(TZCMemoryInput&) { - return 1; - } -}; - + return 1; + } +}; + void Y_FORCE_INLINE PackUI32(IOutputStream& out, ui32 v) { - char buf[sizeof(ui32)]; - char* bufPtr = buf; - size_t size; + char buf[sizeof(ui32)]; + char* bufPtr = buf; + size_t size; PACK_28(v, bufPtr, mem_traits, size); - out.Write(buf, size); -} - + out.Write(buf, size); +} + template <class TStream> struct TInputStream2Traits { - typedef Stream_traits TTraits; -}; - + typedef Stream_traits TTraits; +}; + template <> struct TInputStream2Traits<TZCMemoryInput> { - typedef TZCMemoryInput_traits TTraits; -}; - + typedef TZCMemoryInput_traits TTraits; +}; + template <class TStream> void Y_FORCE_INLINE UnPackUI32(TStream& in, ui32& v) { - size_t size; + size_t size; UNPACK_28(v, in, TInputStream2Traits<TStream>::TTraits, size); (void)size; -} +} template <class TStream> ui32 Y_FORCE_INLINE UnPackUI32(TStream& in) { diff --git a/library/cpp/packedtypes/packed_ut.cpp b/library/cpp/packedtypes/packed_ut.cpp index 70a22cf9c3..2be6f6f77f 100644 --- a/library/cpp/packedtypes/packed_ut.cpp +++ b/library/cpp/packedtypes/packed_ut.cpp @@ -1,13 +1,13 @@ #include "packed.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/system/defaults.h> #include <util/generic/ylimits.h> #include <util/generic/buffer.h> -#include <util/stream/mem.h> +#include <util/stream/mem.h> #include <util/stream/buffer.h> - + namespace NPrivate { #if 0 static ui64 gSeed = 42; @@ -26,67 +26,67 @@ static T PseudoRandom(T max = Max<T>()) { Y_UNIT_TEST_SUITE(TPackedTest) { void TestPackUi32Sub(ui32 v, const TVector<char>& p) { - TBufferOutput out; - PackUI32(out, v); - const TBuffer& buf = out.Buffer(); + TBufferOutput out; + PackUI32(out, v); + const TBuffer& buf = out.Buffer(); UNIT_ASSERT_VALUES_EQUAL(buf.Size(), p.size()); - UNIT_ASSERT(!memcmp(buf.Data(), &p[0], buf.Size())); + UNIT_ASSERT(!memcmp(buf.Data(), &p[0], buf.Size())); - { - TBufferInput in(buf); - ui32 v2; - UnPackUI32(in, v2); + { + TBufferInput in(buf); + ui32 v2; + UnPackUI32(in, v2); UNIT_ASSERT_VALUES_EQUAL(v, v2); - } - + } + { - TZCMemoryInput in(buf.Data(), buf.Size()); - ui32 v2; - UnPackUI32(in, v2); + TZCMemoryInput in(buf.Data(), buf.Size()); + ui32 v2; + UnPackUI32(in, v2); UNIT_ASSERT_VALUES_EQUAL(v, v2); - } - } + } + } Y_UNIT_TEST(TestPackUi32) { - ui32 v; + ui32 v; TVector<char> pv; - - v = 0; - pv.resize(1); - pv[0] = 0x0; + + v = 0; + pv.resize(1); + pv[0] = 0x0; TestPackUi32Sub(v, pv); - - v = 0x1600; - pv.resize(2); - pv[0] = 0x96; - pv[1] = 0x00; + + v = 0x1600; + pv.resize(2); + pv[0] = 0x96; + pv[1] = 0x00; TestPackUi32Sub(v, pv); - - v = 0xEF98; - pv.resize(3); - pv[0] = 0xC0; + + v = 0xEF98; + pv.resize(3); + pv[0] = 0xC0; #if defined(_big_endian_) - pv[1] = 0xEF; - pv[2] = 0x98; -#elif defined(_little_endian_) - pv[1] = 0x98; - pv[2] = 0xEF; -#endif + pv[1] = 0xEF; + pv[2] = 0x98; +#elif defined(_little_endian_) + pv[1] = 0x98; + pv[2] = 0xEF; +#endif TestPackUi32Sub(v, pv); - - v = 0xF567FE4; - pv.resize(4); - pv[0] = 0xEF; - pv[1] = 0x56; + + v = 0xF567FE4; + pv.resize(4); + pv[0] = 0xEF; + pv[1] = 0x56; #if defined(_big_endian_) - pv[2] = 0x7F; - pv[3] = 0xE4; -#elif defined(_little_endian_) - pv[2] = 0xE4; - pv[3] = 0x7F; -#endif + pv[2] = 0x7F; + pv[3] = 0xE4; +#elif defined(_little_endian_) + pv[2] = 0xE4; + pv[3] = 0x7F; +#endif TestPackUi32Sub(v, pv); - } + } #if 0 Y_UNIT_TEST(ReadWrite32) { @@ -127,4 +127,4 @@ Y_UNIT_TEST_SUITE(TPackedTest) { } } #endif -}; +}; diff --git a/library/cpp/packedtypes/packedfloat.h b/library/cpp/packedtypes/packedfloat.h index f178912ed3..334072f211 100644 --- a/library/cpp/packedtypes/packedfloat.h +++ b/library/cpp/packedtypes/packedfloat.h @@ -157,27 +157,27 @@ using uf8 = NPackedFloat::float8<0>; using f8d = NPackedFloat::float8<1, 1>; using uf8d = NPackedFloat::float8<0, 1>; -// [0,1) value in 1/255s. +// [0,1) value in 1/255s. using frac8 = ui8; - + using frac16 = ui16; template <class T> inline constexpr T Float2Frac(float fac) { return T(fac * float(Max<T>())); -} - +} + template <class T> inline constexpr T Float2FracR(float fac) { float v = fac * float(Max<T>()); - return T(v + 0.5f); -} - + return T(v + 0.5f); +} + template <class T> inline constexpr float Frac2Float(T pf) { constexpr float multiplier = float(1.0 / Max<T>()); return pf * multiplier; -} +} class TUi82FloatMapping { private: diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp index 6270ee0624..d57effb114 100644 --- a/library/cpp/protobuf/util/pb_io.cpp +++ b/library/cpp/protobuf/util/pb_io.cpp @@ -2,16 +2,16 @@ #include <library/cpp/binsaver/bin_saver.h> #include <library/cpp/string_utils/base64/base64.h> - + #include <google/protobuf/message.h> #include <google/protobuf/messagext.h> #include <google/protobuf/text_format.h> - + #include <util/generic/string.h> #include <util/stream/file.h> #include <util/stream/str.h> #include <util/string/cast.h> - + namespace NProtoBuf { class TEnumIdValuePrinter : public google::protobuf::TextFormat::FastFieldValuePrinter { @@ -97,10 +97,10 @@ void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out) { NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out); if (!NProtoBuf::TextFormat::Print(m, &adaptor)) { - ythrow yexception() << "SerializeToTextFormat failed on Print"; + ythrow yexception() << "SerializeToTextFormat failed on Print"; } -} - +} + void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName) { /* TUnbufferedFileOutput is unbuffered, but TCopyingOutputStreamAdaptor adds * a buffer on top of it. */ @@ -167,8 +167,8 @@ bool TryParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, } return true; -} - +} + bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, const EParseFromTextFormatOptions options) { try { diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h index 493c84cb5f..b265a13cf3 100644 --- a/library/cpp/protobuf/util/pb_io.h +++ b/library/cpp/protobuf/util/pb_io.h @@ -1,8 +1,8 @@ -#pragma once - +#pragma once + #include <util/generic/fwd.h> #include <util/generic/flags.h> - + struct IBinSaver; namespace google { @@ -10,11 +10,11 @@ namespace google { class Message; } } - + namespace NProtoBuf { using Message = ::google::protobuf::Message; } - + class IInputStream; class IOutputStream; @@ -69,7 +69,7 @@ void ParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, // NOTE: will read `in` till the end. void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, const EParseFromTextFormatOptions options = {}); - + /* @return `true` if parsing was successfull and `false` otherwise. * * @see `ParseFromTextFormat` diff --git a/library/cpp/protobuf/util/pb_utils.h b/library/cpp/protobuf/util/pb_utils.h index 9e9a110b48..83fe0af167 100644 --- a/library/cpp/protobuf/util/pb_utils.h +++ b/library/cpp/protobuf/util/pb_utils.h @@ -1,10 +1,10 @@ -#pragma once - -#define UPDATE_PB_FIELD_MAX(PBMESS, FIELD, VAL) \ +#pragma once + +#define UPDATE_PB_FIELD_MAX(PBMESS, FIELD, VAL) \ if ((VAL) > (PBMESS).Get##FIELD()) { \ (PBMESS).Set##FIELD(VAL); \ } - + #define UPDATE_OPT_PB_FIELD_MAX(PBMESS, FIELD, VAL) \ if (!(PBMESS).Has##FIELD() || ((VAL) > (PBMESS).Get##FIELD())) { \ (PBMESS).Set##FIELD(VAL); \ diff --git a/library/cpp/protobuf/util/ya.make b/library/cpp/protobuf/util/ya.make index b62028af58..9d267d435f 100644 --- a/library/cpp/protobuf/util/ya.make +++ b/library/cpp/protobuf/util/ya.make @@ -1,26 +1,26 @@ LIBRARY() - + OWNER(mowgli) -PEERDIR( - contrib/libs/protobuf +PEERDIR( + contrib/libs/protobuf library/cpp/binsaver library/cpp/protobuf/util/proto library/cpp/string_utils/base64 -) - -SRCS( +) + +SRCS( is_equal.cpp iterators.h merge.cpp path.cpp pb_io.cpp - pb_utils.h + pb_utils.h repeated_field_utils.h simple_reflection.cpp walk.cpp -) - -END() +) + +END() RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/regex/pcre/regexp.cpp b/library/cpp/regex/pcre/regexp.cpp index 575c09cee4..dc288c2c61 100644 --- a/library/cpp/regex/pcre/regexp.cpp +++ b/library/cpp/regex/pcre/regexp.cpp @@ -137,7 +137,7 @@ protected: int CompileOptions; TString RegExpr; regex_t Preg; - + public: TRegExBaseImpl() : CompileOptions(0) @@ -156,8 +156,8 @@ public: regerror(rc, &Preg, errbuf, ERRBUF_SIZE); Error = "Error: regular expression " + re + " is wrong: " + errbuf; ythrow yexception() << "RegExp " << re << ": " << Error.data(); - } - } + } + } int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const { if (!RegExpr) { @@ -205,7 +205,7 @@ TRegExBase::TRegExBase(const TString& re, int cflags) { Compile(re, cflags); } -TRegExBase::~TRegExBase() { +TRegExBase::~TRegExBase() { } void TRegExBase::Compile(const TString& re, int cflags) { @@ -234,7 +234,7 @@ TRegExMatch::TRegExMatch(const char* re, int cflags) : TRegExBase(re, cflags) { } - + TRegExMatch::TRegExMatch(const TString& re, int cflags) : TRegExBase(re, cflags) { @@ -242,47 +242,47 @@ TRegExMatch::TRegExMatch(const TString& re, int cflags) bool TRegExMatch::Match(const char* str) const { return Exec(str, nullptr, 0, 0) == 0; -} - +} + TRegExSubst::TRegExSubst(const char* re, int cflags) : TRegExBase(re, cflags) , Replacement(nullptr) -{ - memset(Brfs, 0, sizeof(TBackReferences) * NMATCHES); -} - +{ + memset(Brfs, 0, sizeof(TBackReferences) * NMATCHES); +} + TString TRegExSubst::Replace(const char* str, int eflags) { TString s; - if (BrfsCount) { - if (Exec(str, PMatch, eflags) == 0) { + if (BrfsCount) { + if (Exec(str, PMatch, eflags) == 0) { int i; for (i = 0; i < BrfsCount; i++) { s += TString(Replacement, Brfs[i].Beg, Brfs[i].End - Brfs[i].Beg); - if (Brfs[i].Refer >= 0 && Brfs[i].Refer < NMATCHES) + if (Brfs[i].Refer >= 0 && Brfs[i].Refer < NMATCHES) s += TString(str, PMatch[Brfs[i].Refer].rm_so, int(PMatch[Brfs[i].Refer].rm_eo - PMatch[Brfs[i].Refer].rm_so)); } s += TString(Replacement, Brfs[i].Beg, Brfs[i].End - Brfs[i].Beg); } } else { - s = Replacement; + s = Replacement; } return s; } //*** // ��� ������������ ������ aaa.$1.$$$$.$2.bbb.$$$ccc Brfs ����� �����: -// {beg = 0, end = 4, Refer = 1} => "aaa." + $1_match -// {beg = 6, end = 8, Refer = -1} => ".$" -// {beg = 9, end = 10, Refer = -1} => "$" -// {beg = 11, end = 12, Refer = 2} => "." + $2_match -// {beg = 14, end = 20, Refer = -1} => ".bbb.$" -// {beg = 21, end = 22, Refer = -1} => "$" -// {beg = 22, end = 25, Refer = -1} => "ccc" -// {beg = 0, end = 0, Refer = 0} +// {beg = 0, end = 4, Refer = 1} => "aaa." + $1_match +// {beg = 6, end = 8, Refer = -1} => ".$" +// {beg = 9, end = 10, Refer = -1} => "$" +// {beg = 11, end = 12, Refer = 2} => "." + $2_match +// {beg = 14, end = 20, Refer = -1} => ".bbb.$" +// {beg = 21, end = 22, Refer = -1} => "$" +// {beg = 22, end = 25, Refer = -1} => "ccc" +// {beg = 0, end = 0, Refer = 0} //*** int TRegExSubst::ParseReplacement(const char* repl) { - Replacement = repl; - if (!Replacement || *Replacement == 0) + Replacement = repl; + if (!Replacement || *Replacement == 0) return 0; char* pos = (char*)Replacement; char* pos1 = nullptr; @@ -290,7 +290,7 @@ int TRegExSubst::ParseReplacement(const char* repl) { int i = 0; while (pos && *pos && i < NMATCHES) { pos1 = strchr(pos, '$'); - Brfs[i].Refer = -1; + Brfs[i].Refer = -1; pos2 = pos1; if (pos1) { pos2 = pos1 + 1; @@ -302,16 +302,16 @@ int TRegExSubst::ParseReplacement(const char* repl) { pos1++; if (*pos2 == '$') pos2++; - Brfs[i].Refer = -1; + Brfs[i].Refer = -1; } } - Brfs[i].Beg = int(pos - (char*)Replacement); + Brfs[i].Beg = int(pos - (char*)Replacement); Brfs[i].End = (pos1 == nullptr ? (int)strlen(Replacement) : int(pos1 - Replacement)); pos = pos2; i++; } - Brfs[i].Beg = Brfs[i].End = 0; - Brfs[i].Refer = -1; - BrfsCount = i; - return BrfsCount; + Brfs[i].Beg = Brfs[i].End = 0; + Brfs[i].Refer = -1; + BrfsCount = i; + return BrfsCount; } diff --git a/library/cpp/regex/pcre/regexp.h b/library/cpp/regex/pcre/regexp.h index bc610bd2f3..9862a9b85b 100644 --- a/library/cpp/regex/pcre/regexp.h +++ b/library/cpp/regex/pcre/regexp.h @@ -17,15 +17,15 @@ class TRegExBaseImpl; class TRegExBase { -protected: +protected: TSimpleIntrusivePtr<TRegExBaseImpl> Impl; -public: +public: TRegExBase(const char* regExpr = nullptr, int cflags = REG_EXTENDED); TRegExBase(const TString& regExpr, int cflags = REG_EXTENDED); virtual ~TRegExBase(); - + int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches = NMATCHES) const; void Compile(const TString& regExpr, int cflags = REG_EXTENDED); bool IsCompiled() const; @@ -34,30 +34,30 @@ public: }; class TRegExMatch: public TRegExBase { -public: +public: TRegExMatch(const char* regExpr = nullptr, int cflags = REG_NOSUB | REG_EXTENDED); TRegExMatch(const TString& regExpr, int cflags = REG_NOSUB | REG_EXTENDED); bool Match(const char* str) const; -}; +}; struct TBackReferences { - int Beg; - int End; - int Refer; -}; + int Beg; + int End; + int Refer; +}; class TRegExSubst: public TRegExBase { -private: - const char* Replacement; +private: + const char* Replacement; regmatch_t PMatch[NMATCHES]; - - TBackReferences Brfs[NMATCHES]; - int BrfsCount; - -public: + + TBackReferences Brfs[NMATCHES]; + int BrfsCount; + +public: TRegExSubst(const char* regExpr = nullptr, int cflags = REG_EXTENDED); - + TString Replace(const char* str, int eflags = 0); int ParseReplacement(const char* replacement); }; diff --git a/library/cpp/streams/zc_memory_input/zc_memory_input.h b/library/cpp/streams/zc_memory_input/zc_memory_input.h index c939d8e426..3880959afd 100644 --- a/library/cpp/streams/zc_memory_input/zc_memory_input.h +++ b/library/cpp/streams/zc_memory_input/zc_memory_input.h @@ -1,48 +1,48 @@ -#pragma once - -#include <util/stream/mem.h> -#include <util/system/defaults.h> +#pragma once + +#include <util/stream/mem.h> +#include <util/system/defaults.h> #include <util/generic/yexception.h> - -/// Zero-copy memory input with fixed read + +/// Zero-copy memory input with fixed read class TZCMemoryInput: public TMemoryInput { -public: +public: TZCMemoryInput() { } - TZCMemoryInput(const char* dataPtr, size_t size) - : TMemoryInput(dataPtr, size) + TZCMemoryInput(const char* dataPtr, size_t size) + : TMemoryInput(dataPtr, size) { } - TZCMemoryInput(TMemoryInput& rhs) - : TMemoryInput(rhs.Buf(), rhs.Avail()) + TZCMemoryInput(TMemoryInput& rhs) + : TMemoryInput(rhs.Buf(), rhs.Avail()) { } - /// if there's 'size' data read it, otherwise just return false + /// if there's 'size' data read it, otherwise just return false Y_FORCE_INLINE bool ReadFixed(const char*& buf, size_t size) { - if (Avail() >= size) { - buf = Buf(); - Reset(Buf() + size, Avail() - size); - return true; - } - return false; - } - + if (Avail() >= size) { + buf = Buf(); + Reset(Buf() + size, Avail() - size); + return true; + } + return false; + } + template <class T> Y_FORCE_INLINE T LoadPOD() { const char* buf = nullptr; - if (!ReadFixed(buf, sizeof(T))) + if (!ReadFixed(buf, sizeof(T))) ythrow yexception() << "TZCMemoryInput::LoadPOD failed: not enough data (" - << Avail() << " of " << sizeof(T) << " bytes)"; + << Avail() << " of " << sizeof(T) << " bytes)"; T res; memcpy(&res, buf, sizeof(T)); return res; } - + template <class T> Y_FORCE_INLINE void ReadPOD(T& x) { - x = LoadPOD<T>(); - } -}; + x = LoadPOD<T>(); + } +}; diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 305bc6b40f..1610d5d39b 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -651,7 +651,7 @@ int NUnitTest::RunMain(int argc, char** argv) { InitNetworkSubSystem(); try { - GetExecPath(); + GetExecPath(); } catch (...) { } diff --git a/library/cpp/threading/local_executor/local_executor.h b/library/cpp/threading/local_executor/local_executor.h index c1c824f67c..0bf5db9304 100644 --- a/library/cpp/threading/local_executor/local_executor.h +++ b/library/cpp/threading/local_executor/local_executor.h @@ -7,7 +7,7 @@ #include <util/generic/noncopyable.h> #include <util/generic/ptr.h> #include <util/generic/singleton.h> -#include <util/generic/ymath.h> +#include <util/generic/ymath.h> #include <functional> diff --git a/library/cpp/xml/ya.make b/library/cpp/xml/ya.make index 5a685b70e6..a83e9eb31d 100644 --- a/library/cpp/xml/ya.make +++ b/library/cpp/xml/ya.make @@ -4,9 +4,9 @@ RECURSE( encode encode/ut init - parslib + parslib parslib/ut - sax + sax sax/ut validator validator/ut diff --git a/tools/ya.make b/tools/ya.make index 51a6b8b426..a0e6418a7c 100644 --- a/tools/ya.make +++ b/tools/ya.make @@ -169,7 +169,7 @@ RECURSE( unpack_staff_cert untranslit_test untranslit_test/tests - url + url urlmenuindexer urlseq_print voice diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..721b9c0513 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -26,8 +26,8 @@ using TCharTemp = TTempArray<wchar16>; namespace NDetail { inline TString InStringMsg(const char* s, size_t len) { return (len <= 50) ? " in string " + TString(s, len).Quote() : TString(); - } - + } + template <bool isPointer> struct TSelector; diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..9eebbf5387 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -500,12 +500,12 @@ void TConversionTest::TestUTF8ToWide() { UNIT_ASSERT(w == wideLatinAlphabet); w = UTF8ToWide(utf8CyrillicAlphabet, strlen(utf8CyrillicAlphabet)); UNIT_ASSERT(w == wideCyrillicAlphabet); - - const char* utf8NonBMP = "\xf4\x80\x89\x84\xf4\x80\x89\x87\xf4\x80\x88\xba"; + + const char* utf8NonBMP = "\xf4\x80\x89\x84\xf4\x80\x89\x87\xf4\x80\x88\xba"; wchar16 wNonBMPDummy[] = {0xDBC0, 0xDE44, 0xDBC0, 0xDE47, 0xDBC0, 0xDE3A}; TestSurrogates(utf8NonBMP, wNonBMPDummy, Y_ARRAY_SIZE(wNonBMPDummy)); - - const char* utf8NonBMP2 = "ab\xf4\x80\x89\x87n"; + + const char* utf8NonBMP2 = "ab\xf4\x80\x89\x87n"; wchar16 wNonBMPDummy2[] = {'a', 'b', 0xDBC0, 0xDE47, 'n'}; TestSurrogates(utf8NonBMP2, wNonBMPDummy2, Y_ARRAY_SIZE(wNonBMPDummy2)); diff --git a/util/datetime/constants.h b/util/datetime/constants.h index 352403270e..63022d73a8 100644 --- a/util/datetime/constants.h +++ b/util/datetime/constants.h @@ -1,7 +1,7 @@ -#pragma once - +#pragma once + #include <time.h> - -const time_t SECONDS_IN_DAY = 86400; -const time_t SECONDS_IN_HOUR = 3600; + +const time_t SECONDS_IN_DAY = 86400; +const time_t SECONDS_IN_HOUR = 3600; const time_t SECONDS_IN_HALFHOUR = 1800; diff --git a/util/draft/date.cpp b/util/draft/date.cpp index a290c46050..314b1ccd9a 100644 --- a/util/draft/date.cpp +++ b/util/draft/date.cpp @@ -3,18 +3,18 @@ #include <util/string/cast.h> #include <util/generic/yexception.h> #include <util/datetime/base.h> - + time_t GetDateStart(time_t ts) { - tm dateTm; - memset(&dateTm, 0, sizeof(tm)); - localtime_r(&ts, &dateTm); + tm dateTm; + memset(&dateTm, 0, sizeof(tm)); + localtime_r(&ts, &dateTm); dateTm.tm_isdst = -1; - dateTm.tm_sec = 0; - dateTm.tm_min = 0; - dateTm.tm_hour = 0; - return mktime(&dateTm); + dateTm.tm_sec = 0; + dateTm.tm_min = 0; + dateTm.tm_hour = 0; + return mktime(&dateTm); } static time_t ParseDate(const char* date, const char* format) { @@ -34,11 +34,11 @@ static time_t ParseDate(const char* dateStr) { return ParseDate(dateStr, "%Y%m%d"); } -template <> -TDate FromStringImpl<TDate>(const char* data, size_t len) { +template <> +TDate FromStringImpl<TDate>(const char* data, size_t len) { return TDate(ParseDate(TString(data, len).data())); -} - +} + TDate::TDate(const char* yyyymmdd) : Timestamp(GetDateStart(ParseDate(yyyymmdd))) { @@ -60,18 +60,18 @@ TDate::TDate(const TString& date, const TString& format) } TDate::TDate(unsigned year, unsigned month, unsigned monthDay) { - tm dateTm; - Zero(dateTm); + tm dateTm; + Zero(dateTm); dateTm.tm_year = year - 1900; dateTm.tm_mon = month - 1; dateTm.tm_mday = monthDay; - dateTm.tm_isdst = -1; - Timestamp = mktime(&dateTm); + dateTm.tm_isdst = -1; + Timestamp = mktime(&dateTm); if (Timestamp == (time_t)-1) { - ythrow yexception() << "Invalid TDate args:(" << year << ',' << month << ',' << monthDay << ')'; + ythrow yexception() << "Invalid TDate args:(" << year << ',' << month << ',' << monthDay << ')'; } -} - +} + time_t TDate::GetStartUTC() const { tm dateTm; localtime_r(&Timestamp, &dateTm); @@ -83,31 +83,31 @@ time_t TDate::GetStartUTC() const { } TString TDate::ToStroka(const char* format) const { - tm dateTm; - localtime_r(&Timestamp, &dateTm); + tm dateTm; + localtime_r(&Timestamp, &dateTm); return Strftime(format, &dateTm); } unsigned TDate::GetWeekDay() const { - tm dateTm; - localtime_r(&Timestamp, &dateTm); - return (unsigned)dateTm.tm_wday; -} - + tm dateTm; + localtime_r(&Timestamp, &dateTm); + return (unsigned)dateTm.tm_wday; +} + unsigned TDate::GetYear() const { - tm dateTm; - localtime_r(&Timestamp, &dateTm); - return ((unsigned)dateTm.tm_year) + 1900; -} - + tm dateTm; + localtime_r(&Timestamp, &dateTm); + return ((unsigned)dateTm.tm_year) + 1900; +} + unsigned TDate::GetMonth() const { - tm dateTm; - localtime_r(&Timestamp, &dateTm); - return ((unsigned)dateTm.tm_mon) + 1; -} - + tm dateTm; + localtime_r(&Timestamp, &dateTm); + return ((unsigned)dateTm.tm_mon) + 1; +} + unsigned TDate::GetMonthDay() const { - tm dateTm; - localtime_r(&Timestamp, &dateTm); - return (unsigned)dateTm.tm_mday; -} + tm dateTm; + localtime_r(&Timestamp, &dateTm); + return (unsigned)dateTm.tm_mday; +} diff --git a/util/draft/date.h b/util/draft/date.h index e3eb616fe5..0e0b1d7a36 100644 --- a/util/draft/date.h +++ b/util/draft/date.h @@ -29,10 +29,10 @@ public: TDate(const char* yyyymmdd); TDate(const TString& yyyymmdd); - TDate(unsigned year, unsigned month, unsigned monthDay); // month from 01, monthDay from 01 + TDate(unsigned year, unsigned month, unsigned monthDay); // month from 01, monthDay from 01 TDate(const TString& date, const TString& format); - - explicit TDate(time_t t); + + explicit TDate(time_t t); time_t GetStart() const { return Timestamp; @@ -54,28 +54,28 @@ public: TDate& operator+=(unsigned days) { Timestamp = GetDateStart(Timestamp + days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2); - return *this; - } - + return *this; + } + TDate& operator-=(unsigned days) { Timestamp = GetDateStart(Timestamp - days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2); - return *this; - } - + return *this; + } + TDate operator+(unsigned days) const { return TDate(Timestamp + days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2); - } - + } + TDate operator-(unsigned days) const { return TDate(Timestamp - days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2); - } - - unsigned GetWeekDay() const; // days since Sunday - - unsigned GetYear() const; + } + + unsigned GetWeekDay() const; // days since Sunday + + unsigned GetYear() const; unsigned GetMonth() const; // from 01 - unsigned GetMonthDay() const; // from 01 - + unsigned GetMonthDay() const; // from 01 + friend bool operator<(const TDate& left, const TDate& right); friend bool operator>(const TDate& left, const TDate& right); friend bool operator<=(const TDate& left, const TDate& right); diff --git a/util/draft/date_ut.cpp b/util/draft/date_ut.cpp index 8c33a6c1cf..5320087abf 100644 --- a/util/draft/date_ut.cpp +++ b/util/draft/date_ut.cpp @@ -1,29 +1,29 @@ -#include "date.h" - +#include "date.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TDateTest) { Y_UNIT_TEST(ComponentsTest) { - { - TDate d("20110215"); - UNIT_ASSERT_EQUAL(d.GetYear(), 2011); - UNIT_ASSERT_EQUAL(d.GetMonth(), 2); - UNIT_ASSERT_EQUAL(d.GetMonthDay(), 15); + { + TDate d("20110215"); + UNIT_ASSERT_EQUAL(d.GetYear(), 2011); + UNIT_ASSERT_EQUAL(d.GetMonth(), 2); + UNIT_ASSERT_EQUAL(d.GetMonthDay(), 15); UNIT_ASSERT_EQUAL(d.ToStroka("%Y%m%d"), "20110215"); UNIT_ASSERT_EQUAL(d.ToStroka(), "20110215"); UNIT_ASSERT_EQUAL(d.ToStroka("%Y--%m--%d"), "2011--02--15"); UNIT_ASSERT_EQUAL(d.ToStroka("%U"), "07"); UNIT_ASSERT_EQUAL(d.GetStartUTC(), 1297728000); - } - { + } + { TDate d(2005, 6, 3); - UNIT_ASSERT_EQUAL(d.GetYear(), 2005); - UNIT_ASSERT_EQUAL(d.GetMonth(), 6); - UNIT_ASSERT_EQUAL(d.GetMonthDay(), 3); + UNIT_ASSERT_EQUAL(d.GetYear(), 2005); + UNIT_ASSERT_EQUAL(d.GetMonth(), 6); + UNIT_ASSERT_EQUAL(d.GetMonthDay(), 3); UNIT_ASSERT_EQUAL(d.ToStroka(), "20050603"); UNIT_ASSERT_EQUAL(d.ToStroka("____%Y__%m____%d"), "____2005__06____03"); UNIT_ASSERT_EQUAL(d.GetStartUTC(), 1117756800); - } + } { TDate d("2011-02-15", "%Y-%m-%d"); UNIT_ASSERT_EQUAL(d.GetYear(), 2011); @@ -32,5 +32,5 @@ Y_UNIT_TEST_SUITE(TDateTest) { UNIT_ASSERT_EQUAL(d.ToStroka("%Y%m%d"), "20110215"); UNIT_ASSERT_EQUAL(d.GetStartUTC(), 1297728000); } - } -} + } +} diff --git a/util/draft/datetime.cpp b/util/draft/datetime.cpp index 5cbe7d8847..cd6a2462cc 100644 --- a/util/draft/datetime.cpp +++ b/util/draft/datetime.cpp @@ -1,15 +1,15 @@ #include "datetime.h" -#include <util/ysaveload.h> - +#include <util/ysaveload.h> + #include <util/system/atomic.h> #include <util/system/fasttime.h> #include <util/datetime/base.h> #include <util/datetime/systime.h> #include <util/stream/output.h> -#include <util/stream/mem.h> -#include <util/string/cast.h> -#include <util/string/printf.h> +#include <util/stream/mem.h> +#include <util/string/cast.h> +#include <util/string/printf.h> namespace NDatetime { const ui32 MonthDays[2][12] = { @@ -213,25 +213,25 @@ namespace NDatetime { return t; } } - + template <> void In<TMonth>(IInputStream& in, TMonth& t) { - char buf[4]; - LoadPodArray(&in, buf, 4); + char buf[4]; + LoadPodArray(&in, buf, 4); t.Year = FromString<ui16>(buf, 4); - LoadPodArray(&in, buf, 2); + LoadPodArray(&in, buf, 2); t.Month = ui8(FromString<ui16>(buf, 2)) - 1; -} - +} + template <> void Out<TMonth>(IOutputStream& o, const TMonth& t) { - o << t.Year << Sprintf("%.2hu", (ui16)(t.Month + 1)); -} - + o << t.Year << Sprintf("%.2hu", (ui16)(t.Month + 1)); +} + template <> TMonth FromStringImpl<TMonth, char>(const char* s, size_t len) { - TMonth res; + TMonth res; TMemoryInput in(s, len); - in >> res; - return res; -} + in >> res; + return res; +} diff --git a/util/draft/datetime.h b/util/draft/datetime.h index 8a387ea6f1..125adff6ab 100644 --- a/util/draft/datetime.h +++ b/util/draft/datetime.h @@ -8,8 +8,8 @@ #include <cstdlib> -#include <time.h> - +#include <time.h> + namespace NDatetime { extern const ui32 MonthDays[2][12]; // !leapYear; !!leapYear extern const ui32 MonthDaysNewYear[2][13]; // !leapYear; !!leapYear @@ -132,53 +132,53 @@ namespace NDatetime { } }; } - + inline TString date2str(const time_t date) { struct tm dateTm; memset(&dateTm, 0, sizeof(dateTm)); localtime_r(&date, &dateTm); - char buf[9]; + char buf[9]; strftime(buf, sizeof(buf), "%Y%m%d", &dateTm); return TString(buf); -} - +} + inline time_t str2date(const TString& dateStr) { struct tm dateTm; - memset(&dateTm, 0, sizeof(tm)); + memset(&dateTm, 0, sizeof(tm)); strptime(dateStr.data(), "%Y%m%d", &dateTm); - return mktime(&dateTm); -} - -// checks whether time2 > time1 and close enough to it + return mktime(&dateTm); +} + +// checks whether time2 > time1 and close enough to it inline bool AreTimesSeqAndClose(time_t time1, time_t time2, time_t closeInterval = 10) { - return (time2 - time1) <= closeInterval; -} - -// checks whether time2 and time1 are close enough + return (time2 - time1) <= closeInterval; +} + +// checks whether time2 and time1 are close enough inline bool AreTimesClose(time_t time1, time_t time2, time_t closeInterval = 10) { return std::abs(time2 - time1) <= closeInterval; -} - -//////////////////////////////// - +} + +//////////////////////////////// + struct TMonth { - ui16 Year; + ui16 Year; ui8 Month; - - TMonth(ui16 year = 0, ui8 month = 0) - : Year(year) - , Month(month) + + TMonth(ui16 year = 0, ui8 month = 0) + : Year(year) + , Month(month) { } - + TMonth operator-(ui16 n) { - if (n <= Month) { + if (n <= Month) { return TMonth(Year, Month - (ui8)n); - } else { - n -= Month; - return (n % 12) ? TMonth(Year - 1 - (n / 12), 12 - (n % 12)) : TMonth(Year - (n / 12), 0); - } - } -}; + } else { + n -= Month; + return (n % 12) ? TMonth(Year - 1 - (n / 12), 12 - (n % 12)) : TMonth(Year - (n / 12), 0); + } + } +}; Y_DECLARE_PODTYPE(NDatetime::TSimpleTM); diff --git a/util/draft/enum.h b/util/draft/enum.h index 18002b7df2..2939099b5e 100644 --- a/util/draft/enum.h +++ b/util/draft/enum.h @@ -1,16 +1,16 @@ #pragma once - + #include <bitset> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/stream/str.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/string/split.h> #include <utility> - + class TEnumNotFoundException: public yexception { -}; - +}; + #define EnumFromString(key, entries) EnumFromStringImpl(key, entries, Y_ARRAY_SIZE(entries)) #define EnumFromStringWithSize(key, entries, size) EnumFromStringImpl(key, entries, size) #define FindEnumFromString(key, entries) FindEnumFromStringImpl(key, entries, Y_ARRAY_SIZE(entries)) @@ -18,24 +18,24 @@ class TEnumNotFoundException: public yexception { #define EnumToString(key, entries) EnumToStringImpl(key, entries, Y_ARRAY_SIZE(entries)) #define EnumToStringWithSize(key, entries, size) EnumToStringImpl(key, entries, size) #define PrintEnumItems(entries) PrintEnumItemsImpl(entries, Y_ARRAY_SIZE(entries)) - + template <class K1, class K2, class V> const V* FindEnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t arraySize) { - for (size_t i = 0; i < arraySize; i++) - if (entries[i].first == key) - return &entries[i].second; + for (size_t i = 0; i < arraySize; i++) + if (entries[i].first == key) + return &entries[i].second; return nullptr; -} - +} + // special version for const char* template <class V> const V* FindEnumFromStringImpl(const char* key, const std::pair<const char*, V>* entries, size_t arraySize) { - for (size_t i = 0; i < arraySize; i++) - if (entries[i].first && key && !strcmp(entries[i].first, key)) - return &entries[i].second; + for (size_t i = 0; i < arraySize; i++) + if (entries[i].first && key && !strcmp(entries[i].first, key)) + return &entries[i].second; return nullptr; -} - +} + template <class K, class V> TString PrintEnumItemsImpl(const std::pair<K, V>* entries, size_t arraySize) { TString result; @@ -57,18 +57,18 @@ TString PrintEnumItemsImpl(const std::pair<const char*, V>* entries, size_t arra template <class K1, class K2, class V> const V* EnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t arraySize) { - const V* res = FindEnumFromStringImpl(key, entries, arraySize); - if (res) - return res; + const V* res = FindEnumFromStringImpl(key, entries, arraySize); + if (res) + return res; ythrow TEnumNotFoundException() << "Key '" << key << "' not found in enum. Valid options are: " << PrintEnumItemsImpl(entries, arraySize) << ". "; -} - +} + template <class K, class V> const K* EnumToStringImpl(V value, const std::pair<K, V>* entries, size_t arraySize) { - for (size_t i = 0; i < arraySize; i++) - if (entries[i].second == value) - return &entries[i].first; + for (size_t i = 0; i < arraySize; i++) + if (entries[i].second == value) + return &entries[i].first; TEnumNotFoundException exc; exc << "Value '" << int(value) << "' not found in enum. Valid values are: "; @@ -76,10 +76,10 @@ const K* EnumToStringImpl(V value, const std::pair<K, V>* entries, size_t arrayS exc << (i ? ", " : "") << int(entries[i].second); exc << ". "; ythrow exc; -} - -/////////////////////////////////// - +} + +/////////////////////////////////// + template <class B> inline void SetEnumFlagsForEmptySpec(B& flags, bool allIfEmpty) { if (allIfEmpty) { @@ -89,18 +89,18 @@ inline void SetEnumFlagsForEmptySpec(B& flags, bool allIfEmpty) { } } -// all set by default +// all set by default template <class E, size_t N, size_t B> inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TStringBuf optSpec, std::bitset<B>& flags, bool allIfEmpty = true) { - if (optSpec.empty()) { + if (optSpec.empty()) { SetEnumFlagsForEmptySpec(flags, allIfEmpty); } else { flags.reset(); for (const auto& it : StringSplitter(optSpec).Split(',')) { E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, N); flags.set(e); - } + } } } @@ -110,14 +110,14 @@ inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf o bool allIfEmpty = true) { if (optSpec.empty()) { SetEnumFlagsForEmptySpec(flags, allIfEmpty); - } else { + } else { flags.reset(); for (const auto& it : StringSplitter(optSpec).Split(',')) { E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, size); flags.set(e); - } - } -} + } + } +} // for enums generated with GENERATE_ENUM_SERIALIZATION template <class E, size_t B> @@ -128,7 +128,7 @@ inline void SetEnumFlags(TStringBuf optSpec, std::bitset<B>& flags, bool allIfEm flags.reset(); for (const auto& it : StringSplitter(optSpec).Split(',')) { E e; - if (!TryFromString(it.Token(), e)) + if (!TryFromString(it.Token(), e)) ythrow yexception() << "Unknown enum value '" << it.Token() << "'"; flags.set((size_t)e); } diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h index 1c62055bd9..0aff81648b 100644 --- a/util/draft/holder_vector.h +++ b/util/draft/holder_vector.h @@ -1,46 +1,46 @@ #pragma once - + #include <util/generic/ptr.h> #include <util/generic/vector.h> #include <util/generic/noncopyable.h> - + template <class T, class D = TDelete> class THolderVector: public TVector<T*>, public TNonCopyable { using TBase = TVector<T*>; -public: +public: explicit THolderVector(size_t n = 0) : TBase(n) { } - ~THolderVector() { + ~THolderVector() { Clear(); } void Clear() { - for (typename TBase::iterator it = TBase::begin(); it != TBase::end(); ++it) { + for (typename TBase::iterator it = TBase::begin(); it != TBase::end(); ++it) { if (*it) D::Destroy(*it); - } + } TBase::clear(); - } - - size_t Size() const { - return TBase::size(); - } - + } + + size_t Size() const { + return TBase::size(); + } + // TVector takes ownership of T - void PushBack(T* t) { - try { + void PushBack(T* t) { + try { TBase::push_back(t); } catch (...) { if (t) D::Destroy(t); throw; - } - } - + } + } + void PushBack(std::unique_ptr<T> t) { PushBack(t.release()); } @@ -82,9 +82,9 @@ public: TBase::swap(other); } - using TBase::operator[]; + using TBase::operator[]; using TBase::operator bool; - using TBase::at; + using TBase::at; using TBase::back; using TBase::begin; using TBase::capacity; @@ -99,4 +99,4 @@ public: using typename TBase::iterator; using typename TBase::reverse_iterator; using typename TBase::value_type; -}; +}; diff --git a/util/draft/ip.h b/util/draft/ip.h index eb947cd2cd..04db85ae24 100644 --- a/util/draft/ip.h +++ b/util/draft/ip.h @@ -1,48 +1,48 @@ -#pragma once - -#include <util/digest/murmur.h> - -#include <util/network/ip.h> - -#include <util/str_stl.h> +#pragma once + +#include <util/digest/murmur.h> + +#include <util/network/ip.h> + +#include <util/str_stl.h> #include <util/generic/maybe.h> #include <util/generic/variant.h> - -#ifdef _unix_ + +#ifdef _unix_ #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> -#endif // _unix_ - -#include <string.h> - -#ifndef INET6_ADDRSTRLEN +#endif // _unix_ + +#include <string.h> + +#ifndef INET6_ADDRSTRLEN #define INET6_ADDRSTRLEN 46 -#endif - -// Network (big-endian) byte order +#endif + +// Network (big-endian) byte order using TIp4 = TIpHost; - -// Network (big-endian) byte order + +// Network (big-endian) byte order struct TIp6 { - char Data[16]; - - bool operator==(const TIp6& rhs) const { - return memcmp(Data, rhs.Data, sizeof(Data)) == 0; - } + char Data[16]; + + bool operator==(const TIp6& rhs) const { + return memcmp(Data, rhs.Data, sizeof(Data)) == 0; + } bool operator<(const TIp6& rhs) const { return memcmp(Data, rhs.Data, sizeof(Data)) < 0; } -}; - -template <> -struct THash<TIp6> { - inline size_t operator()(const TIp6& ip) const { - return MurmurHash<size_t>((const void*)ip.Data, 16); - } -}; - +}; + +template <> +struct THash<TIp6> { + inline size_t operator()(const TIp6& ip) const { + return MurmurHash<size_t>((const void*)ip.Data, 16); + } +}; + static inline TIp6 Ip6FromIp4(TIp4 addr) { TIp6 res; memset(res.Data, 0, sizeof(res.Data)); @@ -52,16 +52,16 @@ static inline TIp6 Ip6FromIp4(TIp4 addr) { return res; } -static inline TIp6 Ip6FromString(const char* ipStr) { - TIp6 res; - - if (inet_pton(AF_INET6, ipStr, &res.Data) == 0) { +static inline TIp6 Ip6FromString(const char* ipStr) { + TIp6 res; + + if (inet_pton(AF_INET6, ipStr, &res.Data) == 0) { ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv6 address"; - } - - return res; -} - + } + + return res; +} + static inline TMaybe<TIp6> TryParseIp6FromString(const char* ipStr) { TIp6 res; @@ -72,60 +72,60 @@ static inline TMaybe<TIp6> TryParseIp6FromString(const char* ipStr) { return res; } -static inline char* Ip6ToString(const TIp6& ip, char* buf, size_t len) { - if (!inet_ntop(AF_INET6, (void*)&ip.Data, buf, (socklen_t)len)) { - ythrow TSystemError() << "Failed to get ipv6 address string"; - } - - return buf; -} - +static inline char* Ip6ToString(const TIp6& ip, char* buf, size_t len) { + if (!inet_ntop(AF_INET6, (void*)&ip.Data, buf, (socklen_t)len)) { + ythrow TSystemError() << "Failed to get ipv6 address string"; + } + + return buf; +} + static inline TString Ip6ToString(const TIp6& ip) { - char buf[INET6_ADDRSTRLEN]; - + char buf[INET6_ADDRSTRLEN]; + return TString(Ip6ToString(ip, buf, sizeof(buf))); -} - +} + template <> inline void Out<TIp6>(IOutputStream& os, const TIp6& a) { os << Ip6ToString(a); } using TIp4Or6 = std::variant<TIp4, TIp6>; - -static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) { - const char* c = ipStr; - for (; *c; ++c) { - if (*c == '.') { - return IpFromString(ipStr); - } - if (*c == ':') { - return Ip6FromString(ipStr); - } - } + +static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) { + const char* c = ipStr; + for (; *c; ++c) { + if (*c == '.') { + return IpFromString(ipStr); + } + if (*c == ':') { + return Ip6FromString(ipStr); + } + } ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv4 or ipv6 address"; -} - +} + static inline TString Ip4Or6ToString(const TIp4Or6& ip) { if (std::holds_alternative<TIp6>(ip)) { return Ip6ToString(std::get<TIp6>(ip)); - } else { + } else { return IpToString(std::get<TIp4>(ip)); - } -} - -// for TIp4 or TIp6, not TIp4Or6 + } +} + +// for TIp4 or TIp6, not TIp4Or6 template <class TIp> struct TIpCompare { - bool Less(const TIp& l, const TIp& r) const { - return memcmp(&l, &r, sizeof(TIp)) < 0; - } - - bool LessEqual(const TIp& l, const TIp& r) const { - return memcmp(&l, &r, sizeof(TIp)) <= 0; - } - - bool operator()(const TIp& l, const TIp& r) const { - return Less(l, r); - } -}; + bool Less(const TIp& l, const TIp& r) const { + return memcmp(&l, &r, sizeof(TIp)) < 0; + } + + bool LessEqual(const TIp& l, const TIp& r) const { + return memcmp(&l, &r, sizeof(TIp)) <= 0; + } + + bool operator()(const TIp& l, const TIp& r) const { + return Less(l, r); + } +}; diff --git a/util/draft/memory.h b/util/draft/memory.h index 0a9722bb36..1f7298d7ec 100644 --- a/util/draft/memory.h +++ b/util/draft/memory.h @@ -1,40 +1,40 @@ -#pragma once - +#pragma once + #include <util/system/defaults.h> -#include <algorithm> -#include <functional> -#include <utility> - +#include <algorithm> +#include <functional> +#include <utility> + template <class T> inline bool IsZero(const T* begin, const T* end) { return std::find_if(begin, end, [](const T& other) { return other != T(0); }) == end; -} - +} + template <size_t Size> inline bool IsZero(const char* p) { size_t sizeInUI64 = Size / 8; const char* pEndUi64 = p + sizeInUI64 * 8; - if (sizeInUI64 && !IsZero<ui64>((const ui64*)p, (const ui64*)pEndUi64)) - return false; - return IsZero(pEndUi64, p + Size); -} - + if (sizeInUI64 && !IsZero<ui64>((const ui64*)p, (const ui64*)pEndUi64)) + return false; + return IsZero(pEndUi64, p + Size); +} + #define IS_ZERO_INTSZ(INT) \ template <> \ inline bool IsZero<sizeof(INT)>(const char* p) { \ return (*(INT*)p) == INT(0); \ } - -IS_ZERO_INTSZ(ui8) -IS_ZERO_INTSZ(ui16) -IS_ZERO_INTSZ(ui32) -IS_ZERO_INTSZ(ui64) - -#undef IS_ZERO_INTSZ - -// If you want to use this to check all fields in a struct make sure it's w/o holes or #pragma pack(1) + +IS_ZERO_INTSZ(ui8) +IS_ZERO_INTSZ(ui16) +IS_ZERO_INTSZ(ui32) +IS_ZERO_INTSZ(ui64) + +#undef IS_ZERO_INTSZ + +// If you want to use this to check all fields in a struct make sure it's w/o holes or #pragma pack(1) template <class T> bool IsZero(const T& t) { - return IsZero<sizeof(T)>((const char*)&t); -} + return IsZero<sizeof(T)>((const char*)&t); +} diff --git a/util/draft/memory_ut.cpp b/util/draft/memory_ut.cpp index 76bee30549..d683c870db 100644 --- a/util/draft/memory_ut.cpp +++ b/util/draft/memory_ut.cpp @@ -1,28 +1,28 @@ #include "memory.h" #include <library/cpp/testing/unittest/registar.h> - -#pragma pack(1) + +#pragma pack(1) struct Y_PACKED TSampleStruct1 { - ui8 A; - ui8 B; -}; - -#pragma pack(1) + ui8 A; + ui8 B; +}; + +#pragma pack(1) struct Y_PACKED TSampleStruct2 { - ui8 A; - ui16 B; - i32 C; -}; - -#pragma pack(1) + ui8 A; + ui16 B; + i32 C; +}; + +#pragma pack(1) struct Y_PACKED TSampleStruct3 { - TSampleStruct2 A; - ui64 B; -}; - -#pragma pack() - + TSampleStruct2 A; + ui64 B; +}; + +#pragma pack() + Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) { Y_UNIT_TEST(IsZeroTest) { ui8 a1 = 0; @@ -34,7 +34,7 @@ Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) { UNIT_ASSERT(!IsZero(a2)); a2 = 0; UNIT_ASSERT(IsZero(a2)); - + double a3 = 0.0; UNIT_ASSERT(IsZero(a3)); a3 = 1.e-13; @@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) { ss1.A = 0; ss1.B = 12; UNIT_ASSERT(!IsZero(ss1)); - + TSampleStruct2 ss2; ss2.A = 0; ss2.B = 100; @@ -55,7 +55,7 @@ Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) { UNIT_ASSERT(!IsZero(ss2)); ss2.B = 0; UNIT_ASSERT(IsZero(ss2)); - + TSampleStruct3 ss3; ss3.A = ss2; ss3.B = 0; @@ -66,4 +66,4 @@ Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) { ss3.A.C = -789; UNIT_ASSERT(!IsZero(ss3)); } -} +} diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..8c03084069 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -375,12 +375,12 @@ char GetDirectorySeparator() { const char* GetDirectorySeparatorS() { return LOCSLASH_S; } - + void RemoveDirWithContents(TString dirName) { - SlashFolderLocal(dirName); - + SlashFolderLocal(dirName); + TDirIterator dir(dirName, TDirIterator::TOptions(FTS_NOSTAT)); - + for (auto it = dir.begin(); it != dir.end(); ++it) { switch (it->fts_info) { case FTS_F: @@ -392,8 +392,8 @@ void RemoveDirWithContents(TString dirName) { ythrow TSystemError() << "error while removing " << it->fts_path; break; } - } -} + } +} int mkpath(char* path, int mode) { return NFs::MakeDirectoryRecursive(path, NFs::EFilePermission(mode)) ? 0 : -1; diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..456f1f6ebb 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -18,15 +18,15 @@ #include <time.h> #include <io.h> #include "dirent_win.h" - + // these live in mktemp_system.cpp extern "C" int mkstemps(char* path, int slen); char* mkdtemp(char* path); - + #else #ifdef _sun_ #include <alloca.h> - + char* mkdtemp(char* path); #endif #include <unistd.h> @@ -44,7 +44,7 @@ int mkpath(char* path, int mode = 0777); TString GetHomeDir(); void MakeDirIfNotExist(const char* path, int mode = 0777); - + inline void MakeDirIfNotExist(const TString& path, int mode = 0777) { MakeDirIfNotExist(path.data(), mode); } @@ -60,7 +60,7 @@ char GetDirectorySeparator(); const char* GetDirectorySeparatorS(); void RemoveDirWithContents(TString dirName); - + const char* GetFileNameComponent(const char* f); inline TString GetFileNameComponent(const TString& f) { diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp index b21fcdbf20..48ecc2d51f 100644 --- a/util/folder/filelist.cpp +++ b/util/folder/filelist.cpp @@ -27,7 +27,7 @@ void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringB TStringBuf filename = file->fts_path + dirNameLength + 1; if (filename.empty() || !filename.StartsWith(prefix) || !filename.EndsWith(suffix)) { - continue; + continue; } if (((Mask & EM_FILES) && file->fts_info == FTS_F) || ((Mask & EM_DIRS) && file->fts_info == FTS_D) || ((Mask & EM_SLINKS) && file->fts_info == FTS_SL)) { diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..51c17970a5 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -71,8 +71,8 @@ TString GetGuidAsString(const TGUID& g) { TString CreateGuidAsString() { return TGUID::Create().AsGuidString(); -} - +} + static bool GetDigit(const char c, ui32& digit) { digit = 0; if ('0' <= c && c <= '9') { diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..54c43aaf59 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -378,8 +378,8 @@ public: } template <typename U> - TMaybe<U, Policy> Cast() const { - return Defined() ? TMaybe<U, Policy>(*Data()) : TMaybe<U, Policy>(); + TMaybe<U, Policy> Cast() const { + return Defined() ? TMaybe<U, Policy>(*Data()) : TMaybe<U, Policy>(); } constexpr explicit operator bool() const noexcept { @@ -451,9 +451,9 @@ private: template <class T> using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; -template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept> -constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) { - return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value)); +template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept> +constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) { + return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value)); } template <class T, class... TArgs> @@ -466,26 +466,26 @@ constexpr TMaybe<T> MakeMaybe(std::initializer_list<U> il, TArgs&&... args) { return TMaybe<T>(typename TMaybe<T>::TInPlace{}, il, std::forward<TArgs>(args)...); } -template <class T, class TPolicy> -void Swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { +template <class T, class TPolicy> +void Swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { lhs.Swap(rhs); } -template <class T, class TPolicy> -void swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { +template <class T, class TPolicy> +void swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { lhs.Swap(rhs); } -template <typename T, class TPolicy> -struct THash<TMaybe<T, TPolicy>> { - constexpr size_t operator()(const TMaybe<T, TPolicy>& data) const { +template <typename T, class TPolicy> +struct THash<TMaybe<T, TPolicy>> { + constexpr size_t operator()(const TMaybe<T, TPolicy>& data) const { return (data.Defined()) ? THash<T>()(data.GetRef()) : 42; } }; // Comparisons between TMaybe -template <class T, class TPolicy> -constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TPolicy>& right) { return (static_cast<bool>(left) != static_cast<bool>(right)) ? false : ( @@ -494,13 +494,13 @@ constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TP : *left == *right); } -template <class T, class TPolicy> -constexpr bool operator!=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator!=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { return !(left == right); } -template <class T, class TPolicy> -constexpr bool operator<(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator<(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { return (!static_cast<bool>(right)) ? false : ( @@ -509,203 +509,203 @@ constexpr bool operator<(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy : (*left < *right)); } -template <class T, class TPolicy> -constexpr bool operator>(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator>(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { return right < left; } -template <class T, class TPolicy> -constexpr bool operator<=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator<=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { return !(right < left); } -template <class T, class TPolicy> -constexpr bool operator>=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { +template <class T, class TPolicy> +constexpr bool operator>=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { return !(left < right); } // Comparisons with TNothing -template <class T, class TPolicy> -constexpr bool operator==(const TMaybe<T, TPolicy>& left, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator==(const TMaybe<T, TPolicy>& left, TNothing) noexcept { return !static_cast<bool>(left); } -template <class T, class TPolicy> -constexpr bool operator==(TNothing, const TMaybe<T, TPolicy>& right) noexcept { +template <class T, class TPolicy> +constexpr bool operator==(TNothing, const TMaybe<T, TPolicy>& right) noexcept { return !static_cast<bool>(right); } -template <class T, class TPolicy> -constexpr bool operator!=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator!=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { return static_cast<bool>(left); } -template <class T, class TPolicy> -constexpr bool operator!=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { +template <class T, class TPolicy> +constexpr bool operator!=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { return static_cast<bool>(right); } -template <class T, class TPolicy> -constexpr bool operator<(const TMaybe<T, TPolicy>&, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator<(const TMaybe<T, TPolicy>&, TNothing) noexcept { return false; } -template <class T, class TPolicy> -constexpr bool operator<(TNothing, const TMaybe<T, TPolicy>& right) noexcept { +template <class T, class TPolicy> +constexpr bool operator<(TNothing, const TMaybe<T, TPolicy>& right) noexcept { return static_cast<bool>(right); } -template <class T, class TPolicy> -constexpr bool operator<=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator<=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { return !static_cast<bool>(left); } -template <class T, class TPolicy> -constexpr bool operator<=(TNothing, const TMaybe<T, TPolicy>&) noexcept { +template <class T, class TPolicy> +constexpr bool operator<=(TNothing, const TMaybe<T, TPolicy>&) noexcept { return true; } -template <class T, class TPolicy> -constexpr bool operator>(const TMaybe<T, TPolicy>& left, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator>(const TMaybe<T, TPolicy>& left, TNothing) noexcept { return static_cast<bool>(left); } -template <class T, class TPolicy> -constexpr bool operator>(TNothing, const TMaybe<T, TPolicy>&) noexcept { +template <class T, class TPolicy> +constexpr bool operator>(TNothing, const TMaybe<T, TPolicy>&) noexcept { return false; } -template <class T, class TPolicy> -constexpr bool operator>=(const TMaybe<T, TPolicy>&, TNothing) noexcept { +template <class T, class TPolicy> +constexpr bool operator>=(const TMaybe<T, TPolicy>&, TNothing) noexcept { return true; } -template <class T, class TPolicy> -constexpr bool operator>=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { +template <class T, class TPolicy> +constexpr bool operator>=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { return !static_cast<bool>(right); } // Comparisons with T -template <class T, class TPolicy> -constexpr bool operator==(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator==(const TMaybe<T, TPolicy>& maybe, const T& value) { return static_cast<bool>(maybe) ? *maybe == value : false; } -template <class T, class TPolicy> -constexpr bool operator==(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator==(const T& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? *maybe == value : false; } -template <class T, class TPolicy> -constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const T& value) { return static_cast<bool>(maybe) ? !(*maybe == value) : true; } -template <class T, class TPolicy> -constexpr bool operator!=(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator!=(const T& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? !(*maybe == value) : true; } -template <class T, class TPolicy> -constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const T& value) { return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; } -template <class T, class TPolicy> -constexpr bool operator<(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator<(const T& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; } -template <class T, class TPolicy> -constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const T& value) { return !(maybe > value); } -template <class T, class TPolicy> -constexpr bool operator<=(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator<=(const T& value, const TMaybe<T, TPolicy>& maybe) { return !(value > maybe); } -template <class T, class TPolicy> -constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const T& value) { return static_cast<bool>(maybe) ? value < maybe : false; } -template <class T, class TPolicy> -constexpr bool operator>(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator>(const T& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? maybe < value : true; } -template <class T, class TPolicy> -constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const T& value) { +template <class T, class TPolicy> +constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const T& value) { return !(maybe < value); } -template <class T, class TPolicy> -constexpr bool operator>=(const T& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy> +constexpr bool operator>=(const T& value, const TMaybe<T, TPolicy>& maybe) { return !(value < maybe); } // Comparison with values convertible to T -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator==(const ::TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator==(const ::TMaybe<T, TPolicy>& maybe, const U& value) { return static_cast<bool>(maybe) ? *maybe == value : false; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator==(const U& value, const ::TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator==(const U& value, const ::TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? *maybe == value : false; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const U& value) { return static_cast<bool>(maybe) ? !(*maybe == value) : true; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator!=(const U& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator!=(const U& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? !(*maybe == value) : true; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const U& value) { return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator<(const U& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator<(const U& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const U& value) { return !(maybe > value); } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator<=(const U& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator<=(const U& value, const TMaybe<T, TPolicy>& maybe) { return !(value > maybe); } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const U& value) { return static_cast<bool>(maybe) ? value < maybe : false; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator>(const U& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator>(const U& value, const TMaybe<T, TPolicy>& maybe) { return static_cast<bool>(maybe) ? maybe < value : true; } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const U& value) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const U& value) { return !(maybe < value); } -template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> -constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) { +template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> +constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) { return !(value < maybe); } diff --git a/util/generic/variant.h b/util/generic/variant.h index 749fc75090..16b36cbfad 100644 --- a/util/generic/variant.h +++ b/util/generic/variant.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include "hash.h" #include <variant> diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..4857b28566 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -172,35 +172,35 @@ inline bool FuzzyEquals(double p1, double p2, double eps = 1.0e-13) { inline bool FuzzyEquals(float p1, float p2, float eps = 1.0e-6) { return (Abs(p1 - p2) <= eps * Min(Abs(p1), Abs(p2))); } - -namespace NUtilMathPrivate { - template <bool IsSigned> - struct TCeilDivImpl {}; - - template <> - struct TCeilDivImpl<true> { + +namespace NUtilMathPrivate { + template <bool IsSigned> + struct TCeilDivImpl {}; + + template <> + struct TCeilDivImpl<true> { template <class T> - static inline T Do(T x, T y) noexcept { - return x / y + (((x < 0) ^ (y > 0)) && (x % y)); - } - }; - - template <> - struct TCeilDivImpl<false> { + static inline T Do(T x, T y) noexcept { + return x / y + (((x < 0) ^ (y > 0)) && (x % y)); + } + }; + + template <> + struct TCeilDivImpl<false> { template <class T> - static inline T Do(T x, T y) noexcept { - auto quot = x / y; - return (x % y) ? (quot + 1) : quot; - } - }; -} - -/** - * @returns Equivalent to ceil((double) x / (double) y) but using only integer arithmetic operations - */ -template <class T> -inline T CeilDiv(T x, T y) noexcept { - static_assert(std::is_integral<T>::value, "Integral type required."); - Y_ASSERT(y != 0); - return ::NUtilMathPrivate::TCeilDivImpl<std::is_signed<T>::value>::Do(x, y); -} + static inline T Do(T x, T y) noexcept { + auto quot = x / y; + return (x % y) ? (quot + 1) : quot; + } + }; +} + +/** + * @returns Equivalent to ceil((double) x / (double) y) but using only integer arithmetic operations + */ +template <class T> +inline T CeilDiv(T x, T y) noexcept { + static_assert(std::is_integral<T>::value, "Integral type required."); + Y_ASSERT(y != 0); + return ::NUtilMathPrivate::TCeilDivImpl<std::is_signed<T>::value>::Do(x, y); +} diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp index 29190b55eb..15514e4bb3 100644 --- a/util/generic/ymath_ut.cpp +++ b/util/generic/ymath_ut.cpp @@ -34,7 +34,7 @@ class TMathTest: public TTestBase { UNIT_TEST(TestAbs); UNIT_TEST(TestPower); UNIT_TEST(TestSigmoid); - UNIT_TEST(TestCeilDiv); + UNIT_TEST(TestCeilDiv); UNIT_TEST_SUITE_END(); private: @@ -45,7 +45,7 @@ private: void TestAbs(); void TestPower(); void TestSigmoid(); - void TestCeilDiv(); + void TestCeilDiv(); inline void TestIsValidFloat() { UNIT_ASSERT(IsValidFloat(-Max<double>() / 2.)); @@ -191,30 +191,30 @@ void TMathTest::TestSigmoid() { UNIT_ASSERT_EQUAL(Sigmoid(-5000.), 0.0); UNIT_ASSERT_EQUAL(Sigmoid(5000.), 1.0); } - -void TMathTest::TestCeilDiv() { - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(2, 3), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(3, 3), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(12, 2), 6); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(10, 3), 4); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(0, 10), 0); - - // negative numbers - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(0, -10), 0); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, 2), 0); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, -2), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(10, -5), -2); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-3, -4), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, -4), 2); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, 4), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-13, 4), -3); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-14, -4), 4); - - // check values close to overflow - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(255, 10), 26); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(std::numeric_limits<ui32>::max() - 3, std::numeric_limits<ui32>::max()), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::max() - 3, std::numeric_limits<i32>::max()), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::min(), std::numeric_limits<i32>::max()), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i8>(std::numeric_limits<i8>::max(), std::numeric_limits<i8>::min() + 1), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i64>(std::numeric_limits<i64>::max() - 2, -(std::numeric_limits<i64>::min() + 1)), 1); -} + +void TMathTest::TestCeilDiv() { + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(2, 3), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(3, 3), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(12, 2), 6); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(10, 3), 4); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(0, 10), 0); + + // negative numbers + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(0, -10), 0); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, 2), 0); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, -2), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(10, -5), -2); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-3, -4), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, -4), 2); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, 4), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-13, 4), -3); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-14, -4), 4); + + // check values close to overflow + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(255, 10), 26); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(std::numeric_limits<ui32>::max() - 3, std::numeric_limits<ui32>::max()), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::max() - 3, std::numeric_limits<i32>::max()), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::min(), std::numeric_limits<i32>::max()), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i8>(std::numeric_limits<i8>::max(), std::numeric_limits<i8>::min() + 1), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i64>(std::numeric_limits<i64>::max() - 2, -(std::numeric_limits<i64>::min() + 1)), 1); +} diff --git a/util/memory/segpool_alloc.h b/util/memory/segpool_alloc.h index 1a83b7a543..d38c000774 100644 --- a/util/memory/segpool_alloc.h +++ b/util/memory/segpool_alloc.h @@ -77,10 +77,10 @@ struct segpool_alloc { if (!pool) { Y_IF_DEBUG(malloc_free_count++); free(__p); - } else { + } else { Y_IF_DEBUG(pool_free_count++); - ; - } + ; + } } ~segpool_alloc() { //assert(pool_count == pool_free_count && malloc_count == malloc_free_count); <- uncomment when swap() problem is solved diff --git a/util/network/ip.h b/util/network/ip.h index dc7c2d24a0..7fd0b63ae1 100644 --- a/util/network/ip.h +++ b/util/network/ip.h @@ -14,28 +14,28 @@ using TIpHost = ui32; /// Port number in host format using TIpPort = ui16; -/* +/* * ipStr is in 'ddd.ddd.ddd.ddd' format * returns IPv4 address in inet format */ -static inline TIpHost IpFromString(const char* ipStr) { - in_addr ia; +static inline TIpHost IpFromString(const char* ipStr) { + in_addr ia; - if (inet_aton(ipStr, &ia) == 0) { + if (inet_aton(ipStr, &ia) == 0) { ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ip address"; - } - - return (ui32)ia.s_addr; -} + } + return (ui32)ia.s_addr; +} + static inline char* IpToString(TIpHost ip, char* buf, size_t len) { if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) { ythrow TSystemError() << "Failed to get ip address string"; - } - + } + return buf; -} - +} + static inline TString IpToString(TIpHost ip) { char buf[INET_ADDRSTRLEN]; diff --git a/util/network/ip_ut.cpp b/util/network/ip_ut.cpp index 6716c6a699..753d62cd0e 100644 --- a/util/network/ip_ut.cpp +++ b/util/network/ip_ut.cpp @@ -1,10 +1,10 @@ #include "ip.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/generic/yexception.h> - -class TSysIpTest: public TTestBase { + +class TSysIpTest: public TTestBase { UNIT_TEST_SUITE(TSysIpTest); UNIT_TEST(TestIpFromString); UNIT_TEST_EXCEPTION(TestIpFromString2, yexception); @@ -21,43 +21,43 @@ private: void TestIpFromString4(); void TestIpFromString5(); void TestIpToString(); -}; - -UNIT_TEST_SUITE_REGISTRATION(TSysIpTest); - +}; + +UNIT_TEST_SUITE_REGISTRATION(TSysIpTest); + void TSysIpTest::TestIpFromString() { - const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; - ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; - + const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; + ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { const ui32 ip = IpFromString(ipStr[i]); - UNIT_ASSERT(memcmp(&ip, ipArr[i], sizeof(ui32)) == 0); - } -} - + UNIT_ASSERT(memcmp(&ip, ipArr[i], sizeof(ui32)) == 0); + } +} + void TSysIpTest::TestIpFromString2() { IpFromString("XXXXXXWXW"); -} - +} + void TSysIpTest::TestIpFromString3() { IpFromString("986.0.37.255"); -} - +} + void TSysIpTest::TestIpFromString4() { IpFromString("256.0.22.365"); -} - +} + void TSysIpTest::TestIpFromString5() { IpFromString("245.12..0"); -} - -void TSysIpTest::TestIpToString() { - ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; - - const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; - +} + +void TSysIpTest::TestIpToString() { + ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; + + const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { UNIT_ASSERT(IpToString(*reinterpret_cast<TIpHost*>(&(ipArr[i]))) == ipStr[i]); - } -} + } +} diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 4f6e804346..192656f57a 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -49,7 +49,7 @@ using namespace NAddr; #if defined(_win_) - + int inet_aton(const char* cp, struct in_addr* inp) { sockaddr_in addr; addr.sin_family = AF_INET; diff --git a/util/network/socket.h b/util/network/socket.h index 40c8648b40..4fb3926110 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -14,10 +14,10 @@ #include <cerrno> -#ifndef INET_ADDRSTRLEN +#ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 -#endif - +#endif + #if defined(_unix_) #define get_host_error() h_errno #elif defined(_win_) @@ -46,15 +46,15 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept; #else #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) #endif - + int inet_aton(const char* cp, struct in_addr* inp); - + #define get_host_error() WSAGetLastError() #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND #define SHUT_RDWR SD_BOTH - + #define INFTIM (-1) #endif diff --git a/util/random/entropy.cpp b/util/random/entropy.cpp index 3617edb83d..77e9ba3170 100644 --- a/util/random/entropy.cpp +++ b/util/random/entropy.cpp @@ -14,7 +14,7 @@ #include <util/system/info.h> #include <util/system/spinlock.h> #include <util/system/thread.h> -#include <util/system/execpath.h> +#include <util/system/execpath.h> #include <util/system/datetime.h> #include <util/system/hostname.h> #include <util/system/getpid.h> diff --git a/util/stream/debug.cpp b/util/stream/debug.cpp index afd5b3e1c7..69ce49155c 100644 --- a/util/stream/debug.cpp +++ b/util/stream/debug.cpp @@ -30,7 +30,7 @@ namespace { Level = 0; } } - + IOutputStream* Out; int Level; }; diff --git a/util/stream/input.cpp b/util/stream/input.cpp index 6e8170f2f9..5a01c2f1ae 100644 --- a/util/stream/input.cpp +++ b/util/stream/input.cpp @@ -258,19 +258,19 @@ IInputStream& NPrivate::StdInStream() noexcept { // helper functions -static inline bool IsStdDelimiter(char c) { +static inline bool IsStdDelimiter(char c) { return (c == '\0') || (c == ' ') || (c == '\r') || (c == '\n') || (c == '\t'); } static void ReadUpToDelimiter(IInputStream& i, TString& s) { char c; while (i.ReadChar(c)) { // skip delimiters - if (!IsStdDelimiter(c)) { + if (!IsStdDelimiter(c)) { s += c; break; } } - while (i.ReadChar(c) && !IsStdDelimiter(c)) { // read data (with trailing delimiter) + while (i.ReadChar(c) && !IsStdDelimiter(c)) { // read data (with trailing delimiter) s += c; } } @@ -279,7 +279,7 @@ static void ReadUpToDelimiter(IInputStream& i, TString& s) { template <> void In<TString>(IInputStream& i, TString& s) { - s.resize(0); + s.resize(0); ReadUpToDelimiter(i, s); } diff --git a/util/stream/mem.h b/util/stream/mem.h index 18a5d46772..878a2ff194 100644 --- a/util/stream/mem.h +++ b/util/stream/mem.h @@ -82,7 +82,7 @@ public: const char* Buf() const noexcept { return Buf_; } - + /** * Initializes this stream with a next chunk extracted from the given zero * copy stream. diff --git a/util/stream/null.cpp b/util/stream/null.cpp index 4e8b298145..66519fb796 100644 --- a/util/stream/null.cpp +++ b/util/stream/null.cpp @@ -7,10 +7,10 @@ TNullIO& NPrivate::StdNullStream() noexcept { } TNullInput::TNullInput() noexcept { -} - +} + TNullInput::~TNullInput() = default; - + size_t TNullInput::DoRead(void*, size_t) { return 0; } @@ -24,7 +24,7 @@ size_t TNullInput::DoNext(const void**, size_t) { } TNullOutput::TNullOutput() noexcept = default; - + TNullOutput::~TNullOutput() = default; void TNullOutput::DoWrite(const void* /*buf*/, size_t /*len*/) { diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp index 51be1934a7..d0e1a78b57 100644 --- a/util/stream/pipe.cpp +++ b/util/stream/pipe.cpp @@ -33,17 +33,17 @@ public: TPipeBase::TPipeBase(const TString& command, const char* mode) : Impl_(new TImpl(command, mode)) -{ -} - +{ +} + TPipeBase::~TPipeBase() = default; - + TPipeInput::TPipeInput(const TString& command) : TPipeBase(command, "r") { } -size_t TPipeInput::DoRead(void* buf, size_t len) { +size_t TPipeInput::DoRead(void* buf, size_t len) { if (Impl_->Pipe_ == nullptr) { return 0; } @@ -59,8 +59,8 @@ size_t TPipeInput::DoRead(void* buf, size_t len) { } } return bytesRead; -} - +} + TPipeOutput::TPipeOutput(const TString& command) : TPipeBase(command, "w") { diff --git a/util/stream/pipe.h b/util/stream/pipe.h index 18525b9517..bbd98a6fbd 100644 --- a/util/stream/pipe.h +++ b/util/stream/pipe.h @@ -46,11 +46,11 @@ public: * @param command Command line to start a process with. */ TPipeInput(const TString& command); - + private: size_t DoRead(void* buf, size_t len) override; }; - + /** * Output stream that binds to a standard input stream of a newly started process. * @@ -74,8 +74,8 @@ public: private: void DoWrite(const void* buf, size_t len) override; -}; - +}; + class TPipedBase { protected: TPipedBase(PIPEHANDLE fd); diff --git a/util/stream/tee.cpp b/util/stream/tee.cpp index 99873b95ba..d059c367d0 100644 --- a/util/stream/tee.cpp +++ b/util/stream/tee.cpp @@ -4,21 +4,21 @@ TTeeOutput::TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept : L_(l) , R_(r) { -} - +} + TTeeOutput::~TTeeOutput() = default; - -void TTeeOutput::DoWrite(const void* buf, size_t len) { + +void TTeeOutput::DoWrite(const void* buf, size_t len) { L_->Write(buf, len); R_->Write(buf, len); -} - -void TTeeOutput::DoFlush() { +} + +void TTeeOutput::DoFlush() { L_->Flush(); R_->Flush(); -} - -void TTeeOutput::DoFinish() { +} + +void TTeeOutput::DoFinish() { L_->Finish(); R_->Finish(); -} +} diff --git a/util/stream/tee.h b/util/stream/tee.h index c69e232fb9..623d44be32 100644 --- a/util/stream/tee.h +++ b/util/stream/tee.h @@ -14,15 +14,15 @@ class TTeeOutput: public IOutputStream { public: TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept; ~TTeeOutput() override; - + private: void DoWrite(const void* buf, size_t len) override; void DoFlush() override; void DoFinish() override; - + private: IOutputStream* L_; IOutputStream* R_; -}; - +}; + /** @} */ diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..eb60ac9dc4 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -348,11 +348,11 @@ void TZLibCompress::TDestruct::Destroy(TImpl* impl) { } TZLibCompress::~TZLibCompress() { - try { - Finish(); - } catch (...) { + try { + Finish(); + } catch (...) { // ¯\_(ツ)_/¯ - } + } } void TZLibCompress::DoWrite(const void* buf, size_t size) { diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..75741efe21 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -54,7 +54,7 @@ namespace { template <class T> std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T value) noexcept { return std::make_unsigned_t<T>(-(value + 1)) + std::make_unsigned_t<T>(1); - } + } template <class T> std::enable_if_t<std::is_unsigned<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T) noexcept { @@ -482,29 +482,29 @@ size_t ToStringImpl<bool>(bool t, char* buf, size_t len) { /* * ------------------------------ parsers ------------------------------ */ - -template <> + +template <> bool TryFromStringImpl<bool>(const char* data, size_t len, bool& result) { - if (len == 1) { - if (data[0] == '0') { + if (len == 1) { + if (data[0] == '0') { result = false; return true; - } else if (data[0] == '1') { + } else if (data[0] == '1') { result = true; - return true; - } - } - TStringBuf buf(data, len); + return true; + } + } + TStringBuf buf(data, len); if (IsTrue(buf)) { result = true; - return true; + return true; } else if (IsFalse(buf)) { result = false; return true; - } + } return false; -} - +} + template <> bool FromStringImpl<bool>(const char* data, size_t len) { bool result; diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..7a176a5c77 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -124,7 +124,7 @@ struct TFromStringException: public TBadCastException { /* * specialized for: - * bool + * bool * short * unsigned short * int diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..e7be19c96a 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -40,31 +40,31 @@ UNIT_ASSERT_VALUES_EQUAL(TryIntFromStringForCheck<base>(IntToString<base>(val), result), false); \ UNIT_ASSERT_VALUES_EQUAL(result, def); -template <class A> -struct TRet { +template <class A> +struct TRet { template <int base> inline A IntFromStringForCheck(const TString& str) { - return IntFromString<A, base>(str); - } + return IntFromString<A, base>(str); + } template <int base> inline bool TryIntFromStringForCheck(const TString& str, A& result) { return TryIntFromString<base>(str, result); } - template <class B> + template <class B> inline void CheckOK(B v) { UNIT_ASSERT_VALUES_EQUAL(FromString<A>(ToString(v)), v); // char UNIT_ASSERT_VALUES_EQUAL(FromString<A>(ToWtring(v)), v); // wide char HEX_MACROS_MAP(OK_HEX_CHECK, A, v); - } + } - template <class B> + template <class B> inline void CheckExc(B v) { UNIT_ASSERT_EXCEPTION(FromString<A>(ToString(v)), yexception); // char UNIT_ASSERT_EXCEPTION(FromString<A>(ToWtring(v)), yexception); // wide char HEX_MACROS_MAP(EXC_HEX_CHECK, A, v); - } + } template <class B> inline void CheckTryOK(B v) { @@ -89,16 +89,16 @@ struct TRet { TRY_HEX_MACROS_MAP(TRY_FAIL_HEX_CHECK, A, v, convV, defaultV); } -}; - -template <> -struct TRet<bool> { - template <class B> +}; + +template <> +struct TRet<bool> { + template <class B> inline void CheckOK(B v) { UNIT_ASSERT_VALUES_EQUAL(FromString<bool>(ToString(v)), v); - } - - template <class B> + } + + template <class B> inline void CheckTryOK(B v) { B convV; UNIT_ASSERT_VALUES_EQUAL(TryFromString<bool>(ToString(v), convV), true); @@ -107,8 +107,8 @@ struct TRet<bool> { template <class B> inline void CheckExc(B v) { - UNIT_ASSERT_EXCEPTION(FromString<bool>(ToString(v)), yexception); - } + UNIT_ASSERT_EXCEPTION(FromString<bool>(ToString(v)), yexception); + } template <class B> inline void CheckTryFail(B v) { @@ -117,13 +117,13 @@ struct TRet<bool> { UNIT_ASSERT_VALUES_EQUAL(TryFromString<bool>(ToString(v), convV), false); UNIT_ASSERT_VALUES_EQUAL(defaultV, convV); } -}; - -template <class A> -inline TRet<A> F() { - return TRet<A>(); -}; - +}; + +template <class A> +inline TRet<A> F() { + return TRet<A>(); +}; + #if 0 template <class T> inline void CheckConvertToBuffer(const T& value, const size_t size, const TString& canonValue) { @@ -181,7 +181,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { test1(bool, false); test2(bool, ""); test2(bool, "a"); - + test2(ui8, -1); test1(i8, -1); test1(i8, SCHAR_MAX); diff --git a/util/string/type.cpp b/util/string/type.cpp index 49671c02c2..c6b6f7aea5 100644 --- a/util/string/type.cpp +++ b/util/string/type.cpp @@ -72,7 +72,7 @@ bool IsTrue(const TStringBuf v) noexcept { "da"}; return IsCaseInsensitiveAnyOf(v, trueOptions); } - + bool IsFalse(const TStringBuf v) noexcept { static constexpr std::array<TStringBuf, 7> falseOptions{ "false", @@ -83,4 +83,4 @@ bool IsFalse(const TStringBuf v) noexcept { "0", "net"}; return IsCaseInsensitiveAnyOf(v, falseOptions); -} +} diff --git a/util/system/compat.cpp b/util/system/compat.cpp index 18fbfa296a..1c8c9b5289 100644 --- a/util/system/compat.cpp +++ b/util/system/compat.cpp @@ -17,11 +17,11 @@ #endif #ifndef HAVE_NATIVE_GETPROGNAME -const char* getprogname() { +const char* getprogname() { return GetProgramName().data(); -} +} #endif - + #ifdef _win_ void sleep(i64 len) { diff --git a/util/system/compat.h b/util/system/compat.h index c53dbcca17..205e79c8f6 100644 --- a/util/system/compat.h +++ b/util/system/compat.h @@ -12,8 +12,8 @@ #if defined(_win_) #include <process.h> -#endif - +#endif + extern "C" { #if defined(_win_) using pid_t = int; @@ -34,8 +34,8 @@ extern "C" { #ifndef HAVE_NATIVE_GETPROGNAME const char* getprogname(); -#endif - +#endif + #if defined(_MSC_VER) void err(int e, const char* m, ...); void errx(int e, const char* m, ...); diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp index 33198af58b..7cff2d5973 100644 --- a/util/system/execpath.cpp +++ b/util/system/execpath.cpp @@ -9,9 +9,9 @@ #elif defined(_win_) #include "winint.h" #include <io.h> -#elif defined(_linux_) +#elif defined(_linux_) #include <unistd.h> -#elif defined(_freebsd_) +#elif defined(_freebsd_) #include <string.h> #include <sys/types.h> // for u_int not defined in sysctl.h #include <sys/sysctl.h> @@ -28,7 +28,7 @@ #include <util/string/cast.h> #include "filemap.h" -#include "execpath.h" +#include "execpath.h" #include "fs.h" #if defined(_freebsd_) @@ -36,28 +36,28 @@ static inline bool GoodPath(const TString& path) { return path.find('/') != TString::npos; } -static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { - for (size_t i = 0; i < 2; ++i) { - size_t cb = res.Size(); +static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { + for (size_t i = 0; i < 2; ++i) { + size_t cb = res.Size(); if (sysctl(mib, mibSize, res.Data(), &cb, nullptr, 0) == 0) { - res.Proceed(cb); - return 0; - } else if (errno == ENOMEM) { - res = TTempBuf(cb); - } else { - return errno; - } + res.Proceed(cb); + return 0; + } else if (errno == ENOMEM) { + res = TTempBuf(cb); + } else { + return errno; + } } - return errno; + return errno; } static inline TString FreeBSDGetExecPath() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; - TTempBuf buf; + TTempBuf buf; int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); - if (r == 0) { + if (r == 0) { return TString(buf.Data(), buf.Filled() - 1); - } else if (r == ENOTSUP) { // older FreeBSD version + } else if (r == ENOTSUP) { // older FreeBSD version /* * BSD analogue for /proc/self is /proc/curproc. * See: @@ -65,7 +65,7 @@ static inline TString FreeBSDGetExecPath() { */ TString path("/proc/curproc/file"); return NFs::ReadLink(path); - } else { + } else { return TString(); } } @@ -74,56 +74,56 @@ 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) { + if (r == 0) { return TString(buf.Data()); - } else if (r == ENOTSUP) { + } else if (r == ENOTSUP) { return TString(); - } else { - ythrow yexception() << "FreeBSDGetArgv0() failed: " << LastSystemErrorText(); - } + } else { + ythrow yexception() << "FreeBSDGetArgv0() failed: " << LastSystemErrorText(); + } } static inline bool FreeBSDGuessExecPath(const TString& guessPath, TString& execPath) { if (NFs::Exists(guessPath)) { - // now it should work for real - execPath = FreeBSDGetExecPath(); - if (RealPath(execPath) == RealPath(guessPath)) { - return true; - } - } - return false; -} - + // now it should work for real + execPath = FreeBSDGetExecPath(); + if (RealPath(execPath) == RealPath(guessPath)) { + return true; + } + } + return false; +} + static inline bool FreeBSDGuessExecBasePath(const TString& guessBasePath, TString& execPath) { return FreeBSDGuessExecPath(TString(guessBasePath) + "/" + getprogname(), execPath); -} - +} + #endif static TString GetExecPathImpl() { #if defined(_solaris_) return execname(); #elif defined(_darwin_) - TTempBuf execNameBuf; - for (size_t i = 0; i < 2; ++i) { + TTempBuf execNameBuf; + for (size_t i = 0; i < 2; ++i) { std::remove_pointer_t<TFunctionArg<decltype(_NSGetExecutablePath), 1>> bufsize = execNameBuf.Size(); int r = _NSGetExecutablePath(execNameBuf.Data(), &bufsize); if (r == 0) { return execNameBuf.Data(); - } else if (r == -1) { - execNameBuf = TTempBuf(bufsize); + } else if (r == -1) { + execNameBuf = TTempBuf(bufsize); } } - ythrow yexception() << "GetExecPathImpl() failed"; + ythrow yexception() << "GetExecPathImpl() failed"; #elif defined(_win_) - TTempBuf execNameBuf; + TTempBuf execNameBuf; for (;;) { DWORD r = GetModuleFileName(nullptr, execNameBuf.Data(), execNameBuf.Size()); - if (r == execNameBuf.Size()) { - execNameBuf = TTempBuf(execNameBuf.Size() * 2); - } else if (r == 0) { - ythrow yexception() << "GetExecPathImpl() failed: " << LastSystemErrorText(); - } else { + if (r == execNameBuf.Size()) { + execNameBuf = TTempBuf(execNameBuf.Size() * 2); + } else if (r == 0) { + ythrow yexception() << "GetExecPathImpl() failed: " << LastSystemErrorText(); + } else { return execNameBuf.Data(); } } @@ -133,23 +133,23 @@ static TString GetExecPathImpl() { // TODO(yoda): check if the filename ends with " (deleted)" #elif defined(_freebsd_) TString execPath = FreeBSDGetExecPath(); - if (GoodPath(execPath)) { - return execPath; - } - if (FreeBSDGuessExecPath(FreeBSDGetArgv0(), execPath)) { - return execPath; + if (GoodPath(execPath)) { + return execPath; } - if (FreeBSDGuessExecPath(getenv("_"), execPath)) { - return execPath; + if (FreeBSDGuessExecPath(FreeBSDGetArgv0(), execPath)) { + return execPath; } - if (FreeBSDGuessExecBasePath(getenv("PWD"), execPath)) { - return execPath; + if (FreeBSDGuessExecPath(getenv("_"), execPath)) { + return execPath; } + if (FreeBSDGuessExecBasePath(getenv("PWD"), execPath)) { + return execPath; + } if (FreeBSDGuessExecBasePath(NFs::CurrentWorkingDirectory(), execPath)) { - return execPath; - } + return execPath; + } - ythrow yexception() << "can not resolve exec path"; + ythrow yexception() << "can not resolve exec path"; #else #error dont know how to implement GetExecPath on this platform #endif diff --git a/util/system/execpath_ut.cpp b/util/system/execpath_ut.cpp index 16b01466f5..d83523de15 100644 --- a/util/system/execpath_ut.cpp +++ b/util/system/execpath_ut.cpp @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TExecPathTest) { UNIT_ASSERT(NFs::Exists(execPath)); UNIT_ASSERT(NFs::Exists(persistentExecPath)); } catch (...) { - Cerr << execPath << Endl; + Cerr << execPath << Endl; throw; } diff --git a/util/system/info.cpp b/util/system/info.cpp index cf6681e89a..dacad12282 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -1,7 +1,7 @@ #include "info.h" -#include "error.h" - +#include "error.h" + #include <cstdlib> #if defined(_linux_) || defined(_cygwin_) @@ -26,7 +26,7 @@ static int getloadavg(double* loadavg, int nelem) { return nelem; } -#elif defined(_unix_) || defined(_darwin_) +#elif defined(_unix_) || defined(_darwin_) #include <sys/types.h> #endif @@ -38,7 +38,7 @@ static int getloadavg(double* loadavg, int nelem) { #include <util/string/cast.h> #include <util/string/strip.h> #include <util/stream/file.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #if defined(_linux_) static inline size_t CgroupCpus() { @@ -204,25 +204,25 @@ size_t NSystemInfo::TotalMemorySize() { sysinfo(&info); return info.totalram; #elif defined(_darwin_) - int mib[2]; - int64_t memSize; - size_t length; - - // Get the Physical memory size - mib[0] = CTL_HW; - mib[1] = HW_MEMSIZE; - length = sizeof(int64_t); - if (sysctl(mib, 2, &memSize, &length, NULL, 0) != 0) { - ythrow yexception() << "sysctl failed: " << LastSystemErrorText(); - } - return (size_t)memSize; + int mib[2]; + int64_t memSize; + size_t length; + + // Get the Physical memory size + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; + length = sizeof(int64_t); + if (sysctl(mib, 2, &memSize, &length, NULL, 0) != 0) { + ythrow yexception() << "sysctl failed: " << LastSystemErrorText(); + } + return (size_t)memSize; #elif defined(_win_) - MEMORYSTATUSEX memoryStatusEx; - memoryStatusEx.dwLength = sizeof(memoryStatusEx); - if (!GlobalMemoryStatusEx(&memoryStatusEx)) { - ythrow yexception() << "GlobalMemoryStatusEx failed: " << LastSystemErrorText(); - } - return (size_t)memoryStatusEx.ullTotalPhys; + MEMORYSTATUSEX memoryStatusEx; + memoryStatusEx.dwLength = sizeof(memoryStatusEx); + if (!GlobalMemoryStatusEx(&memoryStatusEx)) { + ythrow yexception() << "GlobalMemoryStatusEx failed: " << LastSystemErrorText(); + } + return (size_t)memoryStatusEx.ullTotalPhys; #else return 0; #endif diff --git a/util/system/interrupt_signals.cpp b/util/system/interrupt_signals.cpp index 96b723f2b8..61ff8dd720 100644 --- a/util/system/interrupt_signals.cpp +++ b/util/system/interrupt_signals.cpp @@ -1,60 +1,60 @@ -#include "interrupt_signals.h" - -#include "compiler.h" -#include "error.h" - -#include <util/generic/yexception.h> - -#include <csignal> - -static void (*InterruptSignalsHandler)(int signum) = nullptr; - -#ifdef _win_ - +#include "interrupt_signals.h" + +#include "compiler.h" +#include "error.h" + +#include <util/generic/yexception.h> + +#include <csignal> + +static void (*InterruptSignalsHandler)(int signum) = nullptr; + +#ifdef _win_ + #include <windows.h> - -static BOOL WINAPI WindowsSignalsHandler(_In_ DWORD dwCtrlType) { - if (!InterruptSignalsHandler) { - return FALSE; - } - - switch (dwCtrlType) { - case CTRL_C_EVENT: - InterruptSignalsHandler(SIGINT); - return TRUE; - case CTRL_BREAK_EVENT: - InterruptSignalsHandler(SIGTERM); - return TRUE; - case CTRL_CLOSE_EVENT: - InterruptSignalsHandler(SIGHUP); - return TRUE; - default: - return FALSE; - } - Y_UNREACHABLE(); -} - -#endif - -// separate function is to enforce 'extern "C"' linkage -extern "C" void CppSignalsHandler(int signum) { - if (InterruptSignalsHandler) { - InterruptSignalsHandler(signum); - } -} - -void SetInterruptSignalsHandler(void (*handler)(int signum)) { - InterruptSignalsHandler = handler; -#ifdef _win_ - if (!SetConsoleCtrlHandler(WindowsSignalsHandler, TRUE)) { - ythrow TSystemError() << "SetConsoleCtrlHandler failed: " << LastSystemErrorText(); - } - for (int signum : {SIGINT, SIGTERM}) { -#else - for (int signum : {SIGINT, SIGTERM, SIGHUP}) { -#endif - if (std::signal(signum, CppSignalsHandler) == SIG_ERR) { - ythrow TSystemError() << "std::signal failed to set handler for signal with id " << signum; - } - } -} + +static BOOL WINAPI WindowsSignalsHandler(_In_ DWORD dwCtrlType) { + if (!InterruptSignalsHandler) { + return FALSE; + } + + switch (dwCtrlType) { + case CTRL_C_EVENT: + InterruptSignalsHandler(SIGINT); + return TRUE; + case CTRL_BREAK_EVENT: + InterruptSignalsHandler(SIGTERM); + return TRUE; + case CTRL_CLOSE_EVENT: + InterruptSignalsHandler(SIGHUP); + return TRUE; + default: + return FALSE; + } + Y_UNREACHABLE(); +} + +#endif + +// separate function is to enforce 'extern "C"' linkage +extern "C" void CppSignalsHandler(int signum) { + if (InterruptSignalsHandler) { + InterruptSignalsHandler(signum); + } +} + +void SetInterruptSignalsHandler(void (*handler)(int signum)) { + InterruptSignalsHandler = handler; +#ifdef _win_ + if (!SetConsoleCtrlHandler(WindowsSignalsHandler, TRUE)) { + ythrow TSystemError() << "SetConsoleCtrlHandler failed: " << LastSystemErrorText(); + } + for (int signum : {SIGINT, SIGTERM}) { +#else + for (int signum : {SIGINT, SIGTERM, SIGHUP}) { +#endif + if (std::signal(signum, CppSignalsHandler) == SIG_ERR) { + ythrow TSystemError() << "std::signal failed to set handler for signal with id " << signum; + } + } +} diff --git a/util/system/interrupt_signals.h b/util/system/interrupt_signals.h index 9f9c2427f1..e38f95908d 100644 --- a/util/system/interrupt_signals.h +++ b/util/system/interrupt_signals.h @@ -1,22 +1,22 @@ -#pragma once - -#include "platform.h" - -#include <csignal> - -#ifdef _win_ - #ifndef SIGHUP +#pragma once + +#include "platform.h" + +#include <csignal> + +#ifdef _win_ + #ifndef SIGHUP #define SIGHUP 1 /* Hangup (POSIX). */ - #endif -#endif - + #endif +#endif + /** - * Set handler for interrupt signals. - * - * All OSes: SIGINT, SIGTERM (defined by C++ standard) - * UNIX variants: Also SIGHUP - * Windows: CTRL_C_EVENT handled as SIGINT, CTRL_BREAK_EVENT as SIGTERM, CTRL_CLOSE_EVENT as SIGHUP + * Set handler for interrupt signals. + * + * All OSes: SIGINT, SIGTERM (defined by C++ standard) + * UNIX variants: Also SIGHUP + * Windows: CTRL_C_EVENT handled as SIGINT, CTRL_BREAK_EVENT as SIGTERM, CTRL_CLOSE_EVENT as SIGHUP * * \param handler Signal handler to use. Pass nullptr to clear currently set handler. - */ -void SetInterruptSignalsHandler(void (*handler)(int signum)); + */ +void SetInterruptSignalsHandler(void (*handler)(int signum)); diff --git a/util/system/interrupt_signals_ut.cpp b/util/system/interrupt_signals_ut.cpp index bec54fec61..822c290e82 100644 --- a/util/system/interrupt_signals_ut.cpp +++ b/util/system/interrupt_signals_ut.cpp @@ -1,46 +1,46 @@ -#include "interrupt_signals.h" - -#include "atomic.h" - -#include <util/datetime/base.h> - +#include "interrupt_signals.h" + +#include "atomic.h" + +#include <util/datetime/base.h> + #include <library/cpp/testing/unittest/registar.h> - -#ifdef _win_ - #include <windows.h> -#endif - + +#ifdef _win_ + #include <windows.h> +#endif + Y_UNIT_TEST_SUITE(TTestInterruptSignals) { - static TAtomic HandledSigNum = 0; - - static void Handler(int signum) { - AtomicSet(HandledSigNum, signum); - } - + static TAtomic HandledSigNum = 0; + + static void Handler(int signum) { + AtomicSet(HandledSigNum, signum); + } + Y_UNIT_TEST(Test1) { - SetInterruptSignalsHandler(Handler); -#ifdef _win_ - // TODO: unfortunately GenerateConsoleCtrlEvent fails under Wine - /* - for (auto [winEvent, posixSigNum] : { - std::make_pair(CTRL_C_EVENT, SIGINT), - std::make_pair(CTRL_BREAK_EVENT, SIGTERM) - }) - { - if (!GenerateConsoleCtrlEvent(winEvent, 0)) { - UNIT_FAIL("GenerateConsoleCtrlEvent failed: " << LastSystemErrorText()); - } - Sleep(TDuration::MilliSeconds(100)); - UNIT_ASSERT_VALUES_EQUAL(HandledSigNum, posixSigNum); - } - */ - for (int signum : {SIGINT, SIGTERM}) { -#else - for (int signum : {SIGINT, SIGTERM, SIGHUP}) { -#endif - std::raise(signum); - Sleep(TDuration::MilliSeconds(100)); // give it time to handle an async signal - UNIT_ASSERT_VALUES_EQUAL(HandledSigNum, signum); - } - } -} + SetInterruptSignalsHandler(Handler); +#ifdef _win_ + // TODO: unfortunately GenerateConsoleCtrlEvent fails under Wine + /* + for (auto [winEvent, posixSigNum] : { + std::make_pair(CTRL_C_EVENT, SIGINT), + std::make_pair(CTRL_BREAK_EVENT, SIGTERM) + }) + { + if (!GenerateConsoleCtrlEvent(winEvent, 0)) { + UNIT_FAIL("GenerateConsoleCtrlEvent failed: " << LastSystemErrorText()); + } + Sleep(TDuration::MilliSeconds(100)); + UNIT_ASSERT_VALUES_EQUAL(HandledSigNum, posixSigNum); + } + */ + for (int signum : {SIGINT, SIGTERM}) { +#else + for (int signum : {SIGINT, SIGTERM, SIGHUP}) { +#endif + std::raise(signum); + Sleep(TDuration::MilliSeconds(100)); // give it time to handle an async signal + UNIT_ASSERT_VALUES_EQUAL(HandledSigNum, signum); + } + } +} diff --git a/util/system/mktemp_system.cpp b/util/system/mktemp_system.cpp index 32bea2987c..03a16254a4 100644 --- a/util/system/mktemp_system.cpp +++ b/util/system/mktemp_system.cpp @@ -41,13 +41,13 @@ #include <string.h> #include <ctype.h> -#ifdef _win32_ +#ifdef _win32_ #include "winint.h" #include <util/folder/dirut.h> #else - #include <unistd.h> -#endif - + #include <unistd.h> +#endif + #include <util/random/random.h> #include "sysstat.h" @@ -59,10 +59,10 @@ GetTemp(char* path, int* doopen, int domkdir, int slen) { char *start, *trv, *suffp; char* pad; -#ifndef _win32_ +#ifndef _win32_ struct stat sbuf; int rval; -#endif +#endif ui32 rand; if (doopen != nullptr && domkdir) { @@ -95,7 +95,7 @@ GetTemp(char* path, int* doopen, int domkdir, int slen) for (; trv > path; --trv) { if (*trv == '/') { *trv = '\0'; -#ifdef _win32_ +#ifdef _win32_ ui32 attr = ::GetFileAttributesA(path); *trv = '/'; if (attr == 0xFFFFFFFF) @@ -104,7 +104,7 @@ GetTemp(char* path, int* doopen, int domkdir, int slen) errno = ENOTDIR; return (0); } -#else +#else rval = stat(path, &sbuf); *trv = '/'; if (rval != 0) { @@ -114,7 +114,7 @@ GetTemp(char* path, int* doopen, int domkdir, int slen) errno = ENOTDIR; return (0); } -#endif +#endif break; } } @@ -137,14 +137,14 @@ GetTemp(char* path, int* doopen, int domkdir, int slen) return (0); } } else -#ifdef _win32_ +#ifdef _win32_ if (::GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) return (errno == ENOENT); -#else +#else if (lstat(path, &sbuf)) { return (errno == ENOENT); } -#endif +#endif /* If we have a collision, cycle through the space of filenames */ for (trv = start;;) { if (*trv == '\0' || trv == suffp) { diff --git a/util/system/platform.h b/util/system/platform.h index 58f310ab34..5c4abea622 100644 --- a/util/system/platform.h +++ b/util/system/platform.h @@ -138,10 +138,10 @@ #define _sse2_ #endif -#if defined(__SSE3__) || defined(SSE3_ENABLED) +#if defined(__SSE3__) || defined(SSE3_ENABLED) #define _sse3_ -#endif - +#endif + #if defined(__SSSE3__) || defined(SSSE3_ENABLED) #define _ssse3_ #endif diff --git a/util/system/progname.cpp b/util/system/progname.cpp index 2c29119320..4e3a173a64 100644 --- a/util/system/progname.cpp +++ b/util/system/progname.cpp @@ -1,4 +1,4 @@ -#include "execpath.h" +#include "execpath.h" #include "progname.h" #include <util/folder/dirut.h> diff --git a/util/system/rusage.cpp b/util/system/rusage.cpp index 2befeca875..800a685cb9 100644 --- a/util/system/rusage.cpp +++ b/util/system/rusage.cpp @@ -109,7 +109,7 @@ void TRusage::Fill() { } #if defined(_darwin_) - // see https://lists.apple.com/archives/darwin-kernel/2009/Mar/msg00005.html + // see https://lists.apple.com/archives/darwin-kernel/2009/Mar/msg00005.html MaxRss = ru.ru_maxrss; #else MaxRss = ru.ru_maxrss * 1024LL; diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 9d849279d2..458ecd0025 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -298,7 +298,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { // this ut is unix-only, port to win using %TEMP% Y_UNIT_TEST(TestInterrupt) { TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); - + TShellCommandOptions options; options.SetAsync(true); options.SetQuoteArguments(false); diff --git a/util/system/user.cpp b/util/system/user.cpp index 83e89ea0a8..8c66a8ce95 100644 --- a/util/system/user.cpp +++ b/util/system/user.cpp @@ -1,18 +1,18 @@ -#include "user.h" -#include "platform.h" -#include "defaults.h" +#include "user.h" +#include "platform.h" +#include "defaults.h" #include "env.h" - -#include <util/generic/yexception.h> - -#ifdef _win_ + +#include <util/generic/yexception.h> + +#ifdef _win_ #include "winint.h" -#else +#else #include <errno.h> #include <pwd.h> #include <unistd.h> -#endif - +#endif + TString GetUsername() { for (const auto& var : {"LOGNAME", "USER", "LNAME", "USERNAME"}) { TString val = GetEnv(var); @@ -21,19 +21,19 @@ TString GetUsername() { } } - TTempBuf nameBuf; - for (;;) { -#if defined(_win_) - DWORD len = (DWORD)Min(nameBuf.Size(), size_t(32767)); + TTempBuf nameBuf; + for (;;) { +#if defined(_win_) + DWORD len = (DWORD)Min(nameBuf.Size(), size_t(32767)); if (!GetUserNameA(nameBuf.Data(), &len)) { - DWORD err = GetLastError(); - if ((err == ERROR_INSUFFICIENT_BUFFER) && (nameBuf.Size() <= 32767)) - nameBuf = TTempBuf((size_t)len); - else - ythrow TSystemError(err) << " GetUserName failed"; - } else { + DWORD err = GetLastError(); + if ((err == ERROR_INSUFFICIENT_BUFFER) && (nameBuf.Size() <= 32767)) + nameBuf = TTempBuf((size_t)len); + else + ythrow TSystemError(err) << " GetUserName failed"; + } else { return TString(nameBuf.Data(), (size_t)(len - 1)); - } + } #elif defined(_bionic_) const passwd* pwd = getpwuid(geteuid()); @@ -43,16 +43,16 @@ TString GetUsername() { ythrow TSystemError() << TStringBuf(" getpwuid failed"); #else - passwd pwd; - passwd* tmpPwd; - int err = getpwuid_r(geteuid(), &pwd, nameBuf.Data(), nameBuf.Size(), &tmpPwd); + passwd pwd; + passwd* tmpPwd; + int err = getpwuid_r(geteuid(), &pwd, nameBuf.Data(), nameBuf.Size(), &tmpPwd); if (err == 0 && tmpPwd) { return TString(pwd.pw_name); } else if (err == ERANGE) { nameBuf = TTempBuf(nameBuf.Size() * 2); - } else { + } else { ythrow TSystemError(err) << " getpwuid_r failed"; - } -#endif - } -} + } +#endif + } +} diff --git a/util/system/user.h b/util/system/user.h index be348d1cee..e426a79a9e 100644 --- a/util/system/user.h +++ b/util/system/user.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include <util/generic/fwd.h> - + TString GetUsername(); diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index 127e7c261e..76e8db9225 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -51,7 +51,7 @@ SRCS( system/hi_lo_ut.cpp system/hostname_ut.cpp system/info_ut.cpp - system/interrupt_signals_ut.cpp + system/interrupt_signals_ut.cpp system/mem_info_ut.cpp system/mincore_ut.cpp system/mutex_ut.cpp diff --git a/util/ya.make b/util/ya.make index 6ebe7e40cf..9d22bff2d9 100644 --- a/util/ya.make +++ b/util/ya.make @@ -288,7 +288,7 @@ JOIN_SRCS( system/cpu_id.cpp system/fhandle.cpp system/guard.cpp - system/interrupt_signals.cpp + system/interrupt_signals.cpp system/madvise.cpp system/maxlen.cpp system/mem_info.cpp |