diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (patch) | |
tree | e98df59de24d2ef7c77baed9f41e4875a2fef972 | |
parent | bd30392c4cc92487950adc375c07adf52da1d592 (diff) | |
download | ydb-43f5a35593ebc9f6bcea619bb170394ea7ae468e.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 2 of 2.
161 files changed, 2669 insertions, 2669 deletions
diff --git a/build/plugins/split_codegen.py b/build/plugins/split_codegen.py index 2e6cecbca1..f1e60bc142 100644 --- a/build/plugins/split_codegen.py +++ b/build/plugins/split_codegen.py @@ -1,11 +1,11 @@ from _common import sort_by_keywords -# This hard-coded many times in CppParts in various codegens -_DEFAULT_CPP_PARTS = 20 -# See TCodegenParams::MethodStream usage in factor codegen -_ADDITIONAL_STREAM_COUNT = 5 +# This hard-coded many times in CppParts in various codegens +_DEFAULT_CPP_PARTS = 20 +# See TCodegenParams::MethodStream usage in factor codegen +_ADDITIONAL_STREAM_COUNT = 5 + - def onsplit_codegen(unit, *args): ''' @usage: SPLIT_CODEGEN(tool prefix opts... [OUT_NUM num] [OUTPUT_INCLUDES output_includes...]) @@ -19,10 +19,10 @@ def onsplit_codegen(unit, *args): keywords = {"OUT_NUM": 1} flat_args, spec_args = sort_by_keywords(keywords, args) - num_outputs = _DEFAULT_CPP_PARTS + _ADDITIONAL_STREAM_COUNT - if "OUT_NUM" in spec_args: - num_outputs = int(spec_args["OUT_NUM"][0]) - + num_outputs = _DEFAULT_CPP_PARTS + _ADDITIONAL_STREAM_COUNT + if "OUT_NUM" in spec_args: + num_outputs = int(spec_args["OUT_NUM"][0]) + tool = flat_args[0] prefix = flat_args[1] @@ -30,14 +30,14 @@ def onsplit_codegen(unit, *args): for num in range(num_outputs): cmd.append('{}.{}.cpp'.format(prefix, num)) - cpp_parts = int(num_outputs) - _ADDITIONAL_STREAM_COUNT - cpp_parts_args = ['--cpp-parts', str(cpp_parts)] - + cpp_parts = int(num_outputs) - _ADDITIONAL_STREAM_COUNT + cpp_parts_args = ['--cpp-parts', str(cpp_parts)] + if len(flat_args) > 2: if flat_args[2] != 'OUTPUT_INCLUDES': cmd.append('OPTS') - cmd += cpp_parts_args + flat_args[2:] - else: - cmd += ['OPTS'] + cpp_parts_args + cmd += cpp_parts_args + flat_args[2:] + else: + cmd += ['OPTS'] + cpp_parts_args unit.on_split_codegen_base(cmd) diff --git a/build/ya.conf.json b/build/ya.conf.json index 396cb8890a..5f7cc875d6 100644 --- a/build/ya.conf.json +++ b/build/ya.conf.json @@ -460,9 +460,9 @@ "iceflame": { "description": "Performance data collection and analysis" }, - "cs": { - "description": "Fast CodeSearch CLI tool" - }, + "cs": { + "description": "Fast CodeSearch CLI tool" + }, "wall-e": { "description": "Client for Wall-E" }, @@ -3508,13 +3508,13 @@ } ] }, - "ag": { - "tools": { + "ag": { + "tools": { "ag": { "bottle": "ag", "executable": "ag" } - }, + }, "platforms": [ { "host": { @@ -3523,7 +3523,7 @@ "default": true } ] - }, + }, "yf": { "tools": { "yf": { @@ -5578,28 +5578,28 @@ } ] }, - "cs": { - "tools": { - "cs": { - "bottle": "cs", - "executable": "cs" - } - }, - "platforms": [ - { - "host": { - "os": "LINUX" - }, - "default": true - }, - { - "host": { - "os": "DARWIN" - }, - "default": true - } - ] - }, + "cs": { + "tools": { + "cs": { + "bottle": "cs", + "executable": "cs" + } + }, + "platforms": [ + { + "host": { + "os": "LINUX" + }, + "default": true + }, + { + "host": { + "os": "DARWIN" + }, + "default": true + } + ] + }, "wall-e": { "tools": { "wall-e": { @@ -6768,17 +6768,17 @@ ] } }, - "ag": { - "formula": { + "ag": { + "formula": { "sandbox_id": 75851513, - "match": "Ag" - }, - "executable": { + "match": "Ag" + }, + "executable": { "ag": [ "ag" ] - } - }, + } + }, "valgrind": { "formula": { "sandbox_id": 944969271, @@ -7885,17 +7885,17 @@ ] } }, - "cs": { - "formula": { + "cs": { + "formula": { "sandbox_id": 1206856496, - "match": "cs" - }, - "executable": { - "cs": [ - "cs" - ] - } - }, + "match": "cs" + }, + "executable": { + "cs": [ + "cs" + ] + } + }, "wall-e": { "formula": { "sandbox_id": 1085675590, diff --git a/build/ymake.core.conf b/build/ymake.core.conf index dd5d45e9b5..081833998b 100644 --- a/build/ymake.core.conf +++ b/build/ymake.core.conf @@ -297,7 +297,7 @@ USE_VANILLA_PROTOC=no FML_TOOL=${tool:"tools/relev_fml_codegen"} FML_UNUSED_TOOL=${tool:"tools/relev_fml_unused"} LUA_TOOL=${tool:"tools/lua"} -ENUM_PARSER_TOOL=${tool:"tools/enum_parser/enum_parser"} +ENUM_PARSER_TOOL=${tool:"tools/enum_parser/enum_parser"} # tag:python-specific tag:cython-specific CYTHON_SCRIPT=${input:"${ARCADIA_ROOT}/contrib/tools/cython/cython.py"} @@ -5375,7 +5375,7 @@ when ($STRIP_DEBUG_INFO) { ### @usage: SPLIT_DWARF() ### ### Emit debug info for the PROGRAM/DLL as a separate file <module_name>.debug. -### NB: It does not help you to save process RSS but can add problems (see e.g. BEGEMOT-2147). +### NB: It does not help you to save process RSS but can add problems (see e.g. BEGEMOT-2147). macro SPLIT_DWARF() { SET(SPLIT_DWARF_VALUE yes) } @@ -6506,8 +6506,8 @@ macro CONFIGURE_FILE(Src, Dst) { ### Generator ${prefix}.cpp + ${prefix}.h files based on ${prefix}.in. macro BASE_CODEGEN(Tool, Prefix, Opts...) { .CMD=${tool:Tool} ${input:Prefix.in} ${output;nopath;noauto:Prefix.cpp} ${output;nopath:Prefix.h} $Opts ${kv;hide:"p BC"} ${kv;hide:"pc yellow"} -} - +} + # tag:internal ### @usage: _SPLIT_CODEGEN_BASE(tool prefix OUTS[] OUTPUT_INCLUDES[]) # internal ### @@ -6803,7 +6803,7 @@ macro _MX_GEN_TABLE(Srcs...) { } RELEV_FML_CODEGEN_INCLS=${output_include;hide:"kernel/relevfml/relev_fml.h"} ${output_include;hide:"library/cpp/sse/sse.h"} - + ### @usage: GENERATE_ENUM_SERIALIZATION(File.h) ### ### Create serialization support for enumeration members defined in the header (String <-> Enum conversions) and compile it into the module. diff --git a/contrib/README.md b/contrib/README.md index fac84ee1d6..44863a0baf 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -58,8 +58,8 @@ Happy Path Ð´Ð»Ñ Ð¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ñ‚ÐµÐ»Ñ, которому понадобилР[Arcadia WG](https://abc.yandex-team.ru/services/arcadia-wg/) привлекаетÑÑ Ð¿Ñ€Ð¾Ñ„Ð¸Ð»ÑŒÐ½Ñ‹Ð¼Ð¸ комитетами Ð´Ð»Ñ Ð¾Ð±ÑÑƒÐ¶Ð´ÐµÐ½Ð¸Ñ Ñложных Ñлучаев (еÑÑ‚ÑŒ ÑомнениÑ, проблемы Ñ Ð»Ð¸Ñ†ÐµÐ½Ð·Ð¸Ñми). -ÐžÐ³Ñ€Ð°Ð½Ð¸Ñ‡ÐµÐ½Ð¸Ñ Ð¸ÑÐ¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐº контролируетÑÑ [макроÑами ÑƒÐ¿Ñ€Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð»Ð¸Ñ†ÐµÐ½Ð·Ð¸Ñми](https://docs.yandex-team.ru/ya-make/general/rules#licenzii). - +ÐžÐ³Ñ€Ð°Ð½Ð¸Ñ‡ÐµÐ½Ð¸Ñ Ð¸ÑÐ¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐº контролируетÑÑ [макроÑами ÑƒÐ¿Ñ€Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð»Ð¸Ñ†ÐµÐ½Ð·Ð¸Ñми](https://docs.yandex-team.ru/ya-make/general/rules#licenzii). + Итого, процеÑÑ ÑоÑтоит из Ñтапов: * Подтверждение от Ñзыкового комитета (1) diff --git a/contrib/libs/pire/pire/encoding.cpp b/contrib/libs/pire/pire/encoding.cpp index 2405602704..842e2b534d 100644 --- a/contrib/libs/pire/pire/encoding.cpp +++ b/contrib/libs/pire/pire/encoding.cpp @@ -11,7 +11,7 @@ * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * Pire is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -39,8 +39,8 @@ namespace { class Latin1: public Encoding { public: - Latin1() : Encoding() {} - + Latin1() : Encoding() {} + wchar32 FromLocal(const char*& begin, const char* end) const { if (begin == end) @@ -61,7 +61,7 @@ namespace { void AppendDot(Fsm& fsm) const { fsm.AppendDot(); } }; - + namespace UtfRanges { static const size_t MaxLen = 4; @@ -74,11 +74,11 @@ namespace { static const size_t Next[2] = {0x80, 0xC0}; } - + class Utf8: public Encoding { public: - Utf8() : Encoding() {} - + Utf8() : Encoding() {} + wchar32 FromLocal(const char*& begin, const char* end) const { wchar32 rune; @@ -117,16 +117,16 @@ namespace { namespace Encodings { - const Encoding& Utf8() + const Encoding& Utf8() { static const Pire::Utf8 utf8; - return utf8; + return utf8; } - const Encoding& Latin1() + const Encoding& Latin1() { - static const Pire::Latin1 latin1; - return latin1; + static const Pire::Latin1 latin1; + return latin1; } } diff --git a/contrib/libs/ya.make b/contrib/libs/ya.make index 4927c3eaf3..9c4640fdcf 100644 --- a/contrib/libs/ya.make +++ b/contrib/libs/ya.make @@ -107,7 +107,7 @@ RECURSE( hwloc hyperscan i18n - i18n/ut + i18n/ut icu ImageMagick inja diff --git a/contrib/restricted/boost/README.md b/contrib/restricted/boost/README.md index de72851a21..a33f951cc3 100644 --- a/contrib/restricted/boost/README.md +++ b/contrib/restricted/boost/README.md @@ -1,15 +1,15 @@ -ÐžÐ³Ñ€Ð°Ð½Ð¸Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ñ€Ð¸ иÑпользовании библиотеки boost в Ðркадии -======================================================== - -1. Старые проекты извне аркадии могут иÑпользовать `boost` -2. Можно иÑпользовать `boost`, когда нет альтернативы (внутренней или внешней). - ЕÑли хочетÑÑ Ð¸Ñпользовать boost, заведите тикет в очереди CONTRIB [1], - обоÑнуйте в нём необходимоÑÑ‚ÑŒ и получите OK от Комитета CONTRIB [2]. -3. Можно иÑпользовать `boost` по завиÑимоÑÑ‚Ñм от `contrib/`. Ð’ `library/` нельзÑ. - ЕÑÑ‚ÑŒ единÑтвенное иÑключение в `library/`, но Ñто недоработка того, - что никак не положат новую верÑию `hyperscan`: IGNIETFERRO-588 [3] -4. РекомендуетÑÑ Ð¿Ñ€Ñтать в `.cpp`, чтобы не ÑветилоÑÑŒ в заголовках. - -[1] https://st.yandex-team.ru/CONTRIB -[2] https://wiki.yandex-team.ru/arcadia/faq/add-to-contrib-howto/ -[3] https://st.yandex-team.ru/IGNIETFERRO-588 +ÐžÐ³Ñ€Ð°Ð½Ð¸Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ñ€Ð¸ иÑпользовании библиотеки boost в Ðркадии +======================================================== + +1. Старые проекты извне аркадии могут иÑпользовать `boost` +2. Можно иÑпользовать `boost`, когда нет альтернативы (внутренней или внешней). + ЕÑли хочетÑÑ Ð¸Ñпользовать boost, заведите тикет в очереди CONTRIB [1], + обоÑнуйте в нём необходимоÑÑ‚ÑŒ и получите OK от Комитета CONTRIB [2]. +3. Можно иÑпользовать `boost` по завиÑимоÑÑ‚Ñм от `contrib/`. Ð’ `library/` нельзÑ. + ЕÑÑ‚ÑŒ единÑтвенное иÑключение в `library/`, но Ñто недоработка того, + что никак не положат новую верÑию `hyperscan`: IGNIETFERRO-588 [3] +4. РекомендуетÑÑ Ð¿Ñ€Ñтать в `.cpp`, чтобы не ÑветилоÑÑŒ в заголовках. + +[1] https://st.yandex-team.ru/CONTRIB +[2] https://wiki.yandex-team.ru/arcadia/faq/add-to-contrib-howto/ +[3] https://st.yandex-team.ru/IGNIETFERRO-588 diff --git a/contrib/tools/ragel6/parsedata.cpp b/contrib/tools/ragel6/parsedata.cpp index fd92cbb5bc..eafe73e524 100644 --- a/contrib/tools/ragel6/parsedata.cpp +++ b/contrib/tools/ragel6/parsedata.cpp @@ -115,7 +115,7 @@ Key makeFsmKeyHex( char *str, const InputLoc &loc, ParseData *pd ) } if ( unusedBits && keyOps->alphType->isSigned && ul >> (size * 8 - 1) ) - ul |= ( (unsigned long)(-1L) >> (size*8) ) << (size*8); + ul |= ( (unsigned long)(-1L) >> (size*8) ) << (size*8); return Key( (long)ul ); } diff --git a/library/README.md b/library/README.md index b9bde7ea66..fc418bef7b 100644 --- a/library/README.md +++ b/library/README.md @@ -1,20 +1,20 @@ library === `library/` is a directory with reusable libraries. Common ideas (with [key words](https://tools.ietf.org/html/rfc2119)): - + 1. Libraries are categorized by the languages in which they will be used. Bindings **MUST** be put in `<language>` directory. - + 2. Grouping by any other criteria **SHOULD** be defined by the language committee in `<language>` directory. - + 3. The library **SHOULD** be in use in at least two projects. If you are not sure if you should put some library in `library/`, please contact `<language>` committee or arcadia-wg@yandex-team.ru. - + 4. The library **SHOULD** be portable. Please contact `<language>` committee if you cannot provide usage on all platforms: `linux`, `darwin`, `windows`. - + 5. The library **MUST** depend only on a limited list of external components (currently it is `util/`, `contrib/`, `vendor/`, `library/`). diff --git a/library/cpp/balloc/balloc.cpp b/library/cpp/balloc/balloc.cpp index 4fb8cdfc65..fab489db4c 100644 --- a/library/cpp/balloc/balloc.cpp +++ b/library/cpp/balloc/balloc.cpp @@ -200,12 +200,12 @@ void operator delete[](void* p, const std::nothrow_t&) OP_THROWNOTHING { #endif } -extern "C" void* calloc(size_t n, size_t elemSize) { - const size_t size = n * elemSize; +extern "C" void* calloc(size_t n, size_t elemSize) { + const size_t size = n * elemSize; - if (elemSize != 0 && size / elemSize != n) { - return nullptr; - } + if (elemSize != 0 && size / elemSize != n) { + return nullptr; + } #if defined(Y_COVER_PTR) void* result = malloc(size); @@ -213,7 +213,7 @@ extern "C" void* calloc(size_t n, size_t elemSize) { void* result = NBalloc::Malloc(size); #endif - if (result) { + if (result) { memset(result, 0, size); } @@ -231,19 +231,19 @@ extern "C" void cfree(void* ptr) { #if defined(Y_COVER_PTR) static inline void* DoRealloc(void* oldPtr, size_t newSize) { #else -extern "C" void* realloc(void* oldPtr, size_t newSize) { +extern "C" void* realloc(void* oldPtr, size_t newSize) { #endif - if (!oldPtr) { + if (!oldPtr) { void* result = NBalloc::Malloc(newSize); return result; } if (newSize == 0) { NBalloc::Free(oldPtr); - return nullptr; + return nullptr; } void* newPtr = NBalloc::Malloc(newSize); - if (!newPtr) { - return nullptr; + if (!newPtr) { + return nullptr; } NBalloc::TAllocHeader* header = (NBalloc::TAllocHeader*)oldPtr - 1; const size_t oldSize = header->AllocSize & ~NBalloc::SIGNATURE_MASK; @@ -253,8 +253,8 @@ extern "C" void* realloc(void* oldPtr, size_t newSize) { NBalloc::Free(oldPtr); return newPtr; } - NMalloc::AbortFromCorruptedAllocator(); - return nullptr; + NMalloc::AbortFromCorruptedAllocator(); + return nullptr; } #if defined(Y_COVER_PTR) diff --git a/library/cpp/balloc/ya.make b/library/cpp/balloc/ya.make index 84b634c24e..d4457fbba9 100644 --- a/library/cpp/balloc/ya.make +++ b/library/cpp/balloc/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( - ironpeter +OWNER( + ironpeter g:base -) +) NO_UTIL() NO_COMPILER_WARNINGS() diff --git a/library/cpp/blockcodecs/README.md b/library/cpp/blockcodecs/README.md index b8e9bf16dc..417917a475 100644 --- a/library/cpp/blockcodecs/README.md +++ b/library/cpp/blockcodecs/README.md @@ -1,20 +1,20 @@ -This is a simple library for block data compression (this means data is compressed/uncompressed +This is a simple library for block data compression (this means data is compressed/uncompressed by whole blocks in memory). It's a lite-version of the `library/cpp/codecs`. Lite here means that it -provide only well-known compression algorithms, without the possibility of learning. - -There are two possible ways to work with it. - -Codec by name -============= -Use `NBlockCodec::Codec` to obtain the codec by name. The codec can be asked to compress -or decompress something and in various ways. - -To get a full list of codecs there is a function `NBlockCodecs::ListAllCodecs()`. - -Streaming -========= -Use `stream.h` to obtain simple streams over block codecs (buffer data, compress them by blocks, -write to the resulting stream). +provide only well-known compression algorithms, without the possibility of learning. + +There are two possible ways to work with it. + +Codec by name +============= +Use `NBlockCodec::Codec` to obtain the codec by name. The codec can be asked to compress +or decompress something and in various ways. + +To get a full list of codecs there is a function `NBlockCodecs::ListAllCodecs()`. + +Streaming +========= +Use `stream.h` to obtain simple streams over block codecs (buffer data, compress them by blocks, +write to the resulting stream). Using codec plugins =================== diff --git a/library/cpp/blockcodecs/codecs_ut.cpp b/library/cpp/blockcodecs/codecs_ut.cpp index f9e876327b..bfe5a23690 100644 --- a/library/cpp/blockcodecs/codecs_ut.cpp +++ b/library/cpp/blockcodecs/codecs_ut.cpp @@ -269,27 +269,27 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { Y_UNIT_TEST(TestStreams19) { TestStreams(20, 19); } - - Y_UNIT_TEST(TestMaxPossibleDecompressedSize) { - - UNIT_ASSERT_VALUES_EQUAL(GetMaxPossibleDecompressedLength(), Max<size_t>()); - - TVector<char> input(10001, ' '); - TCodecList codecs = ListAllCodecs(); - SetMaxPossibleDecompressedLength(10000); - - for (const auto& codec : codecs) { - const ICodec* c = Codec(codec); - TBuffer inputBuffer(input.data(), input.size()); - TBuffer output; - TBuffer decompressed; - c->Encode(inputBuffer, output); - UNIT_ASSERT_EXCEPTION(c->Decode(output, decompressed), yexception); - } - - // restore status quo - SetMaxPossibleDecompressedLength(Max<size_t>()); - } + + Y_UNIT_TEST(TestMaxPossibleDecompressedSize) { + + UNIT_ASSERT_VALUES_EQUAL(GetMaxPossibleDecompressedLength(), Max<size_t>()); + + TVector<char> input(10001, ' '); + TCodecList codecs = ListAllCodecs(); + SetMaxPossibleDecompressedLength(10000); + + for (const auto& codec : codecs) { + const ICodec* c = Codec(codec); + TBuffer inputBuffer(input.data(), input.size()); + TBuffer output; + TBuffer decompressed; + c->Encode(inputBuffer, output); + UNIT_ASSERT_EXCEPTION(c->Decode(output, decompressed), yexception); + } + + // restore status quo + SetMaxPossibleDecompressedLength(Max<size_t>()); + } Y_UNIT_TEST(TestListAllCodecs) { static const TString ALL_CODECS = diff --git a/library/cpp/blockcodecs/core/codecs.cpp b/library/cpp/blockcodecs/core/codecs.cpp index 332b671221..21506e812b 100644 --- a/library/cpp/blockcodecs/core/codecs.cpp +++ b/library/cpp/blockcodecs/core/codecs.cpp @@ -64,9 +64,9 @@ namespace { TVector<TCodecPtr> Codecs; typedef THashMap<TStringBuf, ICodec*> TRegistry; TRegistry Registry; - - // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) - size_t MaxPossibleDecompressedLength = Max<size_t>(); + + // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) + size_t MaxPossibleDecompressedLength = Max<size_t>(); }; } @@ -94,25 +94,25 @@ void NBlockCodecs::RegisterAlias(TStringBuf from, TStringBuf to) { Singleton<TCodecFactory>()->Alias(from, to); } -void NBlockCodecs::SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength) { - Singleton<TCodecFactory>()->MaxPossibleDecompressedLength = maxPossibleDecompressedLength; -} - -size_t NBlockCodecs::GetMaxPossibleDecompressedLength() { - return Singleton<TCodecFactory>()->MaxPossibleDecompressedLength; -} - -size_t ICodec::GetDecompressedLength(const TData& in) const { - const size_t len = DecompressedLength(in); - - Y_ENSURE( - len <= NBlockCodecs::GetMaxPossibleDecompressedLength(), - "Attempt to decompress the block that is larger than maximum possible decompressed length, " - "see SEARCH-8344 for details. " - ); - return len; -} - +void NBlockCodecs::SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength) { + Singleton<TCodecFactory>()->MaxPossibleDecompressedLength = maxPossibleDecompressedLength; +} + +size_t NBlockCodecs::GetMaxPossibleDecompressedLength() { + return Singleton<TCodecFactory>()->MaxPossibleDecompressedLength; +} + +size_t ICodec::GetDecompressedLength(const TData& in) const { + const size_t len = DecompressedLength(in); + + Y_ENSURE( + len <= NBlockCodecs::GetMaxPossibleDecompressedLength(), + "Attempt to decompress the block that is larger than maximum possible decompressed length, " + "see SEARCH-8344 for details. " + ); + return len; +} + void ICodec::Encode(const TData& in, TBuffer& out) const { const size_t maxLen = MaxCompressedLength(in); @@ -121,7 +121,7 @@ void ICodec::Encode(const TData& in, TBuffer& out) const { } void ICodec::Decode(const TData& in, TBuffer& out) const { - const size_t len = GetDecompressedLength(in); + const size_t len = GetDecompressedLength(in); out.Reserve(len); out.Resize(Decompress(in, out.Data())); diff --git a/library/cpp/blockcodecs/core/codecs.h b/library/cpp/blockcodecs/core/codecs.h index 2fede1f029..9c93c00274 100644 --- a/library/cpp/blockcodecs/core/codecs.h +++ b/library/cpp/blockcodecs/core/codecs.h @@ -39,7 +39,7 @@ namespace NBlockCodecs { struct ICodec { virtual ~ICodec(); - // main interface + // main interface virtual size_t DecompressedLength(const TData& in) const = 0; virtual size_t MaxCompressedLength(const TData& in) const = 0; virtual size_t Compress(const TData& in, void* out) const = 0; @@ -47,7 +47,7 @@ namespace NBlockCodecs { virtual TStringBuf Name() const noexcept = 0; - // some useful helpers + // some useful helpers void Encode(const TData& in, TBuffer& out) const; void Decode(const TData& in, TBuffer& out) const; @@ -69,22 +69,22 @@ namespace NBlockCodecs { return out; } - private: - size_t GetDecompressedLength(const TData& in) const; + private: + size_t GetDecompressedLength(const TData& in) const; }; using TCodecPtr = THolder<ICodec>; const ICodec* Codec(const TStringBuf& name); - // some aux methods + // some aux methods typedef TVector<TStringBuf> TCodecList; TCodecList ListAllCodecs(); TString ListAllCodecsAsString(); - - // SEARCH-8344: Get the size of max possible decompressed block - size_t GetMaxPossibleDecompressedLength(); - // SEARCH-8344: Globally set the size of max possible decompressed block - void SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength); - + + // SEARCH-8344: Get the size of max possible decompressed block + size_t GetMaxPossibleDecompressedLength(); + // SEARCH-8344: Globally set the size of max possible decompressed block + void SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength); + } diff --git a/library/cpp/build_info/build_info.h b/library/cpp/build_info/build_info.h index d8e3843f03..a494870ba3 100644 --- a/library/cpp/build_info/build_info.h +++ b/library/cpp/build_info/build_info.h @@ -1,6 +1,6 @@ #pragma once -#include "sandbox.h" +#include "sandbox.h" #include "build_info_static.h" #if defined(__cplusplus) diff --git a/library/cpp/build_info/sandbox.cpp.in b/library/cpp/build_info/sandbox.cpp.in index 071268c197..ac3b2d9004 100644 --- a/library/cpp/build_info/sandbox.cpp.in +++ b/library/cpp/build_info/sandbox.cpp.in @@ -1,27 +1,27 @@ #include <library/cpp/build_info/sandbox.h> #include <library/cpp/string_utils/base64/base64.h> -#include <util/generic/string.h> -#include <util/string/subst.h> - -extern "C" const char* GetSandboxTaskId() { - return "@SANDBOX_TASK_ID@"; -} - -class TKosherVersionHolder { -public: - const char* Version() const { - if (!Version_) { - TString version = "@KOSHER_SVN_VERSION@"; - SubstGlobal(version, ".", "="); - Version_ = Base64Decode(version); - } - return Version_.c_str(); - } -private: - mutable TString Version_; -}; - -// Experimental code for RMDEV-365 -extern "C" const char* GetKosherSvnVersion() { - return Singleton<TKosherVersionHolder>()->Version(); -} +#include <util/generic/string.h> +#include <util/string/subst.h> + +extern "C" const char* GetSandboxTaskId() { + return "@SANDBOX_TASK_ID@"; +} + +class TKosherVersionHolder { +public: + const char* Version() const { + if (!Version_) { + TString version = "@KOSHER_SVN_VERSION@"; + SubstGlobal(version, ".", "="); + Version_ = Base64Decode(version); + } + return Version_.c_str(); + } +private: + mutable TString Version_; +}; + +// Experimental code for RMDEV-365 +extern "C" const char* GetKosherSvnVersion() { + return Singleton<TKosherVersionHolder>()->Version(); +} diff --git a/library/cpp/build_info/sandbox.h b/library/cpp/build_info/sandbox.h index 331340db18..924ff89c8c 100644 --- a/library/cpp/build_info/sandbox.h +++ b/library/cpp/build_info/sandbox.h @@ -1,12 +1,12 @@ -#pragma once - -#if defined(__cplusplus) -extern "C" { -#endif - +#pragma once + +#if defined(__cplusplus) +extern "C" { +#endif + const char* GetSandboxTaskId(); -const char* GetKosherSvnVersion(); - -#if defined(__cplusplus) -} -#endif +const char* GetKosherSvnVersion(); + +#if defined(__cplusplus) +} +#endif diff --git a/library/cpp/build_info/ya.make b/library/cpp/build_info/ya.make index 1ddbe0d7df..99886a8893 100644 --- a/library/cpp/build_info/ya.make +++ b/library/cpp/build_info/ya.make @@ -11,12 +11,12 @@ DEFAULT(KOSHER_SVN_VERSION "") CREATE_BUILDINFO_FOR(buildinfo_data.h) -PEERDIR( +PEERDIR( library/cpp/string_utils/base64 -) - +) + SRCS( - sandbox.cpp.in + sandbox.cpp.in build_info.cpp.in build_info_static.cpp ) diff --git a/library/cpp/cgiparam/cgiparam.h b/library/cpp/cgiparam/cgiparam.h index a153461f8b..87d1ab0ad4 100644 --- a/library/cpp/cgiparam/cgiparam.h +++ b/library/cpp/cgiparam/cgiparam.h @@ -21,7 +21,7 @@ public: TCgiParameters() = default; explicit TCgiParameters(const TStringBuf cgiParamStr) { - Scan(cgiParamStr); + Scan(cgiParamStr); } TCgiParameters(std::initializer_list<std::pair<TString, TString>> il); @@ -75,9 +75,9 @@ public: Y_PURE_FUNCTION bool Has(const TStringBuf name) const noexcept { - const auto pair = equal_range(name); - return pair.first != pair.second; - } + const auto pair = equal_range(name); + return pair.first != pair.second; + } /// Returns value by name /** * @note The returned value is CGI-unescaped. diff --git a/library/cpp/charset/recyr.hh b/library/cpp/charset/recyr.hh index 7d05a2e268..5ec8734bcf 100644 --- a/library/cpp/charset/recyr.hh +++ b/library/cpp/charset/recyr.hh @@ -4,7 +4,7 @@ #include <util/charset/recode_result.h> #include <util/generic/ptr.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #include "codepage.h" #include "doccodes.h" @@ -18,32 +18,32 @@ template <class TCharType> inline RECODE_RESULT RecodeToUnicode(ECharset from, const char* in, TCharType* out, size_t inSize, size_t outSize, size_t& inRead, size_t& outWritten) { static_assert(sizeof(TCharType) > 1, "expect wide character type"); - return NCodepagePrivate::_recodeToUnicode(from, in, out, inSize, outSize, inRead, outWritten); + return NCodepagePrivate::_recodeToUnicode(from, in, out, inSize, outSize, inRead, outWritten); } template <class TCharType> inline RECODE_RESULT RecodeFromUnicode(ECharset to, const TCharType* in, char* out, size_t inSize, size_t outSize, size_t& inRead, size_t& outWritten) { static_assert(sizeof(TCharType) > 1, "expect wide character type"); - return NCodepagePrivate::_recodeFromUnicode(to, in, out, inSize, outSize, inRead, outWritten); + return NCodepagePrivate::_recodeFromUnicode(to, in, out, inSize, outSize, inRead, outWritten); } inline RECODE_RESULT RecodeFromUnicode(ECharset to, wchar32 rune, char* out, size_t outSize, size_t& outWritten) { - return NCodepagePrivate::_recodeFromUnicode(to, rune, out, outSize, outWritten); + return NCodepagePrivate::_recodeFromUnicode(to, rune, out, outSize, outWritten); } template <class TCharType> -inline RECODE_RESULT RecodeToUnicode(ECharset from, const char* in, TCharType* out, size_t inSize, size_t outSize) { - size_t inRead = 0; - size_t outWritten = 0; - return RecodeToUnicode(from, in, out, inSize, outSize, inRead, outWritten); +inline RECODE_RESULT RecodeToUnicode(ECharset from, const char* in, TCharType* out, size_t inSize, size_t outSize) { + size_t inRead = 0; + size_t outWritten = 0; + return RecodeToUnicode(from, in, out, inSize, outSize, inRead, outWritten); } template <class TCharType> -inline RECODE_RESULT RecodeFromUnicode(ECharset to, const TCharType* in, char* out, size_t inSize, size_t outSize) { - size_t inRead = 0; - size_t outWritten = 0; - return RecodeFromUnicode(to, in, out, inSize, outSize, inRead, outWritten); +inline RECODE_RESULT RecodeFromUnicode(ECharset to, const TCharType* in, char* out, size_t inSize, size_t outSize) { + size_t inRead = 0; + size_t outWritten = 0; + return RecodeFromUnicode(to, in, out, inSize, outSize, inRead, outWritten); } inline RECODE_RESULT RecodeFromUnicode(ECharset theEncoding, const wchar16* chars, size_t length, @@ -58,76 +58,76 @@ inline RECODE_RESULT RecodeFromUnicode(ECharset theEncoding, const wchar16* char } inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* out, size_t inSize, size_t outSize, size_t& inRead, size_t& outWritten) { - inRead = 0; - outWritten = 0; + inRead = 0; + outWritten = 0; - if (!ValidCodepage(to) || !ValidCodepage(from)) + if (!ValidCodepage(to) || !ValidCodepage(from)) return RECODE_ERROR; - if (to == from) - return NCodepagePrivate::_recodeCopy(in, out, inSize, outSize, inRead, outWritten); - - if (NCodepagePrivate::NativeCodepage(from) && NCodepagePrivate::NativeCodepage(to)) { - if (from == CODES_UTF8) - return NCodepagePrivate::_recodeFromUTF8(to, in, out, inSize, outSize, inRead, outWritten); - if (to == CODES_UTF8) - return NCodepagePrivate::_recodeToUTF8(from, in, out, inSize, outSize, inRead, outWritten); - if (from == CODES_YANDEX) - return NCodepagePrivate::_recodeFromYandex(to, in, out, inSize, outSize, inRead, outWritten); - if (to == CODES_YANDEX) - return NCodepagePrivate::_recodeToYandex(from, in, out, inSize, outSize, inRead, outWritten); - } else if (NICONVPrivate::CanConvert(from, to)) { - return NICONVPrivate::RecodeNoThrow(from, to, in, out, inSize, outSize, inRead, outWritten); + if (to == from) + return NCodepagePrivate::_recodeCopy(in, out, inSize, outSize, inRead, outWritten); + + if (NCodepagePrivate::NativeCodepage(from) && NCodepagePrivate::NativeCodepage(to)) { + if (from == CODES_UTF8) + return NCodepagePrivate::_recodeFromUTF8(to, in, out, inSize, outSize, inRead, outWritten); + if (to == CODES_UTF8) + return NCodepagePrivate::_recodeToUTF8(from, in, out, inSize, outSize, inRead, outWritten); + if (from == CODES_YANDEX) + return NCodepagePrivate::_recodeFromYandex(to, in, out, inSize, outSize, inRead, outWritten); + if (to == CODES_YANDEX) + return NCodepagePrivate::_recodeToYandex(from, in, out, inSize, outSize, inRead, outWritten); + } else if (NICONVPrivate::CanConvert(from, to)) { + return NICONVPrivate::RecodeNoThrow(from, to, in, out, inSize, outSize, inRead, outWritten); } - size_t wideSize = inSize * 3; + size_t wideSize = inSize * 3; TArrayHolder<wchar16> wide(new wchar16[wideSize]); size_t wideRead = 0; size_t wideWritten = 0; - RECODE_RESULT res = RecodeToUnicode(from, in, wide.Get(), inSize, wideSize, inRead, wideWritten); + RECODE_RESULT res = RecodeToUnicode(from, in, wide.Get(), inSize, wideSize, inRead, wideWritten); if (res != RECODE_OK) return res; - res = RecodeFromUnicode(to, wide.Get(), out, wideWritten, outSize, wideRead, outWritten); + res = RecodeFromUnicode(to, wide.Get(), out, wideWritten, outSize, wideRead, outWritten); return res; } -inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* out, size_t inSize, size_t outSize) { - size_t inRead = 0; - size_t outWritten = 0; - return Recode(from, to, in, out, inSize, outSize, inRead, outWritten); +inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* out, size_t inSize, size_t outSize) { + size_t inRead = 0; + size_t outWritten = 0; + return Recode(from, to, in, out, inSize, outSize, inRead, outWritten); } /** * Recode from one charset to another; throw an exception if conversion failed - * @param[in] from the source character set - * @param[in] to the target character set + * @param[in] from the source character set + * @param[in] to the target character set * @param[in] in the input string buffer * @param[out] out the output string object if conversion was successful * @return false if conversion was not attempted (charsets were the same), * true if successful */ inline bool Recode(ECharset from, ECharset to, const TStringBuf& in, TString& out) { - if (to == from) + if (to == from) return false; - const size_t inSize = in.length(); - const size_t outSize = SingleByteCodepage(to) ? inSize : 3 * inSize; + const size_t inSize = in.length(); + const size_t outSize = SingleByteCodepage(to) ? inSize : 3 * inSize; out.clear(); // so we don't copy stuff around when resizing - out.ReserveAndResize(outSize); + out.ReserveAndResize(outSize); - size_t inRead = 0; - size_t outWritten = 0; + size_t inRead = 0; + size_t outWritten = 0; const RECODE_RESULT res = Recode(from, to, in.data(), out.begin(), inSize, outSize, inRead, outWritten); Y_ENSURE(RECODE_OK == res, "Recode failed. "); - if (outWritten > outSize) + if (outWritten > outSize) ythrow yexception() << "Recode overrun the buffer: size=" << outSize << " need=" << outWritten; - out.remove(outWritten); + out.remove(outWritten); return true; } @@ -136,29 +136,29 @@ inline bool Recode(ECharset from, ECharset to, const TStringBuf& in, TString& ou /////////////////////////////////////////////////////////////////////////////////////// inline TString Recode(ECharset from, ECharset to, const TString& in) { TString out; - return to != from && Recode(from, to, in, out) ? out : in; + return to != from && Recode(from, to, in, out) ? out : in; } inline TString RecodeToYandex(ECharset from, const TString& in) { - return Recode(from, CODES_YANDEX, in); + return Recode(from, CODES_YANDEX, in); } inline TString RecodeFromYandex(ECharset to, const TString& in) { - return Recode(CODES_YANDEX, to, in); + return Recode(CODES_YANDEX, to, in); } inline TString RecodeToHTMLEntities(ECharset from, const TString& in) { RECODE_RESULT res; - size_t outWritten, inRead; + size_t outWritten, inRead; TString out; out.resize(in.length() * (4 + 4)); - res = NCodepagePrivate::_recodeToHTMLEntities(from, in.c_str(), out.begin(), in.length(), out.length(), inRead, outWritten); + res = NCodepagePrivate::_recodeToHTMLEntities(from, in.c_str(), out.begin(), in.length(), out.length(), inRead, outWritten); if (res == RECODE_EOOUTPUT) { //input contains many 8-byte characters? out.resize(in.length() * (4 + 8)); - res = NCodepagePrivate::_recodeToHTMLEntities(from, in.c_str(), out.begin(), in.length(), out.length(), inRead, outWritten); + res = NCodepagePrivate::_recodeToHTMLEntities(from, in.c_str(), out.begin(), in.length(), out.length(), inRead, outWritten); } if (res != RECODE_OK) { ythrow yexception() << "Recode to HTML entities failed"; } - out.resize(outWritten - 1); + out.resize(outWritten - 1); return out; } diff --git a/library/cpp/codecs/float_huffman.h b/library/cpp/codecs/float_huffman.h index 234c101b3e..786a8eae1d 100644 --- a/library/cpp/codecs/float_huffman.h +++ b/library/cpp/codecs/float_huffman.h @@ -1,8 +1,8 @@ #pragma once - + #include <util/generic/array_ref.h> -#include <util/generic/vector.h> -#include <util/generic/strbuf.h> +#include <util/generic/vector.h> +#include <util/generic/strbuf.h> #include <array> @@ -12,15 +12,15 @@ namespace NCodecs::NFloatHuff { class TDecoder { public: explicit TDecoder(TStringBuf data); - + TVector<float> DecodeAll(size_t sizeHint = 0); - + // Returns number of decoded floats. May be fewer than requested if the EOS is found. size_t Decode(TArrayRef<float> dest); - + // Returns the number of skipped values. size_t Skip(size_t count); - + bool HasMore() const; private: diff --git a/library/cpp/codecs/ut/float_huffman_ut.cpp b/library/cpp/codecs/ut/float_huffman_ut.cpp index e02e3f63a8..3156fb1f46 100644 --- a/library/cpp/codecs/ut/float_huffman_ut.cpp +++ b/library/cpp/codecs/ut/float_huffman_ut.cpp @@ -1,202 +1,202 @@ #include <library/cpp/codecs/float_huffman.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/stream/format.h> -#include <util/stream/output.h> + +#include <util/stream/format.h> +#include <util/stream/output.h> #include <library/cpp/string_utils/base64/base64.h> - -namespace fh = NCodecs::NFloatHuff; - + +namespace fh = NCodecs::NFloatHuff; + Y_UNIT_TEST_SUITE(FloatHuffmanTest) { - static const float Factors[] = { - 0.340582, 0.000974026, 0.487168, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0.411765, 0.921569, - 0.00390625, 0.109371, 0, 1, 0, 0, 0, 0, 0.523322, 0, 1, 0, 0, 0, 0, 0.285714, 1, - 0.008253, 1, 0, 0, 0.00993935, 0.450213, 0.000974026, 1, 1, 1, 1, 0, 0, 0.20564, - 0.97561, 0.913896, 1, 1, 0, 1, 0, 0, 0.5, 0, 0, 0, 0.1, 1, 0, 0, 0, 0, 0, 0.450923, - 0, 0.5, 0, 0, 0.20564, 0, 0.5, 0, 0, 0.20564, 0, 0, 0.0313726, 0, 1, 1, 1, 0.363636, - 0.5, 0.686073, 0.45121, 0.00574382, 0.366166, 0.413295, 1, 1, 1, 0, 0, 0, 0, 0.160784, - 0, 0.937255, 0.537255, 0.133333, 0, 0, 0, 0, 0.00392157, 0, 0.333333, 0.027451, 0.0156863, - 1, 0.105882, 1, 0.00220908, 0.000112501, 0.0111262, 0.102384, 0.00140808, 0.123581, - 0.29308, 6.57282e-06, 0.00489498, 2.10209e-05, 0.00140559, 5.907e-06, 0, 0.559322, - 0.559322, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.794765, 0, - 0.352648, 0.225904, 1, 0.047619, 0.0107276, 0.399461, 0.0304838, 0.292932, 0.00969929, - 0, 0, 0.886904, 0.714693, 0, 0.00223213, 0.000544069, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0.00507403, 0, 0, 0, 0, 0, 0.875, 0, 0, 1, 1, 1, 0, 0.20564, 0, 0.00176048, 0, - 0.000440121, 0, 0, 0, 0.000974026, 0.487168, 0, 0, 0.533333, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 1, 0, 0, 0.723187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0.206882, 0.00483367, 0.792983, 0.00126106, 1, 0.0313726, 0.470588, - 0.254902, 0.188235, 0.188235, 0.388235, 0.164706, 0, 0.870588, 0.843137, 0.635294, - 0.384314, 0.384314, 0.643137, 0, 0, 0, 0, 0, 0, 0, 0, 0.541176, 0, 0.541176, 0, 0, - 0.0532634, 1, 0, 0, 0, 0.015044, 1, 0, 1, 1, 1, 0.47451, 0.329412, 0.964706, 0, 0, - 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0941176, 0.970588, 0.970588, 0, 0.970588, 0.97561, - 0, 0.0431373, 0.47451, 0.329412, 0.964706, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0.231373, 0.00392157, 0, 0, 0, 0.054902, 0, 0, - 1, 0, 0, 0.0235294, 0, 1, 0, 0, 0, 0, 0.34902, 0.0352941, 0.925379, 0.623681, 0, - 0.954543, 0, 0, 0.00102756, 0.709804, 0.498039, 0.0901961, 0.631373, 0.847059, 0.270588, - 0.0156863, 0.133333, 0.980392, 1e-12, 1e-12, 1e-12, 1e-12, 0.497159, 0, 0.407487, - 0, 0, 0, 0.00392157, 0.00202156, 0.046875, 0.187159, 0.046875, 0.15625, 0.434232, - 0.15625, 0, 2.95083e-07, 0.20564, 0.20564, 0.97561, 0.913896, 0, 0, 0, 0, 0, 0, 0.00784314, - 0, 0.695525, 1, 0.07205, 0, 0, 0.176471, 0, 0, 0, 1, 1, 0.98, 0.01, 0.01, 0, 0.00690702, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29078, 0.29078, 1, 0, 0, 0, 0, 0.192157, 0.188235, - 0.0941176, 0, 0.0313726, 0, 0.141176, 0.207843, 0.0901961, 0.00784314, 0.0784314, - 0, 0, 0, 0, 0, 0.203922, 0.0196078, 0.34902, 0.0235294, 0.0980392, 0.164706, 0.133333, - 0.368627, 0, 0.0941176, 0, 1, 0.313726, 0, 0, 0.433582, 0.384508, 0.0532186, 0.0833333, - 0.01609, 0, 1, 0, 0, 0, 0.0666667, 0, 0, 0, 0, 1, 0, 0.564706, 0.501961, 0, 0, 0, - 0, 0, 0.0516447, 0.000173065, 0, 0, 0, 0, 0, 0, 0, 0.996309, 0, 0, 0.00392157, 1, - 0, 0.01, 0, 0, 0, 0, 0, 0.439505, 0.206882, 0.206882, 0.260891, 0, 0.875, 0, 0, 0, - 0, 0, 0.185657, 1, 1, 0, 0, 0, 0.0332647, 0.206106, 0.0688878, 0.239216, 0, 0, 0, - 0, 0.054902, 0, 0.101961, 0.160784, 0.180392, 0, 0.737828, 0, 0, 0.875, 0.0142566, - 0, 0.662745, 1, 0, 0, 0, 0.225806, 0.99992, 0.631373, 0.00392157, 1, 0, 0.143647, - 0.00270085, 1, 0.231482, 0.246735, 0.0428062, 0, 0, 1, 0, 0.186441, 0.0115358, 0, - 0.221762, 0, 0.2, 0, 0.0156863, 0, 0, 0, 0.976471, 0, 0.231373, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0.00392157, 0.00392157, 0.0666667, 0, 0, 0, 0, 0.0117647, 0.580392, 0.98737, - 1, 1, 1, 0, 0, 0, 0.153, 0.847, 0.931373, 0.94697, 0.94697, 0, 0.946294, 0.408118, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0.99992, 0.97561, 0, 0, 0, 0, 0, 0, - 0.274677, 0.153017, 0, 0.642356, 0, 0, 0.1, 0, 0, 0, 0, 0.327944, 0.327944, 0, 0, - 0.815686, 0, 0, 0, 0, 0.206106, 0.439126, 0, 0, 0, 0, 0, 1, 1, 1, 0.00392157, 0.232788, - 0.232465, 0.999899, 0.00309296, 0.0636097, 0.445954, 0.156863, 0, 0, 0, 0, 0, 0, - 0.3796, 0.0784, 0.0651664, 0, 0, 0.254902, 0.266667, 1, 0, 0, 0, 0, 0, 0.596073, - 0.517876, 0.145833, 0.372549, 0, 0.991667, 0.602125, 0.161979, 0, 0, 0, 0, 0.0255146, - 0.947855, 0, 0, 0, 0, 0, 0, 0, 0, 0.847059, 0.679841, 0, 0.156863, 0, 0, 1, 0, 0, - 0, 0, 0.969697, 0, 0, 0.564706, 0, 0, 0, 0, 0, 1, 0.0367282, 0.0395228, 0, 0, 0, + static const float Factors[] = { + 0.340582, 0.000974026, 0.487168, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0.411765, 0.921569, + 0.00390625, 0.109371, 0, 1, 0, 0, 0, 0, 0.523322, 0, 1, 0, 0, 0, 0, 0.285714, 1, + 0.008253, 1, 0, 0, 0.00993935, 0.450213, 0.000974026, 1, 1, 1, 1, 0, 0, 0.20564, + 0.97561, 0.913896, 1, 1, 0, 1, 0, 0, 0.5, 0, 0, 0, 0.1, 1, 0, 0, 0, 0, 0, 0.450923, + 0, 0.5, 0, 0, 0.20564, 0, 0.5, 0, 0, 0.20564, 0, 0, 0.0313726, 0, 1, 1, 1, 0.363636, + 0.5, 0.686073, 0.45121, 0.00574382, 0.366166, 0.413295, 1, 1, 1, 0, 0, 0, 0, 0.160784, + 0, 0.937255, 0.537255, 0.133333, 0, 0, 0, 0, 0.00392157, 0, 0.333333, 0.027451, 0.0156863, + 1, 0.105882, 1, 0.00220908, 0.000112501, 0.0111262, 0.102384, 0.00140808, 0.123581, + 0.29308, 6.57282e-06, 0.00489498, 2.10209e-05, 0.00140559, 5.907e-06, 0, 0.559322, + 0.559322, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.794765, 0, + 0.352648, 0.225904, 1, 0.047619, 0.0107276, 0.399461, 0.0304838, 0.292932, 0.00969929, + 0, 0, 0.886904, 0.714693, 0, 0.00223213, 0.000544069, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0.00507403, 0, 0, 0, 0, 0, 0.875, 0, 0, 1, 1, 1, 0, 0.20564, 0, 0.00176048, 0, + 0.000440121, 0, 0, 0, 0.000974026, 0.487168, 0, 0, 0.533333, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 0, 0.723187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0.206882, 0.00483367, 0.792983, 0.00126106, 1, 0.0313726, 0.470588, + 0.254902, 0.188235, 0.188235, 0.388235, 0.164706, 0, 0.870588, 0.843137, 0.635294, + 0.384314, 0.384314, 0.643137, 0, 0, 0, 0, 0, 0, 0, 0, 0.541176, 0, 0.541176, 0, 0, + 0.0532634, 1, 0, 0, 0, 0.015044, 1, 0, 1, 1, 1, 0.47451, 0.329412, 0.964706, 0, 0, + 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0941176, 0.970588, 0.970588, 0, 0.970588, 0.97561, + 0, 0.0431373, 0.47451, 0.329412, 0.964706, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0.231373, 0.00392157, 0, 0, 0, 0.054902, 0, 0, + 1, 0, 0, 0.0235294, 0, 1, 0, 0, 0, 0, 0.34902, 0.0352941, 0.925379, 0.623681, 0, + 0.954543, 0, 0, 0.00102756, 0.709804, 0.498039, 0.0901961, 0.631373, 0.847059, 0.270588, + 0.0156863, 0.133333, 0.980392, 1e-12, 1e-12, 1e-12, 1e-12, 0.497159, 0, 0.407487, + 0, 0, 0, 0.00392157, 0.00202156, 0.046875, 0.187159, 0.046875, 0.15625, 0.434232, + 0.15625, 0, 2.95083e-07, 0.20564, 0.20564, 0.97561, 0.913896, 0, 0, 0, 0, 0, 0, 0.00784314, + 0, 0.695525, 1, 0.07205, 0, 0, 0.176471, 0, 0, 0, 1, 1, 0.98, 0.01, 0.01, 0, 0.00690702, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29078, 0.29078, 1, 0, 0, 0, 0, 0.192157, 0.188235, + 0.0941176, 0, 0.0313726, 0, 0.141176, 0.207843, 0.0901961, 0.00784314, 0.0784314, + 0, 0, 0, 0, 0, 0.203922, 0.0196078, 0.34902, 0.0235294, 0.0980392, 0.164706, 0.133333, + 0.368627, 0, 0.0941176, 0, 1, 0.313726, 0, 0, 0.433582, 0.384508, 0.0532186, 0.0833333, + 0.01609, 0, 1, 0, 0, 0, 0.0666667, 0, 0, 0, 0, 1, 0, 0.564706, 0.501961, 0, 0, 0, + 0, 0, 0.0516447, 0.000173065, 0, 0, 0, 0, 0, 0, 0, 0.996309, 0, 0, 0.00392157, 1, + 0, 0.01, 0, 0, 0, 0, 0, 0.439505, 0.206882, 0.206882, 0.260891, 0, 0.875, 0, 0, 0, + 0, 0, 0.185657, 1, 1, 0, 0, 0, 0.0332647, 0.206106, 0.0688878, 0.239216, 0, 0, 0, + 0, 0.054902, 0, 0.101961, 0.160784, 0.180392, 0, 0.737828, 0, 0, 0.875, 0.0142566, + 0, 0.662745, 1, 0, 0, 0, 0.225806, 0.99992, 0.631373, 0.00392157, 1, 0, 0.143647, + 0.00270085, 1, 0.231482, 0.246735, 0.0428062, 0, 0, 1, 0, 0.186441, 0.0115358, 0, + 0.221762, 0, 0.2, 0, 0.0156863, 0, 0, 0, 0.976471, 0, 0.231373, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0.00392157, 0.00392157, 0.0666667, 0, 0, 0, 0, 0.0117647, 0.580392, 0.98737, + 1, 1, 1, 0, 0, 0, 0.153, 0.847, 0.931373, 0.94697, 0.94697, 0, 0.946294, 0.408118, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0.99992, 0.97561, 0, 0, 0, 0, 0, 0, + 0.274677, 0.153017, 0, 0.642356, 0, 0, 0.1, 0, 0, 0, 0, 0.327944, 0.327944, 0, 0, + 0.815686, 0, 0, 0, 0, 0.206106, 0.439126, 0, 0, 0, 0, 0, 1, 1, 1, 0.00392157, 0.232788, + 0.232465, 0.999899, 0.00309296, 0.0636097, 0.445954, 0.156863, 0, 0, 0, 0, 0, 0, + 0.3796, 0.0784, 0.0651664, 0, 0, 0.254902, 0.266667, 1, 0, 0, 0, 0, 0, 0.596073, + 0.517876, 0.145833, 0.372549, 0, 0.991667, 0.602125, 0.161979, 0, 0, 0, 0, 0.0255146, + 0.947855, 0, 0, 0, 0, 0, 0, 0, 0, 0.847059, 0.679841, 0, 0.156863, 0, 0, 1, 0, 0, + 0, 0, 0.969697, 0, 0, 0.564706, 0, 0, 0, 0, 0, 1, 0.0367282, 0.0395228, 0, 0, 0, 0, 0, 0.0470588, 0.141176, 0.054902, 0, 0, 0, 0}; static const size_t FactorCount = Y_ARRAY_SIZE(Factors); - - static const ui8 CodedFactors[] = { - 0x24, 0x06, 0x73, 0xB5, 0xC7, 0x55, 0x7F, 0x3A, 0xB4, 0x70, 0xCB, 0xEF, 0xEE, 0xFE, 0xB3, 0x5B, - 0x5A, 0x1A, 0x93, 0x5F, 0x5F, 0x13, 0x00, 0x00, 0x10, 0x00, 0x3D, 0xEF, 0xFF, 0xEE, 0x0F, 0xDC, - 0xF0, 0xAB, 0x3F, 0x37, 0x92, 0x24, 0x5D, 0x5E, 0xDE, 0x1C, 0xF8, 0x12, 0x15, 0x5B, 0x84, 0x51, - 0x82, 0xE6, 0xF6, 0xB8, 0xEA, 0x4F, 0xC7, 0xDD, 0x7D, 0x2E, 0x4D, 0x4A, 0x21, 0xCA, 0xE0, 0xC4, - 0x2E, 0xEA, 0xD3, 0xBD, 0x0F, 0x00, 0x00, 0xE0, 0xDA, 0xCC, 0xCC, 0xEC, 0x9F, 0x61, 0xDF, 0xE6, - 0x01, 0x00, 0x00, 0xCC, 0xA5, 0x49, 0xA9, 0x00, 0x00, 0x00, 0xE6, 0xD2, 0xA4, 0xD4, 0xEA, 0x08, - 0x08, 0xD0, 0xDD, 0xF9, 0xE7, 0xA2, 0x0B, 0x00, 0x00, 0x40, 0xD8, 0x13, 0x7D, 0xFE, 0x13, 0x9C, - 0x9B, 0xA8, 0x36, 0xBC, 0x00, 0x90, 0x43, 0x6F, 0x97, 0x67, 0x9B, 0xD3, 0xEE, 0xFE, 0x84, 0x24, - 0x25, 0x89, 0xC9, 0xBF, 0x3F, 0x58, 0x4C, 0x4C, 0xCA, 0x21, 0x22, 0xBC, 0x39, 0x08, 0x08, 0x08, - 0x40, 0x7E, 0xAA, 0xAA, 0xCA, 0x75, 0x70, 0x70, 0xE9, 0x08, 0x08, 0xE8, 0x9A, 0x8A, 0x8D, 0xED, - 0xA6, 0x8D, 0x31, 0x04, 0x00, 0x96, 0xD0, 0x7D, 0x1D, 0x47, 0xAA, 0x2A, 0xD9, 0x28, 0xAD, 0x6B, - 0xB4, 0x9D, 0x7A, 0xC4, 0xD5, 0xD1, 0x04, 0x8C, 0x7E, 0x56, 0x3A, 0x58, 0x5A, 0x0C, 0x46, 0x6E, - 0x1B, 0x53, 0xC2, 0x0C, 0x14, 0x00, 0xAB, 0x60, 0x05, 0x7B, 0x63, 0x8D, 0x77, 0x70, 0x75, 0xAC, - 0x2F, 0x8D, 0xB1, 0x4D, 0xA0, 0xFB, 0xF2, 0x40, 0xF7, 0xE5, 0x7F, 0xDF, 0xDD, 0xFD, 0xBB, 0x1B, - 0xB8, 0x75, 0x9B, 0x47, 0x8E, 0xB4, 0x0C, 0x9B, 0x3A, 0x73, 0x25, 0x61, 0x18, 0x92, 0xD1, 0xC2, - 0x2F, 0x3C, 0x31, 0x64, 0x96, 0x2A, 0xB9, 0xF9, 0x7C, 0xD9, 0xAF, 0x94, 0xC5, 0xE9, 0x1E, 0x63, - 0x24, 0x0C, 0x03, 0x7F, 0xD8, 0x5B, 0xB3, 0x1D, 0x49, 0x02, 0x00, 0xAB, 0xFD, 0xE9, 0xA0, 0xF3, - 0xBF, 0xC9, 0x40, 0x64, 0x0A, 0xC0, 0xC7, 0x00, 0x00, 0x60, 0x77, 0xCF, 0xA5, 0x49, 0xA9, 0x16, - 0xFD, 0xD7, 0x5C, 0xA7, 0x55, 0x00, 0x36, 0xCF, 0xB9, 0x3D, 0xAE, 0xFA, 0xD3, 0xA1, 0x85, 0x5B, - 0xFE, 0x60, 0x10, 0x11, 0xFF, 0xF7, 0x7D, 0x38, 0x59, 0x24, 0xFF, 0xFF, 0xDF, 0x13, 0x1C, 0x7B, - 0xCA, 0x1C, 0x1E, 0xF3, 0x04, 0xC0, 0x78, 0x07, 0x58, 0x7B, 0xA2, 0x54, 0xAA, 0xE3, 0xEA, 0x08, - 0x08, 0xC0, 0x74, 0x78, 0x78, 0x88, 0x50, 0x50, 0xD8, 0x0A, 0x0C, 0xC4, 0x56, 0x60, 0x20, 0xF6, - 0x1A, 0x1B, 0x33, 0x16, 0x15, 0xA5, 0xB8, 0xED, 0xED, 0x22, 0xF5, 0xF5, 0x09, 0xA1, 0xA2, 0x42, - 0x67, 0x62, 0x62, 0x3A, 0x13, 0x13, 0x0B, 0xA0, 0xA4, 0xF4, 0x0F, 0x06, 0x15, 0x35, 0x18, 0x54, - 0xD4, 0x35, 0x57, 0x45, 0xCB, 0x2F, 0x39, 0xF6, 0xEC, 0xBC, 0xBB, 0x53, 0x5F, 0x5E, 0x9E, 0xB1, - 0xA8, 0xA8, 0x28, 0xDF, 0xDE, 0x3E, 0x00, 0x00, 0x80, 0x5F, 0x75, 0x81, 0x81, 0x51, 0x1D, 0x1E, - 0xA2, 0x3A, 0x3C, 0x8C, 0xEA, 0xF0, 0x10, 0x51, 0x06, 0x67, 0xED, 0x85, 0x85, 0xA1, 0xBE, 0xBC, - 0x3C, 0x63, 0x51, 0x51, 0x51, 0xBE, 0xBD, 0xFD, 0xFF, 0xFD, 0xFE, 0xCE, 0x85, 0x76, 0x36, 0x73, - 0x10, 0x10, 0x10, 0x80, 0xEB, 0x3A, 0x38, 0xD8, 0xBE, 0xD4, 0x05, 0x06, 0xEE, 0x4F, 0x60, 0x59, - 0x59, 0x65, 0x84, 0x84, 0xC0, 0x46, 0xCB, 0x19, 0x7F, 0x4C, 0xFD, 0xC8, 0x9D, 0x8B, 0xB6, 0x31, - 0xAF, 0x86, 0x3A, 0xF0, 0x6D, 0x6D, 0x11, 0xDF, 0xDF, 0x5F, 0x79, 0x71, 0x71, 0x85, 0xD4, 0xD0, - 0x10, 0xB9, 0xB1, 0x11, 0x1A, 0x54, 0x54, 0xE9, 0x08, 0x08, 0x48, 0x39, 0x44, 0x04, 0x84, 0xAF, - 0xAF, 0x96, 0x99, 0x97, 0x71, 0xC5, 0x32, 0xF3, 0x32, 0xAE, 0x58, 0x66, 0x5E, 0xC6, 0x15, 0xCB, - 0xCC, 0xCB, 0xB8, 0x42, 0xD0, 0x45, 0xFF, 0x1C, 0x11, 0x85, 0xBE, 0x39, 0x08, 0x08, 0x08, 0x80, - 0x69, 0xC2, 0x47, 0x00, 0x80, 0x02, 0x00, 0x00, 0x91, 0xD3, 0xF4, 0x47, 0x01, 0x00, 0x80, 0x08, - 0x00, 0x00, 0x42, 0xD4, 0x29, 0x6F, 0x02, 0x00, 0x80, 0xB4, 0xE6, 0x6B, 0x9E, 0x34, 0x5C, 0x9A, - 0x94, 0xE2, 0xD2, 0xA4, 0x14, 0xA2, 0x0C, 0x4E, 0xEC, 0xA2, 0x3E, 0x7F, 0x39, 0x08, 0x08, 0x10, - 0x6E, 0x6F, 0x10, 0xD7, 0x79, 0xC7, 0xC9, 0x09, 0x4D, 0x4B, 0x73, 0x77, 0x84, 0x14, 0xAE, 0x52, - 0xE1, 0x7A, 0x44, 0x2A, 0x5C, 0x8F, 0x34, 0x93, 0xA8, 0xC4, 0x01, 0xF8, 0x3F, 0x3D, 0xC2, 0x29, - 0xE9, 0x11, 0x4E, 0xE9, 0x4F, 0x67, 0x62, 0x22, 0xB6, 0x02, 0x03, 0xA9, 0x2E, 0x30, 0x70, 0x75, - 0x04, 0x04, 0xC8, 0x38, 0x48, 0x08, 0x32, 0x53, 0x53, 0x29, 0x2F, 0x2E, 0xAE, 0x1C, 0x04, 0x04, - 0x50, 0x52, 0x50, 0xD0, 0x4F, 0x77, 0x68, 0x28, 0x99, 0x08, 0x0A, 0x4A, 0x60, 0x59, 0x59, 0xA9, - 0x0B, 0x0C, 0xAC, 0xC7, 0xC8, 0xC8, 0x8C, 0x45, 0x45, 0xA1, 0x1C, 0x22, 0x02, 0x5D, 0x79, 0x79, - 0xAB, 0x2E, 0x30, 0x70, 0xA7, 0x2C, 0x28, 0xE8, 0xB4, 0xF3, 0xEF, 0x26, 0x8F, 0x37, 0xB1, 0xFE, - 0xEE, 0x67, 0xA9, 0xA9, 0xAA, 0xAA, 0x6C, 0x79, 0x1E, 0xEC, 0xD7, 0x46, 0x44, 0xC4, 0xF7, 0xF8, - 0x24, 0x24, 0x00, 0x42, 0x40, 0xF8, 0x5A, 0x96, 0x38, 0x65, 0x91, 0xF1, 0x6A, 0x72, 0xFE, 0x68, - 0xC3, 0xE1, 0x37, 0x07, 0x01, 0x01, 0x01, 0xF0, 0x52, 0xE1, 0x7A, 0xE4, 0xB3, 0xD9, 0x20, 0x9C, - 0xE0, 0xD8, 0x53, 0x04, 0xC7, 0x9E, 0x82, 0x02, 0x27, 0x2B, 0x06, 0x00, 0x00, 0x9F, 0xDE, 0x1C, - 0x3E, 0xEE, 0xD7, 0x48, 0x20, 0x04, 0xD2, 0x35, 0x4C, 0x29, 0x43, 0x45, 0x23, 0x15, 0xEA, 0xE9, - 0x5E, 0xD7, 0xC1, 0xC1, 0xAA, 0x3B, 0x34, 0x34, 0x21, 0x49, 0x49, 0xE8, 0x8A, 0x8B, 0x13, 0x66, - 0x12, 0xE7, 0x31, 0x00, 0x00, 0x90, 0x84, 0x94, 0x69, 0x05, 0xD4, 0xD4, 0xF4, 0x13, 0x36, 0xE7, - 0x0C, 0x09, 0xEB, 0xBF, 0x90, 0x1A, 0x1A, 0xE6, 0x20, 0x20, 0x20, 0x00, 0x9E, 0x33, 0x18, 0x13, - 0xA6, 0x2F, 0x40, 0x0C, 0x00, 0x4E, 0xCF, 0x84, 0x36, 0x6A, 0xA0, 0xF2, 0xA9, 0x63, 0xD5, 0xCB, - 0x9E, 0x64, 0xEA, 0x3E, 0xF2, 0x14, 0xA0, 0x27, 0x29, 0x2B, 0xC6, 0xB2, 0x99, 0x99, 0xA9, 0x74, - 0x04, 0x04, 0x3C, 0x0A, 0xD0, 0xCF, 0x5C, 0x68, 0x67, 0xFB, 0xDF, 0x1C, 0x04, 0x04, 0x04, 0xC0, - 0x1C, 0x04, 0x04, 0x04, 0x40, 0x1B, 0x11, 0x11, 0x5F, 0xEA, 0x02, 0x03, 0xE1, 0x92, 0x94, 0x84, - 0x90, 0x88, 0xD9, 0xDD, 0x4F, 0x04, 0x56, 0x0E, 0xD1, 0x9F, 0x1A, 0x31, 0x3B, 0x37, 0x47, 0xA0, - 0x6C, 0x82, 0x40, 0xD9, 0x24, 0x9A, 0x02, 0x12, 0x62, 0xD3, 0x43, 0xFF, 0xBF, 0x8F, 0x84, 0xF5, - 0x1F, 0x51, 0x06, 0xE7, 0x0F, 0xDD, 0x89, 0x32, 0xFB, 0x60, 0x39, 0x0A, 0x71, 0x71, 0xB4, 0x36, - 0x33, 0x33, 0x3F, 0x8F, 0xD0, 0x4F, 0x79, 0x84, 0x7E, 0xBA, 0xC8, 0x0C, 0x0D, 0x4F, 0xBA, 0x86, - 0x29, 0x82, 0x54, 0x83, 0x7F, 0x77, 0x37, 0x07, 0x01, 0x01, 0x01, 0xA0, 0xFE, 0x97, 0x1B, 0x9D, - 0x16, 0xDC, 0x90, 0x58, 0xFE, 0x9B, 0x42, 0xB3, 0x4A, 0x00, 0x68, 0x73, 0x91, 0x20, 0x2B, 0xA8, - 0xC8, 0x29, 0x0B, 0x0A, 0xF2, 0xD3, 0x5D, 0x4B, 0x58, 0x5D, 0x20, 0x41, 0xD5, 0xBE, 0xAE, 0x70, - 0x88, 0x50, 0x50, 0x20, 0x4A, 0x44, 0xF4, 0x8F, 0xF7, 0x60, 0x22, 0x30, 0x9C, 0x24, 0xFE, 0x54, - 0x55, 0xD0, 0xD7, 0xD7, 0x37, 0x1A, 0xEF, 0x6E, 0xBC, 0x9B, 0x44, 0x39, 0xDD, 0x5D, 0xF2, 0xF2, - 0x7F, 0x20, 0x1A, 0x81, 0x9A, 0xCA, 0xBF, 0xC8, 0x8D, 0x8D, 0xC2, 0x83, 0x82, 0xA7, 0x2C, 0x28, - 0xC8, 0xFE, 0x08, 0xC2, 0x07, 0xC7, 0x27, 0x21, 0xE1, 0xBB, 0x3E, 0xC1, 0x59, 0x68, 0xAA, 0x78, - 0xC8, 0x57, 0x5D, 0x60, 0x20, 0xC6, 0x41, 0x42, 0xE8, 0x3A, 0x38, 0xD8, 0x9B, 0xFF, 0xFF, 0xFF, + + static const ui8 CodedFactors[] = { + 0x24, 0x06, 0x73, 0xB5, 0xC7, 0x55, 0x7F, 0x3A, 0xB4, 0x70, 0xCB, 0xEF, 0xEE, 0xFE, 0xB3, 0x5B, + 0x5A, 0x1A, 0x93, 0x5F, 0x5F, 0x13, 0x00, 0x00, 0x10, 0x00, 0x3D, 0xEF, 0xFF, 0xEE, 0x0F, 0xDC, + 0xF0, 0xAB, 0x3F, 0x37, 0x92, 0x24, 0x5D, 0x5E, 0xDE, 0x1C, 0xF8, 0x12, 0x15, 0x5B, 0x84, 0x51, + 0x82, 0xE6, 0xF6, 0xB8, 0xEA, 0x4F, 0xC7, 0xDD, 0x7D, 0x2E, 0x4D, 0x4A, 0x21, 0xCA, 0xE0, 0xC4, + 0x2E, 0xEA, 0xD3, 0xBD, 0x0F, 0x00, 0x00, 0xE0, 0xDA, 0xCC, 0xCC, 0xEC, 0x9F, 0x61, 0xDF, 0xE6, + 0x01, 0x00, 0x00, 0xCC, 0xA5, 0x49, 0xA9, 0x00, 0x00, 0x00, 0xE6, 0xD2, 0xA4, 0xD4, 0xEA, 0x08, + 0x08, 0xD0, 0xDD, 0xF9, 0xE7, 0xA2, 0x0B, 0x00, 0x00, 0x40, 0xD8, 0x13, 0x7D, 0xFE, 0x13, 0x9C, + 0x9B, 0xA8, 0x36, 0xBC, 0x00, 0x90, 0x43, 0x6F, 0x97, 0x67, 0x9B, 0xD3, 0xEE, 0xFE, 0x84, 0x24, + 0x25, 0x89, 0xC9, 0xBF, 0x3F, 0x58, 0x4C, 0x4C, 0xCA, 0x21, 0x22, 0xBC, 0x39, 0x08, 0x08, 0x08, + 0x40, 0x7E, 0xAA, 0xAA, 0xCA, 0x75, 0x70, 0x70, 0xE9, 0x08, 0x08, 0xE8, 0x9A, 0x8A, 0x8D, 0xED, + 0xA6, 0x8D, 0x31, 0x04, 0x00, 0x96, 0xD0, 0x7D, 0x1D, 0x47, 0xAA, 0x2A, 0xD9, 0x28, 0xAD, 0x6B, + 0xB4, 0x9D, 0x7A, 0xC4, 0xD5, 0xD1, 0x04, 0x8C, 0x7E, 0x56, 0x3A, 0x58, 0x5A, 0x0C, 0x46, 0x6E, + 0x1B, 0x53, 0xC2, 0x0C, 0x14, 0x00, 0xAB, 0x60, 0x05, 0x7B, 0x63, 0x8D, 0x77, 0x70, 0x75, 0xAC, + 0x2F, 0x8D, 0xB1, 0x4D, 0xA0, 0xFB, 0xF2, 0x40, 0xF7, 0xE5, 0x7F, 0xDF, 0xDD, 0xFD, 0xBB, 0x1B, + 0xB8, 0x75, 0x9B, 0x47, 0x8E, 0xB4, 0x0C, 0x9B, 0x3A, 0x73, 0x25, 0x61, 0x18, 0x92, 0xD1, 0xC2, + 0x2F, 0x3C, 0x31, 0x64, 0x96, 0x2A, 0xB9, 0xF9, 0x7C, 0xD9, 0xAF, 0x94, 0xC5, 0xE9, 0x1E, 0x63, + 0x24, 0x0C, 0x03, 0x7F, 0xD8, 0x5B, 0xB3, 0x1D, 0x49, 0x02, 0x00, 0xAB, 0xFD, 0xE9, 0xA0, 0xF3, + 0xBF, 0xC9, 0x40, 0x64, 0x0A, 0xC0, 0xC7, 0x00, 0x00, 0x60, 0x77, 0xCF, 0xA5, 0x49, 0xA9, 0x16, + 0xFD, 0xD7, 0x5C, 0xA7, 0x55, 0x00, 0x36, 0xCF, 0xB9, 0x3D, 0xAE, 0xFA, 0xD3, 0xA1, 0x85, 0x5B, + 0xFE, 0x60, 0x10, 0x11, 0xFF, 0xF7, 0x7D, 0x38, 0x59, 0x24, 0xFF, 0xFF, 0xDF, 0x13, 0x1C, 0x7B, + 0xCA, 0x1C, 0x1E, 0xF3, 0x04, 0xC0, 0x78, 0x07, 0x58, 0x7B, 0xA2, 0x54, 0xAA, 0xE3, 0xEA, 0x08, + 0x08, 0xC0, 0x74, 0x78, 0x78, 0x88, 0x50, 0x50, 0xD8, 0x0A, 0x0C, 0xC4, 0x56, 0x60, 0x20, 0xF6, + 0x1A, 0x1B, 0x33, 0x16, 0x15, 0xA5, 0xB8, 0xED, 0xED, 0x22, 0xF5, 0xF5, 0x09, 0xA1, 0xA2, 0x42, + 0x67, 0x62, 0x62, 0x3A, 0x13, 0x13, 0x0B, 0xA0, 0xA4, 0xF4, 0x0F, 0x06, 0x15, 0x35, 0x18, 0x54, + 0xD4, 0x35, 0x57, 0x45, 0xCB, 0x2F, 0x39, 0xF6, 0xEC, 0xBC, 0xBB, 0x53, 0x5F, 0x5E, 0x9E, 0xB1, + 0xA8, 0xA8, 0x28, 0xDF, 0xDE, 0x3E, 0x00, 0x00, 0x80, 0x5F, 0x75, 0x81, 0x81, 0x51, 0x1D, 0x1E, + 0xA2, 0x3A, 0x3C, 0x8C, 0xEA, 0xF0, 0x10, 0x51, 0x06, 0x67, 0xED, 0x85, 0x85, 0xA1, 0xBE, 0xBC, + 0x3C, 0x63, 0x51, 0x51, 0x51, 0xBE, 0xBD, 0xFD, 0xFF, 0xFD, 0xFE, 0xCE, 0x85, 0x76, 0x36, 0x73, + 0x10, 0x10, 0x10, 0x80, 0xEB, 0x3A, 0x38, 0xD8, 0xBE, 0xD4, 0x05, 0x06, 0xEE, 0x4F, 0x60, 0x59, + 0x59, 0x65, 0x84, 0x84, 0xC0, 0x46, 0xCB, 0x19, 0x7F, 0x4C, 0xFD, 0xC8, 0x9D, 0x8B, 0xB6, 0x31, + 0xAF, 0x86, 0x3A, 0xF0, 0x6D, 0x6D, 0x11, 0xDF, 0xDF, 0x5F, 0x79, 0x71, 0x71, 0x85, 0xD4, 0xD0, + 0x10, 0xB9, 0xB1, 0x11, 0x1A, 0x54, 0x54, 0xE9, 0x08, 0x08, 0x48, 0x39, 0x44, 0x04, 0x84, 0xAF, + 0xAF, 0x96, 0x99, 0x97, 0x71, 0xC5, 0x32, 0xF3, 0x32, 0xAE, 0x58, 0x66, 0x5E, 0xC6, 0x15, 0xCB, + 0xCC, 0xCB, 0xB8, 0x42, 0xD0, 0x45, 0xFF, 0x1C, 0x11, 0x85, 0xBE, 0x39, 0x08, 0x08, 0x08, 0x80, + 0x69, 0xC2, 0x47, 0x00, 0x80, 0x02, 0x00, 0x00, 0x91, 0xD3, 0xF4, 0x47, 0x01, 0x00, 0x80, 0x08, + 0x00, 0x00, 0x42, 0xD4, 0x29, 0x6F, 0x02, 0x00, 0x80, 0xB4, 0xE6, 0x6B, 0x9E, 0x34, 0x5C, 0x9A, + 0x94, 0xE2, 0xD2, 0xA4, 0x14, 0xA2, 0x0C, 0x4E, 0xEC, 0xA2, 0x3E, 0x7F, 0x39, 0x08, 0x08, 0x10, + 0x6E, 0x6F, 0x10, 0xD7, 0x79, 0xC7, 0xC9, 0x09, 0x4D, 0x4B, 0x73, 0x77, 0x84, 0x14, 0xAE, 0x52, + 0xE1, 0x7A, 0x44, 0x2A, 0x5C, 0x8F, 0x34, 0x93, 0xA8, 0xC4, 0x01, 0xF8, 0x3F, 0x3D, 0xC2, 0x29, + 0xE9, 0x11, 0x4E, 0xE9, 0x4F, 0x67, 0x62, 0x22, 0xB6, 0x02, 0x03, 0xA9, 0x2E, 0x30, 0x70, 0x75, + 0x04, 0x04, 0xC8, 0x38, 0x48, 0x08, 0x32, 0x53, 0x53, 0x29, 0x2F, 0x2E, 0xAE, 0x1C, 0x04, 0x04, + 0x50, 0x52, 0x50, 0xD0, 0x4F, 0x77, 0x68, 0x28, 0x99, 0x08, 0x0A, 0x4A, 0x60, 0x59, 0x59, 0xA9, + 0x0B, 0x0C, 0xAC, 0xC7, 0xC8, 0xC8, 0x8C, 0x45, 0x45, 0xA1, 0x1C, 0x22, 0x02, 0x5D, 0x79, 0x79, + 0xAB, 0x2E, 0x30, 0x70, 0xA7, 0x2C, 0x28, 0xE8, 0xB4, 0xF3, 0xEF, 0x26, 0x8F, 0x37, 0xB1, 0xFE, + 0xEE, 0x67, 0xA9, 0xA9, 0xAA, 0xAA, 0x6C, 0x79, 0x1E, 0xEC, 0xD7, 0x46, 0x44, 0xC4, 0xF7, 0xF8, + 0x24, 0x24, 0x00, 0x42, 0x40, 0xF8, 0x5A, 0x96, 0x38, 0x65, 0x91, 0xF1, 0x6A, 0x72, 0xFE, 0x68, + 0xC3, 0xE1, 0x37, 0x07, 0x01, 0x01, 0x01, 0xF0, 0x52, 0xE1, 0x7A, 0xE4, 0xB3, 0xD9, 0x20, 0x9C, + 0xE0, 0xD8, 0x53, 0x04, 0xC7, 0x9E, 0x82, 0x02, 0x27, 0x2B, 0x06, 0x00, 0x00, 0x9F, 0xDE, 0x1C, + 0x3E, 0xEE, 0xD7, 0x48, 0x20, 0x04, 0xD2, 0x35, 0x4C, 0x29, 0x43, 0x45, 0x23, 0x15, 0xEA, 0xE9, + 0x5E, 0xD7, 0xC1, 0xC1, 0xAA, 0x3B, 0x34, 0x34, 0x21, 0x49, 0x49, 0xE8, 0x8A, 0x8B, 0x13, 0x66, + 0x12, 0xE7, 0x31, 0x00, 0x00, 0x90, 0x84, 0x94, 0x69, 0x05, 0xD4, 0xD4, 0xF4, 0x13, 0x36, 0xE7, + 0x0C, 0x09, 0xEB, 0xBF, 0x90, 0x1A, 0x1A, 0xE6, 0x20, 0x20, 0x20, 0x00, 0x9E, 0x33, 0x18, 0x13, + 0xA6, 0x2F, 0x40, 0x0C, 0x00, 0x4E, 0xCF, 0x84, 0x36, 0x6A, 0xA0, 0xF2, 0xA9, 0x63, 0xD5, 0xCB, + 0x9E, 0x64, 0xEA, 0x3E, 0xF2, 0x14, 0xA0, 0x27, 0x29, 0x2B, 0xC6, 0xB2, 0x99, 0x99, 0xA9, 0x74, + 0x04, 0x04, 0x3C, 0x0A, 0xD0, 0xCF, 0x5C, 0x68, 0x67, 0xFB, 0xDF, 0x1C, 0x04, 0x04, 0x04, 0xC0, + 0x1C, 0x04, 0x04, 0x04, 0x40, 0x1B, 0x11, 0x11, 0x5F, 0xEA, 0x02, 0x03, 0xE1, 0x92, 0x94, 0x84, + 0x90, 0x88, 0xD9, 0xDD, 0x4F, 0x04, 0x56, 0x0E, 0xD1, 0x9F, 0x1A, 0x31, 0x3B, 0x37, 0x47, 0xA0, + 0x6C, 0x82, 0x40, 0xD9, 0x24, 0x9A, 0x02, 0x12, 0x62, 0xD3, 0x43, 0xFF, 0xBF, 0x8F, 0x84, 0xF5, + 0x1F, 0x51, 0x06, 0xE7, 0x0F, 0xDD, 0x89, 0x32, 0xFB, 0x60, 0x39, 0x0A, 0x71, 0x71, 0xB4, 0x36, + 0x33, 0x33, 0x3F, 0x8F, 0xD0, 0x4F, 0x79, 0x84, 0x7E, 0xBA, 0xC8, 0x0C, 0x0D, 0x4F, 0xBA, 0x86, + 0x29, 0x82, 0x54, 0x83, 0x7F, 0x77, 0x37, 0x07, 0x01, 0x01, 0x01, 0xA0, 0xFE, 0x97, 0x1B, 0x9D, + 0x16, 0xDC, 0x90, 0x58, 0xFE, 0x9B, 0x42, 0xB3, 0x4A, 0x00, 0x68, 0x73, 0x91, 0x20, 0x2B, 0xA8, + 0xC8, 0x29, 0x0B, 0x0A, 0xF2, 0xD3, 0x5D, 0x4B, 0x58, 0x5D, 0x20, 0x41, 0xD5, 0xBE, 0xAE, 0x70, + 0x88, 0x50, 0x50, 0x20, 0x4A, 0x44, 0xF4, 0x8F, 0xF7, 0x60, 0x22, 0x30, 0x9C, 0x24, 0xFE, 0x54, + 0x55, 0xD0, 0xD7, 0xD7, 0x37, 0x1A, 0xEF, 0x6E, 0xBC, 0x9B, 0x44, 0x39, 0xDD, 0x5D, 0xF2, 0xF2, + 0x7F, 0x20, 0x1A, 0x81, 0x9A, 0xCA, 0xBF, 0xC8, 0x8D, 0x8D, 0xC2, 0x83, 0x82, 0xA7, 0x2C, 0x28, + 0xC8, 0xFE, 0x08, 0xC2, 0x07, 0xC7, 0x27, 0x21, 0xE1, 0xBB, 0x3E, 0xC1, 0x59, 0x68, 0xAA, 0x78, + 0xC8, 0x57, 0x5D, 0x60, 0x20, 0xC6, 0x41, 0x42, 0xE8, 0x3A, 0x38, 0xD8, 0x9B, 0xFF, 0xFF, 0xFF, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static const size_t CodedSize = Y_ARRAY_SIZE(CodedFactors); - static const TStringBuf CodedFactorsBuf(reinterpret_cast<const char*>(CodedFactors), CodedSize); - + static const TStringBuf CodedFactorsBuf(reinterpret_cast<const char*>(CodedFactors), CodedSize); + void FillWithGarbage(float* factors, size_t count) { void* data = static_cast<void*>(factors); memset(data, 0xAA, sizeof(float) * count); } - // Helper for dumping compressed values + // Helper for dumping compressed values void PrintCompressed(const TVector<ui8>& codedFactors) { - for (size_t i = 0; i < codedFactors.size(); ++i) { - if (i % 0x10 == 0) - Cerr << Endl; - Cerr << Hex(codedFactors[i]) << ", "; - } - Cerr << Endl; - } - - // Helper for dumping decompressed values + for (size_t i = 0; i < codedFactors.size(); ++i) { + if (i % 0x10 == 0) + Cerr << Endl; + Cerr << Hex(codedFactors[i]) << ", "; + } + Cerr << Endl; + } + + // Helper for dumping decompressed values void PrintDecompressed(const TVector<float>& factors) { - TStringStream result; - TStringStream line; - - for (size_t i = 0; i < factors.size(); ++i) { - line << factors[i] << ", "; - if (line.Str().size() > 80) { - result << line.Str() << Endl; + TStringStream result; + TStringStream line; + + for (size_t i = 0; i < factors.size(); ++i) { + line << factors[i] << ", "; + if (line.Str().size() > 80) { + result << line.Str() << Endl; line.Clear(); - } - } - Cerr << result.Str() << Endl; - } - + } + } + Cerr << result.Str() << Endl; + } + Y_UNIT_TEST(TestCompress) { const auto codedFactors = fh::Encode(Factors); - UNIT_ASSERT_VALUES_EQUAL(codedFactors.size(), CodedSize); - for (size_t i = 0; i < Min(codedFactors.size(), CodedSize); ++i) + UNIT_ASSERT_VALUES_EQUAL(codedFactors.size(), CodedSize); + for (size_t i = 0; i < Min(codedFactors.size(), CodedSize); ++i) UNIT_ASSERT_VALUES_EQUAL((ui8)codedFactors[i], CodedFactors[i]); - //PrintCompressed(codedFactors); - } - + //PrintCompressed(codedFactors); + } + Y_UNIT_TEST(TestSimpleDecompress) { TVector<float> factors = fh::Decode(CodedFactorsBuf); - UNIT_ASSERT_VALUES_EQUAL(factors.size(), FactorCount); - for (size_t i = 0; i < Min(factors.size(), FactorCount); ++i) - UNIT_ASSERT_VALUES_EQUAL(factors[i], Factors[i]); - //PrintDecompressed(factors); - } - + UNIT_ASSERT_VALUES_EQUAL(factors.size(), FactorCount); + for (size_t i = 0; i < Min(factors.size(), FactorCount); ++i) + UNIT_ASSERT_VALUES_EQUAL(factors[i], Factors[i]); + //PrintDecompressed(factors); + } + Y_UNIT_TEST(TestDecompressInParts) { - float factors[FactorCount]; + float factors[FactorCount]; FillWithGarbage(factors, FactorCount); fh::TDecoder decoder(CodedFactorsBuf); - const size_t firstPack = 100; - // unpack first pack + const size_t firstPack = 100; + // unpack first pack UNIT_ASSERT_VALUES_EQUAL(decoder.Decode({factors, firstPack}), firstPack); - // unpack all the rest + // unpack all the rest UNIT_ASSERT_VALUES_EQUAL(decoder.Decode({factors + firstPack, FactorCount - firstPack}), FactorCount - firstPack); - + for (size_t i = 0; i < FactorCount; ++i) - UNIT_ASSERT_VALUES_EQUAL(factors[i], Factors[i]); - //PrintDecompressed(factors); - } - + UNIT_ASSERT_VALUES_EQUAL(factors[i], Factors[i]); + //PrintDecompressed(factors); + } + Y_UNIT_TEST(TestSkip) { float factors[FactorCount]; FillWithGarbage(factors, FactorCount); @@ -219,19 +219,19 @@ Y_UNIT_TEST_SUITE(FloatHuffmanTest) { } Y_UNIT_TEST(TestDecompressForgedData) { - // this coredumps without end-of-coded-stream check, see SEARCH-1156 for details + // this coredumps without end-of-coded-stream check, see SEARCH-1156 for details TString brokenBase64Encoded = - "NLjYltUWs5pqnd3d3f05Li4OAwCAEqrP6mv06jDt7PiAUVu7Y+PiMpuZmdzeM" - "ArqOLxS2q4FKCII52dktcVs7y0zL+OKgeO9SOzEkFj7uPfFqqoCAAAAAADAtZ" - "mZ2fdmICAgANQXhi1WVRUAAAAAAAAGjvcWq6oKAAAAAAAAA8d7qe4rV3Nxcd3" - "d4ZfQZrETm3B+OxxB8bbnTPM5+qtbQ92mJ3fHPGj+iH5+8tzcnJuamry1tWUw" - "MBD693f07+9+DQQEkIGAgIgPetzN5yEbAGxWpbCNxXK/0JGTKRz2KkIoR7aM"; - UNIT_ASSERT_EXCEPTION( + "NLjYltUWs5pqnd3d3f05Li4OAwCAEqrP6mv06jDt7PiAUVu7Y+PiMpuZmdzeM" + "ArqOLxS2q4FKCII52dktcVs7y0zL+OKgeO9SOzEkFj7uPfFqqoCAAAAAADAtZ" + "mZ2fdmICAgANQXhi1WVRUAAAAAAAAGjvcWq6oKAAAAAAAAA8d7qe4rV3Nxcd3" + "d4ZfQZrETm3B+OxxB8bbnTPM5+qtbQ92mJ3fHPGj+iH5+8tzcnJuamry1tWUw" + "MBD693f07+9+DQQEkIGAgIgPetzN5yEbAGxWpbCNxXK/0JGTKRz2KkIoR7aM"; + UNIT_ASSERT_EXCEPTION( fh::Decode(Base64Decode(brokenBase64Encoded)), yexception); - } + } Y_UNIT_TEST(TestDecompressEmpty) { UNIT_ASSERT_EXCEPTION(fh::Decode({}), yexception); } -}; +}; diff --git a/library/cpp/codecs/ut/ya.make b/library/cpp/codecs/ut/ya.make index 7f3374a359..90841b05ef 100644 --- a/library/cpp/codecs/ut/ya.make +++ b/library/cpp/codecs/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST() -OWNER( +OWNER( g:base - velavokr -) + velavokr +) PEERDIR( library/cpp/string_utils/base64 diff --git a/library/cpp/codecs/ya.make b/library/cpp/codecs/ya.make index b9bb4e5fc6..7e76fb0c9a 100644 --- a/library/cpp/codecs/ya.make +++ b/library/cpp/codecs/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( +OWNER( g:base - velavokr -) + velavokr +) SRCS( tls_cache.cpp diff --git a/library/cpp/compproto/bit.h b/library/cpp/compproto/bit.h index 9f59481415..6a421b65f7 100644 --- a/library/cpp/compproto/bit.h +++ b/library/cpp/compproto/bit.h @@ -1,15 +1,15 @@ #pragma once - + #include <util/generic/array_ref.h> #include <util/generic/vector.h> -#include <util/stream/output.h> +#include <util/stream/output.h> #include <util/stream/input.h> - + #include "huff.h" #include "compressor.h" #include "metainfo.h" -namespace NCompProto { +namespace NCompProto { struct TBitBuffer { TVector<ui8> Out; ui64 Position; @@ -18,7 +18,7 @@ namespace NCompProto { TBitBuffer() { Clear(); } - + static ui64 Read(const ui8* out, ui64 position, size_t size) { const ui8* dst = out + (size_t(position >> 3)); ui64 outCode = *reinterpret_cast<const ui64*>(dst); diff --git a/library/cpp/compproto/compproto_ut.cpp b/library/cpp/compproto/compproto_ut.cpp index 0845beecc3..9393be967a 100644 --- a/library/cpp/compproto/compproto_ut.cpp +++ b/library/cpp/compproto/compproto_ut.cpp @@ -1,37 +1,37 @@ -#include "huff.h" -#include "metainfo.h" -#include "bit.h" - +#include "huff.h" +#include "metainfo.h" +#include "bit.h" + #include <util/generic/vector.h> #include <util/generic/map.h> -#include <util/system/protect.h> - +#include <util/system/protect.h> + #include <library/cpp/testing/unittest/registar.h> -static ui64 gSeed = 42; - -static void FlushPseudoRandom() { - gSeed = 42; -} - -static ui32 PseudoRandom(ui32 max) { - // stupid and non-threadsafe, but very predictable chaos generator - gSeed += 1; - gSeed *= 419; - gSeed = gSeed ^ (ui64(max) << 17); - return gSeed % max; +static ui64 gSeed = 42; + +static void FlushPseudoRandom() { + gSeed = 42; +} + +static ui32 PseudoRandom(ui32 max) { + // stupid and non-threadsafe, but very predictable chaos generator + gSeed += 1; + gSeed *= 419; + gSeed = gSeed ^ (ui64(max) << 17); + return gSeed % max; +}; + +enum ECompMode { + CM_SINGLEPASS, + CM_TWOPASS +}; + +struct TTestParams { + size_t DataSize; + ui32 ValueArraySize; }; -enum ECompMode { - CM_SINGLEPASS, - CM_TWOPASS -}; - -struct TTestParams { - size_t DataSize; - ui32 ValueArraySize; -}; - template <typename X> void TestSaveLoadMeta(NCompProto::TMetaInfo<X>& src) { TStringStream ss; @@ -45,16 +45,16 @@ void TestSaveLoadMeta(NCompProto::TMetaInfo<X>& src) { template <typename TDecompressor, template <typename, typename> class TSerialize> void TestWithParams(const TString& metainfo, const ECompMode mode, const TTestParams& params) { - using namespace NCompProto; - FlushPseudoRandom(); + using namespace NCompProto; + FlushPseudoRandom(); + + TStringInput stream(metainfo); - TStringInput stream(metainfo); - THolder<TMetaInfo<THuff>> meta; - if (mode == CM_TWOPASS) { + if (mode == CM_TWOPASS) { TMetaInfo<THist> hist(stream); TEmpty empty; - TSerialize<THist, TEmpty>::Serialize(hist, empty, params); + TSerialize<THist, TEmpty>::Serialize(hist, empty, params); meta.Reset(new TMetaInfo<THuff>(hist, THistToHuff::Instance())); } else { meta.Reset(new TMetaInfo<THuff>(stream)); @@ -62,55 +62,55 @@ void TestWithParams(const TString& metainfo, const ECompMode mode, const TTestPa TestSaveLoadMeta(*meta.Get()); TBitBuffer buffer; - TSerialize<THuff, TBitBuffer>::Serialize(*meta, buffer, params); + TSerialize<THuff, TBitBuffer>::Serialize(*meta, buffer, params); ui64 codedSize = buffer.Position; - + TMetaInfo<TTable> decompressor(*meta, THuffToTable::Instance()); - - // verify that no memory read beyond buffer occurs - const size_t byteSize = buffer.ByteLength(); + + // verify that no memory read beyond buffer occurs + const size_t byteSize = buffer.ByteLength(); const size_t PAGESIZEX = 4096; const size_t busyPages = (byteSize + (PAGESIZEX - 1)) / PAGESIZEX; - const size_t allPages = busyPages + 1; + const size_t allPages = busyPages + 1; const size_t allocSize = (allPages + 1) * PAGESIZEX; TVector<ui8> readBuffer(allocSize); - ui8* start = &readBuffer[0]; + ui8* start = &readBuffer[0]; ui8* pageStart = reinterpret_cast<ui8*>((size_t(start) + PAGESIZEX) & ~(PAGESIZEX - 1)); - // XX DATA DATA DATA DATA PROT - // | | | | | pages - // calculate dataStart so that data ends exactly at the page end + // XX DATA DATA DATA DATA PROT + // | | | | | pages + // calculate dataStart so that data ends exactly at the page end ui8* dataStart = pageStart + busyPages * PAGESIZEX - byteSize; ui8* dataEnd = pageStart + busyPages * PAGESIZEX; ProtectMemory(dataEnd, PAGESIZEX, PM_NONE); - // memory copying should be performed without any problems + // memory copying should be performed without any problems memcpy(dataStart, buffer.Out.data(), byteSize); - + ui64 position = 0; TMetaIterator<TDecompressor> instance; - // we should not read beyond dataEnd here - instance.Decompress(&decompressor, dataStart, position); - const ui64 decodedSize = position; + // we should not read beyond dataEnd here + instance.Decompress(&decompressor, dataStart, position); + const ui64 decodedSize = position; UNIT_ASSERT_EQUAL(codedSize, decodedSize); - // unprotect memory + // unprotect memory ProtectMemory(dataEnd, PAGESIZEX, PM_READ | PM_WRITE | PM_EXEC); } -template <typename TDecompressor, template <typename, typename> class TSerialize> +template <typename TDecompressor, template <typename, typename> class TSerialize> void Test(const TString& metainfo, const ECompMode mode) { - for (size_t ds = 3; ds < 42; ds += (3 + PseudoRandom(5))) { - for (size_t vas = 5; vas < 42; vas += (4 + PseudoRandom(10))) { - TTestParams params; - params.DataSize = ds; - params.ValueArraySize = vas; - TestWithParams<TDecompressor, TSerialize>(metainfo, mode, params); - } - } -} + for (size_t ds = 3; ds < 42; ds += (3 + PseudoRandom(5))) { + for (size_t vas = 5; vas < 42; vas += (4 + PseudoRandom(10))) { + TTestParams params; + params.DataSize = ds; + params.ValueArraySize = vas; + TestWithParams<TDecompressor, TSerialize>(metainfo, mode, params); + } + } +} Y_UNIT_TEST_SUITE(CompProtoTestBasic) { - using namespace NCompProto; - + using namespace NCompProto; + const TString metainfo = "\n\ repeated data id 0\n\ @@ -123,14 +123,14 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { scalar extra id 31 default const 0\n\ end\n"; - struct TRegInfo { - ui32 Clicks; - ui32 Shows; + struct TRegInfo { + ui32 Clicks; + ui32 Shows; }; - struct TData { - ui32 Clicks; - ui32 Shows; + struct TData { + ui32 Clicks; + ui32 Shows; ui32 Extra; TMap<ui32, TRegInfo> RegClicks; }; @@ -138,30 +138,30 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { TVector<TData> data; template <class TMeta, class TFunctor> - struct TSerialize { + struct TSerialize { static void Serialize(TMetaInfo<TMeta>& meta, TFunctor& functor, const TTestParams& params) { - FlushPseudoRandom(); + FlushPseudoRandom(); meta.BeginSelf(functor); data.clear(); - data.resize(params.DataSize); - for (ui32 i = 0; i < params.DataSize; ++i) { + data.resize(params.DataSize); + for (ui32 i = 0; i < params.DataSize; ++i) { meta.BeginElement(i, functor); - data[i].Clicks = PseudoRandom(16) + 100; - data[i].Shows = PseudoRandom(500) * PseudoRandom(16); + data[i].Clicks = PseudoRandom(16) + 100; + data[i].Shows = PseudoRandom(500) * PseudoRandom(16); data[i].Extra = PseudoRandom(500) + (1UL << 31); // test also saving of big values - meta.SetScalar(0, data[i].Clicks, functor); - meta.SetScalar(1, data[i].Shows, functor); + meta.SetScalar(0, data[i].Clicks, functor); + meta.SetScalar(1, data[i].Shows, functor); TMetaInfo<TMeta>& regClicks = meta.BeginRepeated(2, functor); - for (ui32 j = 0; j < PseudoRandom(200); j += 1 + PseudoRandom(10)) { + for (ui32 j = 0; j < PseudoRandom(200); j += 1 + PseudoRandom(10)) { regClicks.BeginElement(j, functor); - TRegInfo& r = data[i].RegClicks[j]; + TRegInfo& r = data[i].RegClicks[j]; - r.Clicks = PseudoRandom(2); - r.Shows = PseudoRandom(800) * PseudoRandom(8) + 56; - regClicks.SetScalar(0, r.Clicks, functor); - regClicks.SetScalar(1, r.Shows, functor); + r.Clicks = PseudoRandom(2); + r.Shows = PseudoRandom(800) * PseudoRandom(8) + 56; + regClicks.SetScalar(0, r.Clicks, functor); + regClicks.SetScalar(1, r.Shows, functor); regClicks.EndElement(functor); } @@ -274,7 +274,7 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { case InDataElem: UNIT_ASSERT_EQUAL(id, 2); State = InRegClicks; - RegIter = data[DataInd].RegClicks.begin(); + RegIter = data[DataInd].RegClicks.begin(); break; case InRegClicks: UNIT_ASSERT(0); @@ -292,7 +292,7 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { case InDataElem: UNIT_ASSERT(0); case InRegClicks: - UNIT_ASSERT_EQUAL(RegIter, data[DataInd].RegClicks.end()); + UNIT_ASSERT_EQUAL(RegIter, data[DataInd].RegClicks.end()); State = InDataElem; break; default: @@ -336,17 +336,17 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { UNIT_ASSERT(0); case InDataElem: if (index == 0) - UNIT_ASSERT_EQUAL(val, data[DataInd].Clicks); + UNIT_ASSERT_EQUAL(val, data[DataInd].Clicks); if (index == 1) - UNIT_ASSERT_EQUAL(val, data[DataInd].Shows); + UNIT_ASSERT_EQUAL(val, data[DataInd].Shows); if (index == 31) UNIT_ASSERT_EQUAL(val, data[DataInd].Extra); break; case InRegClicks: if (index == 0) - UNIT_ASSERT_EQUAL(val, RegIter->second.Clicks); + UNIT_ASSERT_EQUAL(val, RegIter->second.Clicks); if (index == 1) - UNIT_ASSERT_EQUAL(val, RegIter->second.Shows); + UNIT_ASSERT_EQUAL(val, RegIter->second.Shows); break; default: UNIT_ASSERT(0); @@ -355,11 +355,11 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { }; Y_UNIT_TEST(VerifyDecompression) { - Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); + Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); } Y_UNIT_TEST(VerifyHistDecompression) { - Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_TWOPASS); + Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_TWOPASS); } Y_UNIT_TEST(VerifyDecompressionMulti) { @@ -372,7 +372,7 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { } Y_UNIT_TEST_SUITE(CompProtoTestExtended) { - using namespace NCompProto; + using namespace NCompProto; const TString metainfo = "\n\ repeated data id 0\n\ @@ -386,17 +386,17 @@ Y_UNIT_TEST_SUITE(CompProtoTestExtended) { TVector<std::pair<TVector<ui32>, TVector<ui32>>> data; template <class TMeta, class TFunctor> - struct TSerialize { + struct TSerialize { static void Serialize(TMetaInfo<TMeta>& meta, TFunctor& functor, const TTestParams& params) { - FlushPseudoRandom(); + FlushPseudoRandom(); meta.BeginSelf(functor); data.clear(); - data.resize(params.DataSize); - for (size_t i = 0; i < params.DataSize; ++i) { + data.resize(params.DataSize); + for (size_t i = 0; i < params.DataSize; ++i) { meta.BeginElement(i, functor); TMetaInfo<TMeta>& first = meta.BeginRepeated(2, functor); data[i].first.resize(params.ValueArraySize); - for (ui32 j = 0; j < params.ValueArraySize; j++) { + for (ui32 j = 0; j < params.ValueArraySize; j++) { first.BeginElement(j, functor); ui32 val = PseudoRandom(42 * 42 * 42); @@ -409,7 +409,7 @@ Y_UNIT_TEST_SUITE(CompProtoTestExtended) { TMetaInfo<TMeta>& second = meta.BeginRepeated(3, functor); data[i].second.resize(params.ValueArraySize); - for (ui32 j = 0; j < params.ValueArraySize; j++) { + for (ui32 j = 0; j < params.ValueArraySize; j++) { second.BeginElement(j, functor); ui32 val = PseudoRandom(42 * 42 * 42); @@ -534,10 +534,10 @@ Y_UNIT_TEST_SUITE(CompProtoTestExtended) { } }; Y_UNIT_TEST(VerifyDecompression) { - Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); + Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); } Y_UNIT_TEST(VerifyHistDecompression) { - Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_TWOPASS); + Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_TWOPASS); } } diff --git a/library/cpp/compproto/compressor.h b/library/cpp/compproto/compressor.h index d6397269ac..14b335e13c 100644 --- a/library/cpp/compproto/compressor.h +++ b/library/cpp/compproto/compressor.h @@ -1,11 +1,11 @@ #pragma once -#include <util/system/defaults.h> - -namespace NCompProto { +#include <util/system/defaults.h> + +namespace NCompProto { struct TEmpty { }; - + struct TTable { TTable() { for (size_t i = 0; i < 64; ++i) { @@ -70,5 +70,5 @@ namespace NCompProto { return (((ui32)(code >> PrefLength[index])) & CodeMask[index]) + CodeBase[index]; } }; - + } diff --git a/library/cpp/compproto/huff.h b/library/cpp/compproto/huff.h index 11c5f2e074..fa5c139189 100644 --- a/library/cpp/compproto/huff.h +++ b/library/cpp/compproto/huff.h @@ -1,14 +1,14 @@ #pragma once -#include <util/system/defaults.h> -#include <util/generic/yexception.h> -#include <util/generic/ptr.h> -#include <util/generic/vector.h> -#include <util/generic/algorithm.h> +#include <util/system/defaults.h> +#include <util/generic/yexception.h> +#include <util/generic/ptr.h> +#include <util/generic/vector.h> +#include <util/generic/algorithm.h> #include <utility> - + #include <queue> - + #include "compressor.h" namespace NCompProto { diff --git a/library/cpp/compproto/metainfo.h b/library/cpp/compproto/metainfo.h index 17b708de1d..6e68f86e12 100644 --- a/library/cpp/compproto/metainfo.h +++ b/library/cpp/compproto/metainfo.h @@ -1,17 +1,17 @@ #pragma once -#include <util/system/defaults.h> -#include <util/generic/yexception.h> -#include <util/generic/ptr.h> -#include <util/generic/refcount.h> -#include <util/stream/input.h> +#include <util/system/defaults.h> +#include <util/generic/yexception.h> +#include <util/generic/ptr.h> +#include <util/generic/refcount.h> +#include <util/stream/input.h> #include <util/stream/str.h> - + #include "compressor.h" -namespace NCompProto { +namespace NCompProto { const size_t MAX_ELEMENTS = 32; - + struct TScalarDefaultValue { TScalarDefaultValue() : Type(None) @@ -300,5 +300,5 @@ namespace NCompProto { } } }; - + } diff --git a/library/cpp/compproto/ya.make b/library/cpp/compproto/ya.make index a5fc76b80a..60d5cfa08d 100644 --- a/library/cpp/compproto/ya.make +++ b/library/cpp/compproto/ya.make @@ -1,7 +1,7 @@ LIBRARY() -OWNER(ironpeter) - +OWNER(ironpeter) + SRCS( bit.h compressor.h diff --git a/library/cpp/deprecated/mapped_file/mapped_file.cpp b/library/cpp/deprecated/mapped_file/mapped_file.cpp index e5ab717f79..b0e4511299 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.cpp +++ b/library/cpp/deprecated/mapped_file/mapped_file.cpp @@ -9,7 +9,7 @@ TMappedFile::TMappedFile(TFileMap* map, const char* dbgName) { Map_ = map; i64 len = Map_->Length(); if (Hi32(len) != 0 && sizeof(size_t) <= sizeof(ui32)) - ythrow yexception() << "File '" << dbgName << "' mapping error: " << len << " too large"; + ythrow yexception() << "File '" << dbgName << "' mapping error: " << len << " too large"; Map_->Map(0, static_cast<size_t>(len)); } @@ -17,7 +17,7 @@ TMappedFile::TMappedFile(TFileMap* map, const char* dbgName) { TMappedFile::TMappedFile(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) : Map_(nullptr) { - init(file, om, dbgName); + init(file, om, dbgName); } void TMappedFile::precharge(size_t off, size_t size) const { @@ -45,7 +45,7 @@ void TMappedFile::init(const TString& name, size_t length, TFileMap::EOpenMode o void TMappedFile::init(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) { THolder<TFileMap> map(new TFileMap(file, om)); - TMappedFile newFile(map.Get(), dbgName); + TMappedFile newFile(map.Get(), dbgName); Y_UNUSED(map.Release()); newFile.swap(*this); newFile.term(); diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h index 67df94db05..45859ed65a 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.h +++ b/library/cpp/deprecated/mapped_file/mapped_file.h @@ -13,7 +13,7 @@ #include <cstdio> #include <new> -/// Deprecated (by pg@), use TFileMap or TMemoryMap instead +/// Deprecated (by pg@), use TFileMap or TMemoryMap instead class TMappedFile { private: TFileMap* Map_; 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 988b0a9967..afbd5b3358 100644 --- a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp +++ b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp @@ -4,7 +4,7 @@ #include <util/system/fs.h> Y_UNIT_TEST_SUITE(TMappedFileTest) { - static const char* FileName_("./mappped_file"); + static const char* FileName_("./mappped_file"); Y_UNIT_TEST(TestFileMapEmpty) { TFile file(FileName_, CreateAlways | WrOnly); file.Close(); diff --git a/library/cpp/digest/md5/md5.cpp b/library/cpp/digest/md5/md5.cpp index 374f6aeda7..24a5b69eef 100644 --- a/library/cpp/digest/md5/md5.cpp +++ b/library/cpp/digest/md5/md5.cpp @@ -1,8 +1,8 @@ -#include "md5.h" - +#include "md5.h" + #include <library/cpp/string_utils/base64/base64.h> -#include <util/stream/input.h> +#include <util/stream/input.h> #include <util/stream/file.h> #include <util/string/hex.h> @@ -99,10 +99,10 @@ void MD5::Init() { BufferSize = 0; StreamSize = 0; /* Load magic initialization constants. */ - State[0] = 0x67452301; - State[1] = 0xefcdab89; - State[2] = 0x98badcfe; - State[3] = 0x10325476; + State[0] = 0x67452301; + State[1] = 0xefcdab89; + State[2] = 0x98badcfe; + State[3] = 0x10325476; } /* diff --git a/library/cpp/digest/md5/md5.h b/library/cpp/digest/md5/md5.h index e1b804d128..2c17aa0518 100644 --- a/library/cpp/digest/md5/md5.h +++ b/library/cpp/digest/md5/md5.h @@ -4,7 +4,7 @@ #include <util/generic/strbuf.h> class IInputStream; - + class MD5 { public: MD5() { @@ -29,12 +29,12 @@ public: void Pad(); ui8* Final(ui8[16]); - // buf must be char[33]; - char* End(char* buf); - - // buf must be char[25]; - char* End_b64(char* buf); - + // buf must be char[33]; + char* End(char* buf); + + // buf must be char[25]; + char* End_b64(char* buf); + // 8-byte xor-based mix ui64 EndHalfMix(); @@ -45,7 +45,7 @@ public: * * Return nullptr / empty string if the file does not exist. */ - static char* File(const char* filename, char* buf); + static char* File(const char* filename, char* buf); static TString File(const TString& filename); static char* Data(const void* data, size_t len, char* buf); diff --git a/library/cpp/digest/md5/md5_medium_ut.cpp b/library/cpp/digest/md5/md5_medium_ut.cpp index 20067aa62c..a940c5cb66 100644 --- a/library/cpp/digest/md5/md5_medium_ut.cpp +++ b/library/cpp/digest/md5/md5_medium_ut.cpp @@ -20,6 +20,6 @@ Y_UNIT_TEST_SUITE(TMD5MediumTest) { s.to_lower(); UNIT_ASSERT_VALUES_EQUAL(s, "34a5a7ed4f0221310084e21a1e599659"); - } - } -} + } + } +} diff --git a/library/cpp/digest/md5/md5_ut.cpp b/library/cpp/digest/md5/md5_ut.cpp index d92efc9975..1c3e4ad0a9 100644 --- a/library/cpp/digest/md5/md5_ut.cpp +++ b/library/cpp/digest/md5/md5_ut.cpp @@ -7,35 +7,35 @@ Y_UNIT_TEST_SUITE(TMD5Test) { Y_UNIT_TEST(TestMD5) { - // echo -n 'qwertyuiopqwertyuiopasdfghjklasdfghjkl' | md5sum + // echo -n 'qwertyuiopqwertyuiopasdfghjklasdfghjkl' | md5sum constexpr const char* b = "qwertyuiopqwertyuiopasdfghjklasdfghjkl"; - MD5 r; - r.Update((const unsigned char*)b, 15); - r.Update((const unsigned char*)b + 15, strlen(b) - 15); + MD5 r; + r.Update((const unsigned char*)b, 15); + r.Update((const unsigned char*)b + 15, strlen(b) - 15); - char rs[33]; + char rs[33]; TString s(r.End(rs)); - s.to_lower(); + s.to_lower(); UNIT_ASSERT_NO_DIFF(s, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); TString result = r.Calc(TStringBuf(b)); - result.to_lower(); + result.to_lower(); UNIT_ASSERT_NO_DIFF(result, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); - } + } Y_UNIT_TEST(TestFile) { TString s = NUnitTest::RandomString(1000000, 1); const TString tmpFile = "tmp"; - { + { TFixedBufferFileOutput fo(tmpFile); fo.Write(s.data(), s.size()); - } + } - char fileBuf[100]; - char memBuf[100]; + char fileBuf[100]; + char memBuf[100]; TString fileHash = MD5::File(tmpFile.data(), fileBuf); TString memoryHash = MD5::Data((const unsigned char*)s.data(), s.size(), memBuf); @@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(TMD5Test) { NFs::Remove(tmpFile); fileHash = MD5::File(tmpFile); UNIT_ASSERT_EQUAL(fileHash.size(), 0); - } + } Y_UNIT_TEST(TestIsMD5) { UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf())); @@ -63,4 +63,4 @@ Y_UNIT_TEST_SUITE(TMD5Test) { UNIT_ASSERT_EQUAL(MD5::CalcHalfMix(""), 7203772011789518145ul); UNIT_ASSERT_EQUAL(MD5::CalcHalfMix("qwertyuiopqwertyuiopasdfghjklasdfghjkl"), 11753545595885642730ul); } -} +} diff --git a/library/cpp/digest/old_crc/crc.h b/library/cpp/digest/old_crc/crc.h index 5ffb93b2fa..4a3ce6d05e 100644 --- a/library/cpp/digest/old_crc/crc.h +++ b/library/cpp/digest/old_crc/crc.h @@ -53,9 +53,9 @@ inline ui64 crc64(const void* buf, size_t buflen, ui64 crcinit = CRC64INIT) { const unsigned char* ptr = (const unsigned char*)buf; extern const ui64* crctab64; - while (buflen--) { + while (buflen--) { crcinit = crctab64[((crcinit >> 56) ^ *ptr++)] ^ (crcinit << 8); - } + } return crcinit; } diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index cbdd7ed458..79426a9cc9 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -51,9 +51,9 @@ protected: // Built-in options. opts.AddHelpOption('h'); opts.AddCompletionOption("last_getopt_demo"); - + // Custom options. - + opts.AddLongOption('V', "version") .Help("print version and exit") .IfPresentDisableCompletion() @@ -62,11 +62,11 @@ protected: Cerr << "last_getopt_demo 1.0.0" << Endl; exit(0); }); - + opts.AddLongOption('b', "background") .Help("go to background immediately after startup") .StoreTrue(&Background_); - + opts.AddLongOption("timeout") .RequiredArgument("timeout") .DefaultValue("60000") @@ -110,7 +110,7 @@ protected: .Handler0([this]() { ImplicitMethod_ = "POST"; }); - + opts.AddLongOption("post-file") .RequiredArgument("file") .Help("use POST method and send contents of the specified file in the request body (cannot be used with --post-data)") diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 6d11600a46..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -7,9 +7,9 @@ #include <library/cpp/colorizer/colors.h> #include <util/stream/output.h> -#include <util/stream/format.h> +#include <util/stream/format.h> #include <util/generic/yexception.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/string/builder.h> #include <util/string/join.h> @@ -99,7 +99,7 @@ void TModChooser::AddMode(const TString& mode, const TMainFunctionPtrV func, con } void TModChooser::AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden, bool noCompletion) { - if (Modes.FindPtr(mode)) { + if (Modes.FindPtr(mode)) { ythrow yexception() << "TMode '" << mode << "' already exists in TModChooser."; } @@ -184,7 +184,7 @@ int TModChooser::Run(const int argc, const char** argv) const { PrintHelp(argv[0]); return 0; } - if (VersionHandler && (modeName == "-v" || modeName == "--version")) { + if (VersionHandler && (modeName == "-v" || modeName == "--version")) { VersionHandler(); return 0; } @@ -199,7 +199,7 @@ int TModChooser::Run(const int argc, const char** argv) const { } if (modeIter == Modes.end()) { - Cerr << "Unknown mode " << modeName.Quote() << "." << Endl; + Cerr << "Unknown mode " << modeName.Quote() << "." << Endl; PrintHelp(argv[0]); return 1; } @@ -280,9 +280,9 @@ TString TModChooser::TMode::FormatFullName(size_t pad) const { void TModChooser::PrintHelp(const TString& progName) const { Cerr << Description << Endl << Endl; Cerr << NColorizer::StdErr().BoldColor() << "Usage" << NColorizer::StdErr().OldColor() << ": " << progName << " MODE [MODE_OPTIONS]" << Endl; - Cerr << Endl; + Cerr << Endl; Cerr << NColorizer::StdErr().BoldColor() << "Modes" << NColorizer::StdErr().OldColor() << ":" << Endl; - size_t maxModeLen = 0; + size_t maxModeLen = 0; for (const auto& [name, mode] : Modes) { if (name != mode->Name) continue; // this is an alias @@ -309,11 +309,11 @@ void TModChooser::PrintHelp(const TString& progName) const { } } } - - Cerr << Endl; - Cerr << "To get help for specific mode type '" << progName << " MODE " << ModesHelpOption << "'" << Endl; - if (VersionHandler) - Cerr << "To print program version type '" << progName << " --version'" << Endl; + + Cerr << Endl; + Cerr << "To get help for specific mode type '" << progName << " MODE " << ModesHelpOption << "'" << Endl; + if (VersionHandler) + Cerr << "To print program version type '" << progName << " --version'" << Endl; if (!SvnRevisionOptionDisabled) { Cerr << "To print svn revision type --svnrevision" << Endl; } diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 954d8574ca..0a8de6d50b 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -141,7 +141,7 @@ private: //! Help option for modes. TString ModesHelpOption; - //! Wrappers around all modes. + //! Wrappers around all modes. TVector<THolder<TMainClass>> Wrappers; //! Modes diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index 9a06287fec..c99a1d053d 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -145,8 +145,8 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { UNIT_ASSERT_VALUES_EQUAL("/etc", r.GetOrElse("to", "trash")); UNIT_ASSERT(r.Has("from")); UNIT_ASSERT(r.Has("to")); - - UNIT_ASSERT_EXCEPTION(r.Get("left"), TException); + + UNIT_ASSERT_EXCEPTION(r.Get("left"), TException); } Y_UNIT_TEST(TestCharOptions) { @@ -160,30 +160,30 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { UNIT_ASSERT(!r.Has('h')); UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgs().size()); - UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgCount()); + UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgCount()); UNIT_ASSERT_VALUES_EQUAL("/etc", r.GetFreeArgs()[0]); UNIT_ASSERT_VALUES_EQUAL("/tmp/etc", r.GetFreeArgs()[1]); } Y_UNIT_TEST(TestFreeArgs) { - TOptsNoDefault opts; - opts.SetFreeArgsNum(1, 3); + TOptsNoDefault opts; + opts.SetFreeArgsNum(1, 3); TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); - - UNIT_ASSERT_EXCEPTION( + + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), yexception); - - UNIT_ASSERT_EXCEPTION( + + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp"})), yexception); - - opts.SetFreeArgsNum(2); + + opts.SetFreeArgsNum(2); TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); - } - + } + Y_UNIT_TEST(TestCharOptionsRequiredOptional) { TOptsNoDefault opts; opts.AddCharOption('d', REQUIRED_ARGUMENT); @@ -350,19 +350,19 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // this test is broken, cause UNIT_ASSERT(false) always throws return; - bool exception = false; - try { - TOpts opts; - opts.AddLongOption('x', "one"); - opts.AddLongOption('x', "two"); - UNIT_ASSERT(false); + bool exception = false; + try { + TOpts opts; + opts.AddLongOption('x', "one"); + opts.AddLongOption('x', "two"); + UNIT_ASSERT(false); } catch (...) { - // we should go here, duplicating options are forbidden - exception = true; - } - UNIT_ASSERT(exception); - } - + // we should go here, duplicating options are forbidden + exception = true; + } + UNIT_ASSERT(exception); + } + Y_UNIT_TEST(TestPositionWhenNoArgs) { TOptsParserTester tester; @@ -527,7 +527,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // test 'required' opt_d.Required(); - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd"})), TUsageException); @@ -563,7 +563,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption("flag2").RequiredArgument().StoreResultT<int>(&uval); opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs); opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt); - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), yexception); UNIT_ASSERT_VALUES_EQUAL(uval, 5u); @@ -575,21 +575,21 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestTitleAndPrintUsage) { - TOpts opts; - const char* prog = "my_program"; + TOpts opts; + const char* prog = "my_program"; TString title = TString("Sample ") + TString(prog).Quote() + " application"; - opts.SetTitle(title); - int argc = 2; + opts.SetTitle(title); + int argc = 2; const char* cmd[] = {prog}; - TOptsParser parser(&opts, argc, cmd); - TStringStream out; - parser.PrintUsage(out); - // find title + TOptsParser parser(&opts, argc, cmd); + TStringStream out; + parser.PrintUsage(out); + // find title UNIT_ASSERT(out.Str().find(title) != TString::npos); - // find usage + // find usage UNIT_ASSERT(out.Str().find(" " + TString(prog) + " ") != TString::npos); - } - + } + Y_UNIT_TEST(TestCustomCmdLineDescr) { TOpts opts; const char* prog = "my_program"; @@ -756,7 +756,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } { - UNIT_ASSERT_EXCEPTION( + UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), TUsageException); } diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h index f14cabe1c8..b2810bbd41 100644 --- a/library/cpp/http/fetch/httpheader.h +++ b/library/cpp/http/fetch/httpheader.h @@ -8,8 +8,8 @@ #include <util/system/compat.h> #include <util/generic/string.h> #include <util/generic/ylimits.h> -#include <util/system/maxlen.h> - +#include <util/system/maxlen.h> + #include <ctime> #include <cstdio> #include <cstdlib> diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp index c7568f4eb3..2f3d131f8c 100644 --- a/library/cpp/http/io/compression_ut.cpp +++ b/library/cpp/http/io/compression_ut.cpp @@ -9,14 +9,14 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) { static const TString DATA = "I'm a teapot"; - + Y_UNIT_TEST(TestGetBestCodecs) { UNIT_ASSERT(TCompressionCodecFactory::Instance().GetBestCodecs().size() > 0); } - + Y_UNIT_TEST(TestEncoder) { TStringStream buffer; - + { auto encoder = TCompressionCodecFactory::Instance().FindEncoder("gzip"); UNIT_ASSERT(encoder); @@ -27,7 +27,7 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) { TZLibDecompress decompressor(&buffer); UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA); - } + } Y_UNIT_TEST(TestDecoder) { TStringStream buffer; diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 358af13259..6689be684f 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -228,15 +228,15 @@ private: } struct TParsedHeaders { - bool Chunked = false; - bool KeepAlive = false; + bool Chunked = false; + bool KeepAlive = false; TStringBuf LZipped; }; struct TTrEnc { inline void operator()(const TStringBuf& s) { if (s == TStringBuf("chunked")) { - p->Chunked = true; + p->Chunked = true; } } @@ -318,9 +318,9 @@ private: HEADERCMP(header, "connection") { // accept header "Connection: Keep-Alive, TE" if (strnicmp(header.Value().data(), "keep-alive", 10) == 0) { - p.KeepAlive = true; + p.KeepAlive = true; } else if (stricmp(header.Value().data(), "close") == 0) { - p.KeepAlive = false; + p.KeepAlive = false; } } [[fallthrough]]; @@ -336,7 +336,7 @@ private: } } - if (p.Chunked) { + if (p.Chunked) { ChunkedInput_ = Streams_.Add(new TChunkedInput(&Buffered_, &Trailers_)); Input_ = ChunkedInput_; } else { @@ -357,7 +357,7 @@ private: Input_ = Streams_.Add((*decoder)(Input_).Release()); } - KeepAlive_ = p.KeepAlive; + KeepAlive_ = p.KeepAlive; } private: @@ -474,7 +474,7 @@ class THttpOutput::TImpl { } private: - size_t Length_ = 0; + size_t Length_ = 0; }; enum TState { @@ -564,7 +564,7 @@ public: inline void Flush() { TFlush f; Streams_.ForEach(f); - Slave_->Flush(); // see SEARCH-1030 + Slave_->Flush(); // see SEARCH-1030 } inline void Finish() { @@ -574,7 +574,7 @@ public: TFinish f; Streams_.ForEach(f); - Slave_->Finish(); // see SEARCH-1030 + Slave_->Finish(); // see SEARCH-1030 Finished_ = true; } @@ -806,10 +806,10 @@ private: } inline void RebuildStream() { - bool keepAlive = false; + bool keepAlive = false; const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr; bool chunked = false; - bool haveContentLength = false; + bool haveContentLength = false; for (THttpHeaders::TConstIterator h = Headers_.Begin(); h != Headers_.End(); ++h) { const THttpInputHeader& header = *h; @@ -822,7 +822,7 @@ private: } else if (hl == TStringBuf("transfer-encoding")) { chunked = to_lower(header.Value()) == TStringBuf("chunked"); } else if (hl == TStringBuf("content-length")) { - haveContentLength = true; + haveContentLength = true; } } diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 51e8177676..1ea35df675 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -15,84 +15,84 @@ #include <util/stream/null.h> Y_UNIT_TEST_SUITE(THttpStreamTest) { - class TTestHttpServer: public THttpServer::ICallBack { - class TRequest: public THttpClientRequestEx { - public: - inline TRequest(TTestHttpServer* parent) - : Parent_(parent) - { - } - + class TTestHttpServer: public THttpServer::ICallBack { + class TRequest: public THttpClientRequestEx { + public: + inline TRequest(TTestHttpServer* parent) + : Parent_(parent) + { + } + bool Reply(void* /*tsr*/) override { - if (!ProcessHeaders()) { + if (!ProcessHeaders()) { return true; - } + } // Check that function will not hang on Input().ReadAll(); - // "lo" is for "local" - if (RD.ServerName() == "yandex.lo") { - // do redirect + // "lo" is for "local" + if (RD.ServerName() == "yandex.lo") { + // do redirect Output() << "HTTP/1.1 301 Moved permanently\r\n" "Location: http://www.yandex.lo\r\n" "\r\n"; - } else if (RD.ServerName() == "www.yandex.lo") { + } else if (RD.ServerName() == "www.yandex.lo") { Output() << "HTTP/1.1 200 Ok\r\n" "\r\n"; - } else { - Output() << "HTTP/1.1 200 Ok\r\n\r\n"; + } else { + Output() << "HTTP/1.1 200 Ok\r\n\r\n"; if (Buf.Size()) { Output().Write(Buf.AsCharPtr(), Buf.Size()); - } else { - Output() << Parent_->Res_; - } - } - Output().Finish(); - + } else { + Output() << Parent_->Res_; + } + } + Output().Finish(); + Parent_->LastRequestSentSize_ = Output().SentSize(); - return true; - } - - private: - TTestHttpServer* Parent_ = nullptr; - }; - - public: + return true; + } + + private: + TTestHttpServer* Parent_ = nullptr; + }; + + public: inline TTestHttpServer(const TString& res) - : Res_(res) - { - } - + : Res_(res) + { + } + TClientRequest* CreateClient() override { - return new TRequest(this); - } - + return new TRequest(this); + } + size_t LastRequestSentSize() const { return LastRequestSentSize_; } - private: + private: TString Res_; size_t LastRequestSentSize_ = 0; - }; - + }; + Y_UNIT_TEST(TestCodings1) { UNIT_ASSERT(SupportedCodings().size() > 0); } - + Y_UNIT_TEST(TestHttpInput) { TString res = "I'm a teapot"; TPortManager pm; const ui16 port = pm.GetPort(); - - TTestHttpServer serverImpl(res); - THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); - - UNIT_ASSERT(server.Start()); - - TNetworkAddress addr("localhost", port); + + TTestHttpServer serverImpl(res); + THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); + + UNIT_ASSERT(server.Start()); + + TNetworkAddress addr("localhost", port); TSocket s(addr); //TDebugOutput dbg; @@ -109,7 +109,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString r; r += "GET / HTTP/1.1"; r += "\r\n"; - r += "Host: yandex.lo"; + r += "Host: yandex.lo"; r += "\r\n"; r += "\r\n"; @@ -125,8 +125,8 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TransferData(&input, &dbg); } - server.Stop(); - } + server.Stop(); + } Y_UNIT_TEST(TestHttpInputDelete) { TString res = "I'm a teapot"; @@ -240,26 +240,26 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString res = "qqqqqq"; TPortManager pm; const ui16 port = pm.GetPort(); - - TTestHttpServer serverImpl(res); - THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); - - UNIT_ASSERT(server.Start()); - - TNetworkAddress addr("localhost", port); - + + TTestHttpServer serverImpl(res); + THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); + + UNIT_ASSERT(server.Start()); + + TNetworkAddress addr("localhost", port); + TSocket s(addr); TNullOutput dbg; - SendMinimalHttpRequest(s, "www.yandex.lo", "/"); + SendMinimalHttpRequest(s, "www.yandex.lo", "/"); TSocketInput si(s); THttpInput input(&si); - unsigned httpCode = ParseHttpRetCode(input.FirstLine()); + unsigned httpCode = ParseHttpRetCode(input.FirstLine()); UNIT_ASSERT_VALUES_EQUAL(httpCode, 200u); TransferData(&input, &dbg); - server.Stop(); + server.Stop(); } Y_UNIT_TEST(TestResponseWithBlanks) { diff --git a/library/cpp/http/io/ut/ya.make b/library/cpp/http/io/ut/ya.make index de9aee8fb7..84f6949db3 100644 --- a/library/cpp/http/io/ut/ya.make +++ b/library/cpp/http/io/ut/ya.make @@ -2,10 +2,10 @@ UNITTEST_FOR(library/cpp/http/io) OWNER(g:util) -PEERDIR( +PEERDIR( library/cpp/http/server -) - +) + SRCS( chunk_ut.cpp compression_ut.cpp diff --git a/library/cpp/http/io/ya.make b/library/cpp/http/io/ya.make index d28fe909e3..dcfbd79885 100644 --- a/library/cpp/http/io/ya.make +++ b/library/cpp/http/io/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( +OWNER( g:util - mvel -) + mvel +) PEERDIR( library/cpp/blockcodecs diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index c8d6e66dc7..16e59c4d78 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -10,7 +10,7 @@ #include <util/network/address.h> #include <util/network/socket.h> #include <util/generic/hash.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <util/generic/string.h> #include <util/datetime/base.h> #include <util/generic/buffer.h> @@ -47,9 +47,9 @@ public: return Search; } - TStringBuf QueryStringBuf() const { - return TStringBuf(Search, SearchLength); - } + TStringBuf QueryStringBuf() const { + return TStringBuf(Search, SearchLength); + } TStringBuf OrigQueryStringBuf() const { return OrigSearch; @@ -93,7 +93,7 @@ private: TString Port; char* Path; char* Search; - size_t SearchLength; // length of Search + size_t SearchLength; // length of Search TStringBuf OrigSearch; THttpHeadersContainer HeadersIn_; mutable char AddrData[INET6_ADDRSTRLEN]; diff --git a/library/cpp/http/misc/httpreqdata_ut.cpp b/library/cpp/http/misc/httpreqdata_ut.cpp index e1d7156656..e7f16ef27c 100644 --- a/library/cpp/http/misc/httpreqdata_ut.cpp +++ b/library/cpp/http/misc/httpreqdata_ut.cpp @@ -1,7 +1,7 @@ -#include "httpreqdata.h" - +#include "httpreqdata.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TRequestServerDataTest) { Y_UNIT_TEST(Headers) { TServerRequestData sd; @@ -44,13 +44,13 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { Y_UNIT_TEST(ParseScan) { TServerRequestData rd; - + // Parse parses url without host UNIT_ASSERT(!rd.Parse(" http://yandex.ru/yandsearch?>a=fake&haha=da HTTP 1.1 OK")); - + // This should work UNIT_ASSERT(rd.Parse(" /yandsearch?>a=fake&haha=da HTTP 1.1 OK")); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ">a=fake&haha=da"); UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), rd.OrigQueryStringBuf()); @@ -58,10 +58,10 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("gta", "fake")); UNIT_ASSERT(rd.CgiParam.Has("haha", "da")); UNIT_ASSERT(!rd.CgiParam.Has("no-param")); - + rd.Clear(); } - + Y_UNIT_TEST(Ctor) { const TString qs("gta=fake&haha=da"); TServerRequestData rd(qs.c_str()); @@ -73,14 +73,14 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("haha")); UNIT_ASSERT(!rd.CgiParam.Has("no-param")); } - + Y_UNIT_TEST(HashCut) { const TString qs(">a=fake&haha=da"); const TString header = " /yandsearch?" + qs + "#&uberParam=yes&q=? HTTP 1.1 OK"; TServerRequestData rd; rd.Parse(header.c_str()); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), qs); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), qs); @@ -89,36 +89,36 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("haha")); UNIT_ASSERT(!rd.CgiParam.Has("uberParam")); } - + Y_UNIT_TEST(MisplacedHashCut) { TServerRequestData rd; rd.Parse(" /y#ndsearch?>a=fake&haha=da&uberParam=yes&q=? HTTP 1.1 OK"); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ""); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), ""); rd.Scan(); UNIT_ASSERT(rd.CgiParam.empty()); } - + Y_UNIT_TEST(CornerCase) { TServerRequestData rd; rd.Parse(" /yandsearch?#"); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ""); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), ""); rd.Scan(); UNIT_ASSERT(rd.CgiParam.empty()); } - + Y_UNIT_TEST(AppendQueryString) { const TString qs("gta=fake&haha=da"); TServerRequestData rd(qs.c_str()); - + UNIT_ASSERT(rd.CgiParam.Has("gta", "fake")); UNIT_ASSERT(rd.CgiParam.Has("haha", "da")); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), qs); UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), rd.OrigQueryStringBuf()); @@ -129,7 +129,7 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), qs); rd.Scan(); - + UNIT_ASSERT(rd.CgiParam.Has("gta", "true")); UNIT_ASSERT(rd.CgiParam.Has("gta", "new")); } @@ -151,4 +151,4 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { } } -} // TRequestServerDataTest +} // TRequestServerDataTest diff --git a/library/cpp/http/misc/ya.make b/library/cpp/http/misc/ya.make index 298be41adc..fceb3cf79c 100644 --- a/library/cpp/http/misc/ya.make +++ b/library/cpp/http/misc/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( +OWNER( g:util - mvel -) + mvel +) GENERATE_ENUM_SERIALIZATION(httpcodes.h) diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 6980ccd035..128583bdd7 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -8,7 +8,7 @@ #include <util/generic/intrlist.h> #include <util/generic/yexception.h> #include <util/network/address.h> -#include <util/network/socket.h> +#include <util/network/socket.h> #include <util/network/poller.h> #include <util/system/atomic.h> #include <util/system/compat.h> // stricmp, strnicmp, strlwr, strupr, stpcpy @@ -64,7 +64,7 @@ public: public: TSocket Socket_; NAddr::IRemoteAddrRef ListenerSockAddrRef_; - THttpServer::TImpl* HttpServ_ = nullptr; + THttpServer::TImpl* HttpServ_ = nullptr; bool Reject_ = false; TInstant LastUsed; TInstant AcceptMoment; @@ -131,7 +131,7 @@ public: public: TMutex Mutex_; TIntrusiveListWithAutoDelete<TClientConnection, TDelete> Conns_; - TSocketPoller* Poller_ = nullptr; + TSocketPoller* Poller_ = nullptr; const THttpServerOptions& Options; }; @@ -184,7 +184,7 @@ public: Poller.Reset(new TSocketPoller()); Connections.Reset(new TConnections(Poller.Get(), Options_)); - // Start the listener thread + // Start the listener thread ListenerRunningOK = false; // throws on error @@ -204,7 +204,7 @@ public: return false; } - // Wait until the thread has completely started and return the success indicator + // Wait until the thread has completely started and return the success indicator ListenStartEvent.Wait(); return ListenerRunningOK; @@ -271,15 +271,15 @@ public: } } } - + size_t GetRequestQueueSize() const { return Requests->Size(); } - + size_t GetFailQueueSize() const { return FailRequests->Size(); } - + const IThreadPool& GetRequestQueue() const { return *Requests; } @@ -316,7 +316,7 @@ public: private: TSocket S_; - TImpl* Server_ = nullptr; + TImpl* Server_ = nullptr; NAddr::IRemoteAddrRef SockAddrRef_; }; @@ -407,7 +407,7 @@ public: } TImpl(THttpServer* parent, ICallBack* cb, const TOptions& options, IThreadFactory* factory) - : TImpl( + : TImpl( parent, cb, MakeThreadPool<TSimpleThreadPool>(factory, options.UseElasticQueues, cb, options.RequestsThreadName), @@ -448,14 +448,14 @@ public: TSystemEvent ListenStartEvent; TMtpQueueRef Requests; TMtpQueueRef FailRequests; - TAtomic ConnectionCount = 0; + TAtomic ConnectionCount = 0; THolder<TSocketPoller> Poller; THolder<TConnections> Connections; - bool ListenerRunningOK = false; + bool ListenerRunningOK = false; int ErrorCode = 0; TOptions Options_; - ICallBack* Cb_ = nullptr; - THttpServer* Parent_ = nullptr; + ICallBack* Cb_ = nullptr; + THttpServer* Parent_ = nullptr; TWakeupPollAble WakeupPollAble; TMutex StopMutex; @@ -630,7 +630,7 @@ bool TClientRequest::Reply(void* /*ThreadSpecificResource*/) { } bool TClientRequest::IsLocal() const { - return HasLocalAddress(Socket()); + return HasLocalAddress(Socket()); } bool TClientRequest::CheckLoopback() { diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index 37a3dc6146..b292d38f27 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -73,7 +73,7 @@ public: // shutdown a.s.a.p. void Stop(); - // graceful shutdown with serving all already open connections + // graceful shutdown with serving all already open connections void Shutdown(); void Wait(); diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index 64a62cc889..cc62bb988e 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } private: - TEchoServer* Parent_ = nullptr; + TEchoServer* Parent_ = nullptr; }; public: @@ -163,7 +163,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } TString Execute() { - TSocket* s = nullptr; + TSocket* s = nullptr; THolder<TSocket> singleReqSocket; if (KeepAliveConnection) { if (!KeepAlivedSocket) { @@ -277,48 +277,48 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } } - ui16 Port = 0; - bool UseHttpOutput = true; + ui16 Port = 0; + bool UseHttpOutput = true; TString Type = "GET"; TString ContentEncoding; TString Content; - bool KeepAliveConnection = false; + bool KeepAliveConnection = false; THolder<TSocket> KeepAlivedSocket; - bool EnableResponseEncoding = false; + bool EnableResponseEncoding = false; TString Hdr; bool Expect100Continue = false; }; class TFailingMtpQueue: public TSimpleThreadPool { - private: - bool FailOnAdd_ = false; + private: + bool FailOnAdd_ = false; - public: - void SetFailOnAdd(bool fail = true) { - FailOnAdd_ = fail; - } + public: + void SetFailOnAdd(bool fail = true) { + FailOnAdd_ = fail; + } [[nodiscard]] bool Add(IObjectInQueue* pObj) override { - if (FailOnAdd_) { - return false; - } - + if (FailOnAdd_) { + return false; + } + return TSimpleThreadPool::Add(pObj); - } - TFailingMtpQueue() = default; + } + TFailingMtpQueue() = default; TFailingMtpQueue(IThreadFactory* pool) : TSimpleThreadPool(pool) - { - } - }; - + { + } + }; + TString TestData(size_t size = 5 * 4096) { TString res; - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { res += (char)i; } - return res; - } + return res; + } Y_UNIT_TEST(TestEchoServer) { TString res = TestData(); @@ -338,7 +338,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { for (bool keepAlive : trueFalse) { r.KeepAliveConnection = keepAlive; - // THttpOutput use chunked stream, else use Content-Length + // THttpOutput use chunked stream, else use Content-Length for (bool useHttpOutput : trueFalse) { r.UseHttpOutput = useHttpOutput; @@ -367,7 +367,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { server.Stop(); } } - + Y_UNIT_TEST(TestReusePortEnabled) { if (!IsReusePortAvailable()) { return; // skip test @@ -423,38 +423,38 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } Y_UNIT_TEST(TestFailServer) { - /** - * Emulate request processing failures - * Data should be large enough not to fit into socket buffer - **/ + /** + * Emulate request processing failures + * Data should be large enough not to fit into socket buffer + **/ TString res = TestData(10 * 1024 * 1024); TPortManager portManager; const ui16 port = portManager.GetPort(); - TEchoServer serverImpl(res); - THttpServer::TOptions options(port); - options.EnableKeepAlive(true); - options.EnableCompression(true); + TEchoServer serverImpl(res); + THttpServer::TOptions options(port); + options.EnableKeepAlive(true); + options.EnableCompression(true); using TFailingServerMtpQueue = TThreadPoolBinder<TFailingMtpQueue, THttpServer::ICallBack>; THttpServer::TMtpQueueRef mainWorkers = new TFailingServerMtpQueue(&serverImpl, SystemThreadFactory()); THttpServer::TMtpQueueRef failWorkers = new TThreadPool(SystemThreadFactory()); - THttpServer server(&serverImpl, mainWorkers, failWorkers, options); - - UNIT_ASSERT(server.Start()); - for (size_t i = 0; i < 3; ++i) { - // should fail on 2nd request - static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); - TTestRequest r(port); - r.Content = res; - r.Type = "POST"; + THttpServer server(&serverImpl, mainWorkers, failWorkers, options); + + UNIT_ASSERT(server.Start()); + for (size_t i = 0; i < 3; ++i) { + // should fail on 2nd request + static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); + TTestRequest r(port); + r.Content = res; + r.Type = "POST"; TString resp = r.Execute(); - if (i == 1) { + if (i == 1) { UNIT_ASSERT(resp.Contains("Service Unavailable")); - } else { - UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); - } - } - server.Stop(); - } + } else { + UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); + } + } + server.Stop(); + } class TReleaseConnectionServer: public THttpServer::ICallBack { class TRequest: public THttpClientRequestEx { diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 6ff69defd7..38eda0e5e7 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -11,7 +11,7 @@ class THttpServerOptions { public: inline THttpServerOptions(ui16 port = 17000) noexcept - : Port(port) + : Port(port) { } @@ -146,8 +146,8 @@ public: typedef TVector<TAddr> TAddrs; - bool KeepAliveEnabled = true; - bool CompressionEnabled = false; + bool KeepAliveEnabled = true; + bool CompressionEnabled = false; bool RejectExcessConnections = false; bool ReusePort = false; // set SO_REUSEPORT socket option bool ReuseAddress = true; // set SO_REUSEADDR socket option @@ -157,10 +157,10 @@ public: const char* ServerName = "YWS/1.0"; // The Web server name to return in HTTP headers ui32 nThreads = 0; // Thread count for requests processing ui32 MaxQueueSize = 0; // Max allowed request count in queue - ui32 nFThreads = 1; - ui32 MaxFQueueSize = 0; - ui32 MaxConnections = 100; - int ListenBacklog = SOMAXCONN; + ui32 nFThreads = 1; + ui32 MaxFQueueSize = 0; + ui32 MaxConnections = 100; + int ListenBacklog = SOMAXCONN; TDuration ClientTimeout; size_t OutputBufferSize = 0; ui64 MaxInputContentLength = sizeof(size_t) <= 4 ? 2_GB : 64_GB; diff --git a/library/cpp/http/server/ya.make b/library/cpp/http/server/ya.make index a8cf9f2c0e..bae6f33306 100644 --- a/library/cpp/http/server/ya.make +++ b/library/cpp/http/server/ya.make @@ -2,8 +2,8 @@ LIBRARY() OWNER( pg - mvel - kulikov + mvel + kulikov g:base g:middle ) diff --git a/library/cpp/ipv6_address/ipv6_address.cpp b/library/cpp/ipv6_address/ipv6_address.cpp index 24f3bde65d..be8fcbae13 100644 --- a/library/cpp/ipv6_address/ipv6_address.cpp +++ b/library/cpp/ipv6_address/ipv6_address.cpp @@ -9,7 +9,7 @@ #include <util/network/init.h> #include <util/string/cast.h> #include <util/string/split.h> -#include <util/system/byteorder.h> +#include <util/system/byteorder.h> #include <util/ysaveload.h> #include <array> diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp index e9e9953551..cd31afa0b8 100644 --- a/library/cpp/json/ut/json_reader_ut.cpp +++ b/library/cpp/json/ut/json_reader_ut.cpp @@ -372,17 +372,17 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT_EXCEPTION(ReadJsonTree(&in, &value, true), TJsonException); } } - + Y_UNIT_TEST(TJsonMemoryLeakTest) { - // after https://clubs.at.yandex-team.ru/stackoverflow/3691 + // after https://clubs.at.yandex-team.ru/stackoverflow/3691 TString s = "."; - NJson::TJsonValue json; - try { - TStringInput in(s); - NJson::ReadJsonTree(&in, &json, true); - } catch (...) { - } - } // TJsonMemoryLeakTest + NJson::TJsonValue json; + try { + TStringInput in(s); + NJson::ReadJsonTree(&in, &json, true); + } catch (...) { + } + } // TJsonMemoryLeakTest Y_UNIT_TEST(TJsonDuplicateKeysWithNullValuesTest) { const TString json = "{\"\":null,\"\":\"\"}"; diff --git a/library/cpp/json/writer/ya.make b/library/cpp/json/writer/ya.make index 2c4a9757cb..3989ff3504 100644 --- a/library/cpp/json/writer/ya.make +++ b/library/cpp/json/writer/ya.make @@ -8,7 +8,7 @@ OWNER( PEERDIR( library/cpp/json/common -) +) SRCS( json_value.cpp diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index b18cccc6c8..fd2a906d6f 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -1871,11 +1871,11 @@ static const char* LFAlloc_GetParam(const char* param) { static Y_FORCE_INLINE int LFPosixMemalign(void** memptr, size_t alignment, size_t size) { if (Y_UNLIKELY(alignment > 4096)) { const char* error = "Larger alignment are not guaranteed with this implementation\n"; -#ifdef _win_ +#ifdef _win_ OutputDebugStringA(error); -#endif +#endif NMalloc::AbortFromCorruptedAllocator(error); - } + } size_t bigsize = size; if (bigsize <= alignment) { bigsize = alignment; diff --git a/library/cpp/logger/ya.make b/library/cpp/logger/ya.make index 1d0ba09257..00a5263cba 100644 --- a/library/cpp/logger/ya.make +++ b/library/cpp/logger/ya.make @@ -1,9 +1,9 @@ -OWNER( - pg - mvel +OWNER( + pg + mvel g:util g:base -) +) LIBRARY() diff --git a/library/cpp/messagebus/misc/tokenquota.h b/library/cpp/messagebus/misc/tokenquota.h index 375bfa2130..190547fa54 100644 --- a/library/cpp/messagebus/misc/tokenquota.h +++ b/library/cpp/messagebus/misc/tokenquota.h @@ -21,9 +21,9 @@ namespace NBus { , Acquired(0) , WakeLev(wake < 1 ? Max<size_t>(1, tokens / 2) : 0) , Tokens_(tokens) - { + { Y_UNUSED(padd_); - } + } bool Acquire(TAtomic level = 1, bool force = false) { level = Max(TAtomicBase(level), TAtomicBase(1)); diff --git a/library/cpp/messagebus/network.cpp b/library/cpp/messagebus/network.cpp index de1998d257..304bedae5a 100644 --- a/library/cpp/messagebus/network.cpp +++ b/library/cpp/messagebus/network.cpp @@ -125,7 +125,7 @@ std::pair<unsigned, TVector<TBindResult>> NBus::BindOnPort(int port, bool reuseP void NBus::NPrivate::SetSockOptTcpCork(SOCKET s, bool value) { #ifdef _linux_ CheckedSetSockOpt(s, IPPROTO_TCP, TCP_CORK, (int)value, "TCP_CORK"); -#else +#else Y_UNUSED(s); Y_UNUSED(value); #endif diff --git a/library/cpp/on_disk/chunks/reader.cpp b/library/cpp/on_disk/chunks/reader.cpp index ae54e844a9..6e28cbf367 100644 --- a/library/cpp/on_disk/chunks/reader.cpp +++ b/library/cpp/on_disk/chunks/reader.cpp @@ -12,11 +12,11 @@ static inline void ReadAux(const char* data, T* aux, T count, TVector<const char } } -TChunkedDataReader::TChunkedDataReader(const TBlob& blob) { +TChunkedDataReader::TChunkedDataReader(const TBlob& blob) { const char* cdata = blob.AsCharPtr(); const size_t size = blob.Size(); - Y_ENSURE(size >= sizeof(ui32), "Empty file with chunks. "); - + Y_ENSURE(size >= sizeof(ui32), "Empty file with chunks. "); + ui32 last = ReadUnaligned<ui32>((ui32*)(cdata + size) - 1); if (last != 0) { // old version file @@ -29,11 +29,11 @@ TChunkedDataReader::TChunkedDataReader(const TBlob& blob) { return; } - Y_ENSURE(size >= 3 * sizeof(ui64), "Blob size must be >= 3 * sizeof(ui64). "); - + Y_ENSURE(size >= 3 * sizeof(ui64), "Blob size must be >= 3 * sizeof(ui64). "); + ui64* aux = (ui64*)(cdata + size); Version = ReadUnaligned<ui64>(aux - 2); - Y_ENSURE(Version > 0, "Invalid chunked array version. "); + Y_ENSURE(Version > 0, "Invalid chunked array version. "); ui64 count = ReadUnaligned<ui64>(aux - 3); diff --git a/library/cpp/packedtypes/longs.h b/library/cpp/packedtypes/longs.h index 72a868c3f9..084098d705 100644 --- a/library/cpp/packedtypes/longs.h +++ b/library/cpp/packedtypes/longs.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/defaults.h> // _BIDSCLASS _EXPCLASS -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <util/system/unaligned_mem.h> #define PUT_8(x, buf, shift) WriteUnaligned<ui8>((buf)++, (x) >> (shift)) @@ -305,43 +305,43 @@ inline int out_long(const i32& longVal, char* ptrBuf) { inline int len_long(const i32& longVal) { return MY_32(longVal); } - -template <typename T, typename C> -inline const C* Unpack32(T& x, const C* src) { - int pkLen = 0; - const char* c = reinterpret_cast<const char*>(src); + +template <typename T, typename C> +inline const C* Unpack32(T& x, const C* src) { + int pkLen = 0; + const char* c = reinterpret_cast<const char*>(src); Y_UNUSED(pkLen); UNPACK_32(x, c, mem_traits, pkLen); Y_ASSERT(pkLen); - return reinterpret_cast<const C*>(c); -} - -template <typename T, typename C> -inline const C* Unpack64(T& x, const C* src) { - int pkLen = 0; - const char* c = reinterpret_cast<const char*>(src); + return reinterpret_cast<const C*>(c); +} + +template <typename T, typename C> +inline const C* Unpack64(T& x, const C* src) { + int pkLen = 0; + const char* c = reinterpret_cast<const char*>(src); Y_UNUSED(pkLen); - UNPACK_64(x, c, mem_traits, pkLen); + UNPACK_64(x, c, mem_traits, pkLen); Y_ASSERT(pkLen); - return reinterpret_cast<const C*>(c); -} - -template <typename T, typename C> -inline C* Pack32(const T& x, C* dest) { - int pkLen = 0; + return reinterpret_cast<const C*>(c); +} + +template <typename T, typename C> +inline C* Pack32(const T& x, C* dest) { + int pkLen = 0; Y_UNUSED(pkLen); - char* c = reinterpret_cast<char*>(dest); + char* c = reinterpret_cast<char*>(dest); PACK_32(x, c, mem_traits, pkLen); Y_ASSERT(pkLen); - return reinterpret_cast<C*>(c); -} - -template <typename T, typename C> -inline C* Pack64(const T& x, C* dest) { - int pkLen = 0; + return reinterpret_cast<C*>(c); +} + +template <typename T, typename C> +inline C* Pack64(const T& x, C* dest) { + int pkLen = 0; Y_UNUSED(pkLen); - char* c = reinterpret_cast<char*>(dest); - PACK_64(x, c, mem_traits, pkLen); + char* c = reinterpret_cast<char*>(dest); + PACK_64(x, c, mem_traits, pkLen); Y_ASSERT(pkLen); - return reinterpret_cast<C*>(c); -} + return reinterpret_cast<C*>(c); +} diff --git a/library/cpp/packedtypes/packed.h b/library/cpp/packedtypes/packed.h index 6628b5642d..88cff26ae2 100644 --- a/library/cpp/packedtypes/packed.h +++ b/library/cpp/packedtypes/packed.h @@ -69,7 +69,7 @@ void Y_FORCE_INLINE PackUI32(IOutputStream& out, ui32 v) { char buf[sizeof(ui32)]; char* bufPtr = buf; size_t size; - PACK_28(v, bufPtr, mem_traits, size); + PACK_28(v, bufPtr, mem_traits, size); out.Write(buf, size); } @@ -86,7 +86,7 @@ struct TInputStream2Traits<TZCMemoryInput> { template <class TStream> void Y_FORCE_INLINE UnPackUI32(TStream& in, ui32& v) { size_t size; - UNPACK_28(v, in, TInputStream2Traits<TStream>::TTraits, size); + UNPACK_28(v, in, TInputStream2Traits<TStream>::TTraits, size); (void)size; } diff --git a/library/cpp/packedtypes/packed_ut.cpp b/library/cpp/packedtypes/packed_ut.cpp index 9ddf0fe296..70a22cf9c3 100644 --- a/library/cpp/packedtypes/packed_ut.cpp +++ b/library/cpp/packedtypes/packed_ut.cpp @@ -2,51 +2,51 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/system/defaults.h> -#include <util/generic/ylimits.h> +#include <util/system/defaults.h> +#include <util/generic/ylimits.h> #include <util/generic/buffer.h> #include <util/stream/mem.h> #include <util/stream/buffer.h> -namespace NPrivate { +namespace NPrivate { #if 0 -static ui64 gSeed = 42; - -template<typename T> -static T PseudoRandom(T max = Max<T>()) { +static ui64 gSeed = 42; + +template<typename T> +static T PseudoRandom(T max = Max<T>()) { Y_ASSERT(max != 0); - // stupid and non-threadsafe, but very predictable chaos generator - gSeed += 1; - gSeed *= 419; - gSeed = gSeed ^ (ui64(max) << 17u); - return gSeed % max; -}; + // stupid and non-threadsafe, but very predictable chaos generator + gSeed += 1; + gSeed *= 419; + gSeed = gSeed ^ (ui64(max) << 17u); + return gSeed % max; +}; #endif } - + Y_UNIT_TEST_SUITE(TPackedTest) { void TestPackUi32Sub(ui32 v, const TVector<char>& p) { TBufferOutput out; PackUI32(out, v); const TBuffer& buf = out.Buffer(); - UNIT_ASSERT_VALUES_EQUAL(buf.Size(), p.size()); + UNIT_ASSERT_VALUES_EQUAL(buf.Size(), p.size()); UNIT_ASSERT(!memcmp(buf.Data(), &p[0], buf.Size())); { TBufferInput in(buf); ui32 v2; UnPackUI32(in, v2); - UNIT_ASSERT_VALUES_EQUAL(v, v2); + UNIT_ASSERT_VALUES_EQUAL(v, v2); } { TZCMemoryInput in(buf.Data(), buf.Size()); ui32 v2; UnPackUI32(in, v2); - UNIT_ASSERT_VALUES_EQUAL(v, v2); + UNIT_ASSERT_VALUES_EQUAL(v, v2); } } - + Y_UNIT_TEST(TestPackUi32) { ui32 v; TVector<char> pv; @@ -87,44 +87,44 @@ Y_UNIT_TEST_SUITE(TPackedTest) { #endif TestPackUi32Sub(v, pv); } - -#if 0 + +#if 0 Y_UNIT_TEST(ReadWrite32) { - TBuffer buffer(65536); - - char* writePtr = buffer.Data(); + TBuffer buffer(65536); + + char* writePtr = buffer.Data(); TVector<ui32> correctNumbers; - for (size_t i = 0; i < 1000; ++i) { - ui32 randNum = NPrivate::PseudoRandom<ui32>(); - correctNumbers.push_back(randNum); - writePtr = Pack32(randNum, writePtr); - } - - const char* readPtr = buffer.Data(); - for (size_t i = 0; i < correctNumbers.size(); ++i) { - ui32 value = 0xCCCCCCCC; - readPtr = Unpack32(value, readPtr); - UNIT_ASSERT_VALUES_EQUAL(value, correctNumbers[i]); - } - } - + for (size_t i = 0; i < 1000; ++i) { + ui32 randNum = NPrivate::PseudoRandom<ui32>(); + correctNumbers.push_back(randNum); + writePtr = Pack32(randNum, writePtr); + } + + const char* readPtr = buffer.Data(); + for (size_t i = 0; i < correctNumbers.size(); ++i) { + ui32 value = 0xCCCCCCCC; + readPtr = Unpack32(value, readPtr); + UNIT_ASSERT_VALUES_EQUAL(value, correctNumbers[i]); + } + } + Y_UNIT_TEST(ReadWrite64) { - TBuffer buffer(65536); - - char* writePtr = buffer.Data(); + TBuffer buffer(65536); + + char* writePtr = buffer.Data(); TVector<ui64> correctNumbers; - for (size_t i = 0; i < 1000; ++i) { - ui64 randNum = NPrivate::PseudoRandom<ui64>(); - correctNumbers.push_back(randNum); - writePtr = Pack64(randNum, writePtr); - } - - const char* readPtr = buffer.Data(); - for (size_t i = 0; i < correctNumbers.size(); ++i) { - ui64 value = 0xDEADBEEF; - readPtr = Unpack64(value, readPtr); - UNIT_ASSERT_VALUES_EQUAL(value, correctNumbers[i]); - } - } -#endif + for (size_t i = 0; i < 1000; ++i) { + ui64 randNum = NPrivate::PseudoRandom<ui64>(); + correctNumbers.push_back(randNum); + writePtr = Pack64(randNum, writePtr); + } + + const char* readPtr = buffer.Data(); + for (size_t i = 0; i < correctNumbers.size(); ++i) { + ui64 value = 0xDEADBEEF; + readPtr = Unpack64(value, readPtr); + UNIT_ASSERT_VALUES_EQUAL(value, correctNumbers[i]); + } + } +#endif }; diff --git a/library/cpp/streams/lz/lz.cpp b/library/cpp/streams/lz/lz.cpp index a94d5f1f23..b65bb3ed96 100644 --- a/library/cpp/streams/lz/lz.cpp +++ b/library/cpp/streams/lz/lz.cpp @@ -103,7 +103,7 @@ private: if (len) { const size_t out = this->Compress((const char*)ptr, len, (char*)Block(), this->AdditionalDataLength()); - // catch compressor buffer overrun (e.g. SEARCH-2043) + // catch compressor buffer overrun (e.g. SEARCH-2043) //Y_VERIFY(out <= this->Hint(this->BlockSize())); if (out < len || TCompressor::SaveIncompressibleChunks()) { @@ -377,9 +377,9 @@ public: } static inline size_t Hint(size_t len) noexcept { - // see SEARCH-2043 and, e.g. examples at - // http://stackoverflow.com/questions/4235019/how-to-get-lzo-to-work-with-a-file-stream - return len + (len / 16) + 64 + 3; + // see SEARCH-2043 and, e.g. examples at + // http://stackoverflow.com/questions/4235019/how-to-get-lzo-to-work-with-a-file-stream + return len + (len / 16) + 64 + 3; } static inline bool SaveIncompressibleChunks() noexcept { @@ -502,7 +502,7 @@ public: static const char signature[]; static inline size_t Hint(size_t len) noexcept { - return Max<size_t>(snappy::MaxCompressedLength(len), 100); + return Max<size_t>(snappy::MaxCompressedLength(len), 100); } inline size_t Compress(const char* data, size_t len, char* ptr, size_t /*dstMaxSize*/) { @@ -561,8 +561,8 @@ public: } inline bool SaveIncompressibleChunks() const noexcept { - // we must save incompressible chunks "as is" - // after compressor run in streaming mode + // we must save incompressible chunks "as is" + // after compressor run in streaming mode return Table_->Setting(3); } diff --git a/library/cpp/streams/lz/lz_ut.cpp b/library/cpp/streams/lz/lz_ut.cpp index b3ee24af7b..6876f070fc 100644 --- a/library/cpp/streams/lz/lz_ut.cpp +++ b/library/cpp/streams/lz/lz_ut.cpp @@ -4,75 +4,75 @@ #include <library/cpp/resource/resource.h> #include <util/stream/file.h> -#include <util/generic/vector.h> +#include <util/generic/vector.h> #include <util/system/tempfile.h> #include <util/generic/singleton.h> #define LDATA "./ldata" -#define LDATA_RANDOM "./ldata.random" +#define LDATA_RANDOM "./ldata.random" static const TString data = "aa aaa aa aaa aa aaa bb bbb bb bbb bb bbb"; namespace { - /** - * Produces well-formed random crap - **/ + /** + * Produces well-formed random crap + **/ TString RandomString(size_t size) { TString entropy(NResource::Find("/random.data")); TString result; - size_t seed = 1; - size_t j = 0; - for (size_t i = 0; i < size; ++i) { - seed *= 3; - char sym; - do { - sym = char((seed ^ i) % 256); - if (!sym) { - seed += 1; - } - } while (!sym); + size_t seed = 1; + size_t j = 0; + for (size_t i = 0; i < size; ++i) { + seed *= 3; + char sym; + do { + sym = char((seed ^ i) % 256); + if (!sym) { + seed += 1; + } + } while (!sym); Y_ASSERT(sym); j = (j + 1) % entropy.size(); - result += char(sym + entropy[j]); - } - return result; - } - + result += char(sym + entropy[j]); + } + return result; + } + TVector<TString> InitRandomData() { static const TVector<size_t> sizes = { - 0, - 1, - 127, - 2017, - 32767, - }; - + 0, + 1, + 127, + 2017, + 32767, + }; + TVector<TString> result; - for (auto size : sizes) { - result.push_back(RandomString(size)); - } + for (auto size : sizes) { + result.push_back(RandomString(size)); + } result.push_back(NResource::Find("/request.data")); - return result; - } - + return result; + } + TString TestFileName(const TString& d, size_t bufferSize) { return LDATA_RANDOM + TString(".") + ToString(d.size()) + TString(".") + ToString(bufferSize); - } - + } + struct TRandomData: public TVector<TString> { inline TRandomData() { InitRandomData().swap(*this); } }; } - + static const TVector<size_t> bufferSizes = { - 127, - 1024, - 32768, -}; - -namespace { + 127, + 1024, + 32768, +}; + +namespace { template <TLzqCompress::EVersion Ver, int Level, TLzqCompress::EMode Mode> struct TLzqCompressX: public TLzqCompress { inline TLzqCompressX(IOutputStream* out, size_t bufLen) @@ -83,7 +83,7 @@ namespace { } template <class C> -static inline void TestGoodDataCompress() { +static inline void TestGoodDataCompress() { TFixedBufferFileOutput o(LDATA); C c(&o, 1024); @@ -99,28 +99,28 @@ static inline void TestGoodDataCompress() { o.Finish(); } -template <class C> +template <class C> static inline void TestIncompressibleDataCompress(const TString& d, size_t bufferSize) { TString testFileName = TestFileName(d, bufferSize); TFixedBufferFileOutput o(testFileName); - C c(&o, bufferSize); + C c(&o, bufferSize); c.Write(d.data(), d.size()); - c.Finish(); - o.Finish(); -} - -template <class C> -static inline void TestCompress() { - TestGoodDataCompress<C>(); - for (auto bufferSize : bufferSizes) { + c.Finish(); + o.Finish(); +} + +template <class C> +static inline void TestCompress() { + TestGoodDataCompress<C>(); + for (auto bufferSize : bufferSizes) { for (auto rd : *Singleton<TRandomData>()) { - TestIncompressibleDataCompress<C>(rd, bufferSize); - } - } -} - + TestIncompressibleDataCompress<C>(rd, bufferSize); + } + } +} + template <class D> -static inline void TestGoodDataDecompress() { +static inline void TestGoodDataDecompress() { TTempFile tmpFile(LDATA); { @@ -137,29 +137,29 @@ static inline void TestGoodDataDecompress() { } } -template <class D> +template <class D> static inline void TestIncompressibleDataDecompress(const TString& d, size_t bufferSize) { TString testFileName = TestFileName(d, bufferSize); - TTempFile tmpFile(testFileName); - - { + TTempFile tmpFile(testFileName); + + { TFileInput i(testFileName); - D ld(&i); - - UNIT_ASSERT_EQUAL(ld.ReadAll(), d); - } -} - -template <class D> -static inline void TestDecompress() { - TestGoodDataDecompress<D>(); - for (auto bufferSize : bufferSizes) { + D ld(&i); + + UNIT_ASSERT_EQUAL(ld.ReadAll(), d); + } +} + +template <class D> +static inline void TestDecompress() { + TestGoodDataDecompress<D>(); + for (auto bufferSize : bufferSizes) { for (auto rd : *Singleton<TRandomData>()) { - TestIncompressibleDataDecompress<D>(rd, bufferSize); - } - } -} - + TestIncompressibleDataDecompress<D>(rd, bufferSize); + } + } +} + class TMixedDecompress: public IInputStream { public: TMixedDecompress(IInputStream* input) diff --git a/library/cpp/string_utils/scan/scan.h b/library/cpp/string_utils/scan/scan.h index fcadeee89c..703db54321 100644 --- a/library/cpp/string_utils/scan/scan.h +++ b/library/cpp/string_utils/scan/scan.h @@ -2,18 +2,18 @@ #include <util/generic/strbuf.h> -template <bool addAll, char sep, char sepKeyVal, class F> +template <bool addAll, char sep, char sepKeyVal, class F> static inline void ScanKeyValue(TStringBuf s, F&& f) { TStringBuf key, val; while (!s.empty()) { - val = s.NextTok(sep); + val = s.NextTok(sep); if (val.empty()) { continue; // && case } - key = val.NextTok(sepKeyVal); + key = val.NextTok(sepKeyVal); if (addAll || val.IsInited()) { f(key, val); // includes empty keys diff --git a/library/cpp/testing/unittest/checks.cpp b/library/cpp/testing/unittest/checks.cpp index ae63a1c064..c5712ae9d2 100644 --- a/library/cpp/testing/unittest/checks.cpp +++ b/library/cpp/testing/unittest/checks.cpp @@ -3,8 +3,8 @@ bool CheckExceptionMessage(const char* msg, TString& err) { static const char* badMsg[] = { - // ÐžÐ¿ÐµÑ€Ð°Ñ†Ð¸Ñ ÑƒÑпешно завершена [cp1251] - "\xce\xef\xe5\xf0\xe0\xf6\xe8\xff\x20\xf3\xf1\xef\xe5\xf8\xed\xee\x20\xe7\xe0\xe2\xe5\xf0\xf8\xe5\xed\xe0", + // ÐžÐ¿ÐµÑ€Ð°Ñ†Ð¸Ñ ÑƒÑпешно завершена [cp1251] + "\xce\xef\xe5\xf0\xe0\xf6\xe8\xff\x20\xf3\xf1\xef\xe5\xf8\xed\xee\x20\xe7\xe0\xe2\xe5\xf0\xf8\xe5\xed\xe0", "The operation completed successfully", "No error"}; diff --git a/library/cpp/threading/future/ya.make b/library/cpp/threading/future/ya.make index f96d746684..6591031f46 100644 --- a/library/cpp/threading/future/ya.make +++ b/library/cpp/threading/future/ya.make @@ -16,7 +16,7 @@ SRCS( ) END() - -RECURSE_FOR_TESTS( - mt_ut -) + +RECURSE_FOR_TESTS( + mt_ut +) diff --git a/library/cpp/unicode/normalization/ut/normalization_ut.cpp b/library/cpp/unicode/normalization/ut/normalization_ut.cpp index af46d981cd..54d4940a26 100644 --- a/library/cpp/unicode/normalization/ut/normalization_ut.cpp +++ b/library/cpp/unicode/normalization/ut/normalization_ut.cpp @@ -1,32 +1,32 @@ #include <library/cpp/testing/unittest/registar.h> - -#include <util/charset/wide.h> - + +#include <util/charset/wide.h> + #include <library/cpp/unicode/normalization/normalization.h> - + Y_UNIT_TEST_SUITE(TUnicodeNormalizationTest) { template <NUnicode::ENormalization NormType> - void TestInit() { - NUnicode::TNormalizer<NormType> normalizer; + void TestInit() { + NUnicode::TNormalizer<NormType> normalizer; TString s("упÑчка detected"); TUtf16String w; UTF8ToWide(s, w); - normalizer.Normalize(w); - } - + normalizer.Normalize(w); + } + Y_UNIT_TEST(TestInitNFD) { - TestInit<NUnicode::NFD>(); - } - + TestInit<NUnicode::NFD>(); + } + Y_UNIT_TEST(TestInitNFC) { - TestInit<NUnicode::NFC>(); - } - + TestInit<NUnicode::NFC>(); + } + Y_UNIT_TEST(TestInitNFKD) { - TestInit<NUnicode::NFKD>(); - } - + TestInit<NUnicode::NFKD>(); + } + Y_UNIT_TEST(TestInitNFKC) { - TestInit<NUnicode::NFKC>(); - } -} + TestInit<NUnicode::NFKC>(); + } +} diff --git a/library/cpp/unicode/normalization/ut/ya.make b/library/cpp/unicode/normalization/ut/ya.make index 7e12f1a2f6..a74372d9e1 100644 --- a/library/cpp/unicode/normalization/ut/ya.make +++ b/library/cpp/unicode/normalization/ut/ya.make @@ -1,13 +1,13 @@ -UNITTEST() - -OWNER(mvel) - -PEERDIR( +UNITTEST() + +OWNER(mvel) + +PEERDIR( library/cpp/unicode/normalization -) - -SRCS( - normalization_ut.cpp -) - -END() +) + +SRCS( + normalization_ut.cpp +) + +END() diff --git a/library/cpp/uri/ya.make b/library/cpp/uri/ya.make index 19aad4a320..8fc808a6af 100644 --- a/library/cpp/uri/ya.make +++ b/library/cpp/uri/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( - mvel +OWNER( + mvel g:base -) +) SRCS( assign.cpp diff --git a/library/python/ya.make b/library/python/ya.make index dc46d31c5d..2e1eb6e0e1 100644 --- a/library/python/ya.make +++ b/library/python/ya.make @@ -114,7 +114,7 @@ RECURSE( luigi/data luigi/example luigi/luigid_static - maths + maths messagebus metrics_framework mime_types diff --git a/tools/archiver/main.cpp b/tools/archiver/main.cpp index daf3b5cf28..6cda54c1ea 100644 --- a/tools/archiver/main.cpp +++ b/tools/archiver/main.cpp @@ -14,7 +14,7 @@ #include <util/string/escape.h> #include <util/string/hex.h> #include <util/string/subst.h> -#include <util/system/filemap.h> +#include <util/system/filemap.h> #include <cstring> @@ -54,7 +54,7 @@ namespace { class THexOutput: public IOutputStream { public: inline THexOutput(IOutputStream* slave) - : Slave_(slave) + : Slave_(slave) { } @@ -62,13 +62,13 @@ namespace { } inline IOutputStream* Slave() const noexcept { - return Slave_; + return Slave_; } private: void DoFinish() override { - Slave_->Write('\n'); - Slave_->Flush(); + Slave_->Write('\n'); + Slave_->Flush(); } void DoWrite(const void* data, size_t len) override { @@ -79,14 +79,14 @@ namespace { char buf[12]; char* tmp = buf; - if (Count_ % Columns == 0) { + if (Count_ % Columns == 0) { *tmp++ = ' '; *tmp++ = ' '; *tmp++ = ' '; *tmp++ = ' '; } - if (Count_ && Count_ % Columns != 0) { + if (Count_ && Count_ % Columns != 0) { *tmp++ = ','; *tmp++ = ' '; } @@ -95,41 +95,41 @@ namespace { *tmp++ = 'x'; tmp = HexEncode(&c, 1, tmp); - if ((Count_ % Columns) == (Columns - 1)) { + if ((Count_ % Columns) == (Columns - 1)) { *tmp++ = ','; *tmp++ = '\n'; } - Slave_->Write(buf, tmp - buf); + Slave_->Write(buf, tmp - buf); --len; ++b; - ++Count_; + ++Count_; } } private: // width in source chars - static const size_t Columns = 10; - ui64 Count_ = 0; + static const size_t Columns = 10; + ui64 Count_ = 0; IOutputStream* Slave_ = nullptr; }; struct TYasmOutput: public IOutputStream { inline TYasmOutput(IOutputStream* out, const TString& base) - : Out_(out) - , Base_(base) + : Out_(out) + , Base_(base) { - *Out_ << "global " << Base_ << "\n"; - *Out_ << "global " << Base_ << "Size\n\nSECTION .rodata\n\n"; - *Out_ << Base_ << ":\n"; + *Out_ << "global " << Base_ << "\n"; + *Out_ << "global " << Base_ << "Size\n\nSECTION .rodata\n\n"; + *Out_ << Base_ << ":\n"; } ~TYasmOutput() override { } void DoFinish() override { - *Out_ << Base_ << "Size:\ndd " << Count_ << '\n'; + *Out_ << Base_ << "Size:\ndd " << Count_ << '\n'; *Out_ << "%ifidn __OUTPUT_FORMAT__,elf64\n"; *Out_ << "size " << Base_ << " " << Count_ << "\n"; @@ -138,20 +138,20 @@ namespace { } void DoWrite(const void* data, size_t len) override { - Count_ += len; + Count_ += len; const unsigned char* p = (const unsigned char*)data; while (len) { const size_t step = Min<size_t>(len, 100); - *Out_ << "db " << (int)*p++; + *Out_ << "db " << (int)*p++; for (size_t i = 1; i < step; ++i) { - *Out_ << ',' << (int)*p++; + *Out_ << ',' << (int)*p++; } - *Out_ << '\n'; + *Out_ << '\n'; len -= step; } @@ -159,7 +159,7 @@ namespace { IOutputStream* Out_ = nullptr; const TString Base_; - ui64 Count_ = 0; + ui64 Count_ = 0; }; struct TCOutput: public THexOutput { @@ -331,9 +331,9 @@ static bool Quiet = false; static inline void Append(IOutputStream& w, const TString& fname, const TString& rname) { TMappedFileInput in(fname); - if (!Quiet) { + if (!Quiet) { Cerr << "--> " << rname << Endl; - } + } TransferData((IInputStream*)&in, &w); } @@ -343,9 +343,9 @@ static inline void Append(TDuplicatesMap& w, const TString& fname, const TString } static inline void Append(TDeduplicationArchiveWriter& w, const TString& fname, const TString& rname) { - if (!Quiet) { + if (!Quiet) { Cerr << "--> " << rname << Endl; - } + } if (const TString* rootRecordName = w.DuplicatesMap.Synonyms.FindPtr(rname)) { w.Writer.AddSynonym(*rootRecordName, rname); @@ -357,12 +357,12 @@ static inline void Append(TDeduplicationArchiveWriter& w, const TString& fname, namespace { struct TRec { - bool Recursive = false; + bool Recursive = false; TString Key; TString Path; TString Prefix; - TRec() = default; + TRec() = default; inline void Fix() { ::Fix(Path); @@ -422,29 +422,29 @@ static TString CutFirstSlash(const TString& fileName) { } } -struct TMappingReader { - TMemoryMap Map; - TBlob Blob; - TArchiveReader Reader; - +struct TMappingReader { + TMemoryMap Map; + TBlob Blob; + TArchiveReader Reader; + TMappingReader(const TString& archive) - : Map(archive) - , Blob(TBlob::FromMemoryMapSingleThreaded(Map, 0, Map.Length())) - , Reader(Blob) - { - } -}; - + : Map(archive) + , Blob(TBlob::FromMemoryMapSingleThreaded(Map, 0, Map.Length())) + , Reader(Blob) + { + } +}; + static void UnpackArchive(const TString& archive, const TFsPath& dir = TFsPath()) { - TMappingReader mappingReader(archive); - const TArchiveReader& reader = mappingReader.Reader; + TMappingReader mappingReader(archive); + const TArchiveReader& reader = mappingReader.Reader; const size_t count = reader.Count(); for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); const TString fileName = CutFirstSlash(key); - if (!Quiet) { + if (!Quiet) { Cerr << archive << " --> " << fileName << Endl; - } + } const TFsPath path(dir / fileName); path.Parent().MkDirs(); TAutoPtr<IInputStream> in = reader.ObjectByKey(key); @@ -455,8 +455,8 @@ static void UnpackArchive(const TString& archive, const TFsPath& dir = TFsPath() } static void ListArchive(const TString& archive, bool cutSlash) { - TMappingReader mappingReader(archive); - const TArchiveReader& reader = mappingReader.Reader; + TMappingReader mappingReader(archive); + const TArchiveReader& reader = mappingReader.Reader; const size_t count = reader.Count(); for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); @@ -469,8 +469,8 @@ static void ListArchive(const TString& archive, bool cutSlash) { } static void ListArchiveMd5(const TString& archive, bool cutSlash) { - TMappingReader mappingReader(archive); - const TArchiveReader& reader = mappingReader.Reader; + TMappingReader mappingReader(archive); + const TArchiveReader& reader = mappingReader.Reader; const size_t count = reader.Count(); for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); @@ -484,125 +484,125 @@ static void ListArchiveMd5(const TString& archive, bool cutSlash) { } int main(int argc, char** argv) { - NLastGetopt::TOpts opts; - opts.AddHelpOption('?'); - opts.SetTitle( - "Archiver\n" + NLastGetopt::TOpts opts; + opts.AddHelpOption('?'); + opts.SetTitle( + "Archiver\n" "Docs: https://wiki.yandex-team.ru/Development/Poisk/arcadia/tools/archiver" - ); - - bool hexdump = false; - opts.AddLongOption('x', "hexdump", "Produce hexdump") - .NoArgument() - .Optional() - .StoreValue(&hexdump, true); - - size_t stride = 0; - opts.AddLongOption('s', "segments", "Produce segmented C strings array of given size") - .RequiredArgument("<size>") - .Optional() - .DefaultValue("0") - .StoreResult(&stride); - - bool cat = false; - opts.AddLongOption('c', "cat", "Do not store keys (file names), just cat uncompressed files") - .NoArgument() - .Optional() - .StoreValue(&cat, true); - - bool doNotZip = false; - opts.AddLongOption('p', "plain", "Do not use compression") - .NoArgument() - .Optional() - .StoreValue(&doNotZip, true); - + ); + + bool hexdump = false; + opts.AddLongOption('x', "hexdump", "Produce hexdump") + .NoArgument() + .Optional() + .StoreValue(&hexdump, true); + + size_t stride = 0; + opts.AddLongOption('s', "segments", "Produce segmented C strings array of given size") + .RequiredArgument("<size>") + .Optional() + .DefaultValue("0") + .StoreResult(&stride); + + bool cat = false; + opts.AddLongOption('c', "cat", "Do not store keys (file names), just cat uncompressed files") + .NoArgument() + .Optional() + .StoreValue(&cat, true); + + bool doNotZip = false; + opts.AddLongOption('p', "plain", "Do not use compression") + .NoArgument() + .Optional() + .StoreValue(&doNotZip, true); + bool deduplicate = false; opts.AddLongOption("deduplicate", "Turn on file-wise deduplication") .NoArgument() .Optional() .StoreValue(&deduplicate, true); - bool unpack = false; - opts.AddLongOption('u', "unpack", "Unpack archive into current directory") - .NoArgument() - .Optional() - .StoreValue(&unpack, true); - - bool list = false; - opts.AddLongOption('l', "list", "List files in archive") - .NoArgument() - .Optional() - .StoreValue(&list, true); - + bool unpack = false; + opts.AddLongOption('u', "unpack", "Unpack archive into current directory") + .NoArgument() + .Optional() + .StoreValue(&unpack, true); + + bool list = false; + opts.AddLongOption('l', "list", "List files in archive") + .NoArgument() + .Optional() + .StoreValue(&list, true); + bool cutSlash = true; opts.AddLongOption("as-is", "somewhy slash is cutted by default in list; with this option key will be shown as-is") .NoArgument() .Optional() .StoreValue(&cutSlash, false); - bool listMd5 = false; - opts.AddLongOption('m', "md5", "List files in archive with MD5 sums") - .NoArgument() - .Optional() - .StoreValue(&listMd5, true); - - bool recursive = false; - opts.AddLongOption('r', "recursive", "Read all files under each directory, recursively") - .NoArgument() - .Optional() - .StoreValue(&recursive, true); - - Quiet = false; - opts.AddLongOption('q', "quiet", "Do not output progress to stderr") - .NoArgument() - .Optional() - .StoreValue(&Quiet, true); - + bool listMd5 = false; + opts.AddLongOption('m', "md5", "List files in archive with MD5 sums") + .NoArgument() + .Optional() + .StoreValue(&listMd5, true); + + bool recursive = false; + opts.AddLongOption('r', "recursive", "Read all files under each directory, recursively") + .NoArgument() + .Optional() + .StoreValue(&recursive, true); + + Quiet = false; + opts.AddLongOption('q', "quiet", "Do not output progress to stderr") + .NoArgument() + .Optional() + .StoreValue(&Quiet, true); + TString prepend; - opts.AddLongOption('z', "prepend", "Prepend string to output") - .RequiredArgument("<prefix>") - .StoreResult(&prepend); - + opts.AddLongOption('z', "prepend", "Prepend string to output") + .RequiredArgument("<prefix>") + .StoreResult(&prepend); + TString append; - opts.AddLongOption('a', "append", "Append string to output") - .RequiredArgument("<suffix>") - .StoreResult(&append); - + opts.AddLongOption('a', "append", "Append string to output") + .RequiredArgument("<suffix>") + .StoreResult(&append); + TString outputf; - opts.AddLongOption('o', "output", "Output to file instead stdout") - .RequiredArgument("<file>") - .StoreResult(&outputf); - + opts.AddLongOption('o', "output", "Output to file instead stdout") + .RequiredArgument("<file>") + .StoreResult(&outputf); + TString unpackDir; - opts.AddLongOption('d', "unpackdir", "Unpack destination directory") - .RequiredArgument("<dir>") - .DefaultValue(".") - .StoreResult(&unpackDir); - + opts.AddLongOption('d', "unpackdir", "Unpack destination directory") + .RequiredArgument("<dir>") + .DefaultValue(".") + .StoreResult(&unpackDir); + TString yasmBase; - opts.AddLongOption('A', "yasm", "Output dump is yasm format") - .RequiredArgument("<base>") - .StoreResult(&yasmBase); - + opts.AddLongOption('A', "yasm", "Output dump is yasm format") + .RequiredArgument("<base>") + .StoreResult(&yasmBase); + TString cppBase; - opts.AddLongOption('C', "cpp", "Output dump is C/C++ format") - .RequiredArgument("<base>") - .StoreResult(&cppBase); - + opts.AddLongOption('C', "cpp", "Output dump is C/C++ format") + .RequiredArgument("<base>") + .StoreResult(&cppBase); + TString forceKeys; opts.AddLongOption('k', "keys", "Set explicit list of keys for elements") .RequiredArgument("<keys>") .StoreResult(&forceKeys); - opts.SetFreeArgDefaultTitle("<file>"); - opts.SetFreeArgsMin(1); - NLastGetopt::TOptsParseResult optsRes(&opts, argc, argv); - + opts.SetFreeArgDefaultTitle("<file>"); + opts.SetFreeArgsMin(1); + NLastGetopt::TOptsParseResult optsRes(&opts, argc, argv); + SubstGlobal(append, "\\n", "\n"); SubstGlobal(prepend, "\\n", "\n"); TVector<TRec> recs; - const auto& files = optsRes.GetFreeArgs(); + const auto& files = optsRes.GetFreeArgs(); TVector<TStringBuf> keys; if (forceKeys.size()) diff --git a/tools/archiver/tests/directory/file1 b/tools/archiver/tests/directory/file1 index ac9b5ed12b..e2129701f1 100644 --- a/tools/archiver/tests/directory/file1 +++ b/tools/archiver/tests/directory/file1 @@ -1 +1 @@ -file1 +file1 diff --git a/tools/archiver/tests/directory/file2 b/tools/archiver/tests/directory/file2 index c253e57a47..6c493ff740 100644 --- a/tools/archiver/tests/directory/file2 +++ b/tools/archiver/tests/directory/file2 @@ -1 +1 @@ -file2 +file2 diff --git a/tools/archiver/tests/test.py b/tools/archiver/tests/test.py index 9a8a9c4e14..b92d58f6a9 100644 --- a/tools/archiver/tests/test.py +++ b/tools/archiver/tests/test.py @@ -1,41 +1,41 @@ -import os -import logging -from yatest import common as ytc - -logger = logging.getLogger("test_logger") - - -class TestArchiver(object): - @classmethod - def setup_class(cls): +import os +import logging +from yatest import common as ytc + +logger = logging.getLogger("test_logger") + + +class TestArchiver(object): + @classmethod + def setup_class(cls): cls.archiver_path = ytc.binary_path("tools/archiver/archiver") - - def test_recursive(self): - assert 'archiver' == os.path.basename(self.archiver_path) - assert os.path.exists(self.archiver_path) - contents = ytc.source_path("tools/archiver/tests/directory") - ytc.execute( - command=[ - self.archiver_path, - "--output", "archive", - "--recursive", - contents, - ] - ) - with open('result', 'w') as archive_list: - ytc.execute( - command=[ - self.archiver_path, - "--list", - "archive", - ], - stdout=archive_list, - stderr=None, - ) - archive_list = sorted(open('result').read().strip().split('\n')) + + def test_recursive(self): + assert 'archiver' == os.path.basename(self.archiver_path) + assert os.path.exists(self.archiver_path) + contents = ytc.source_path("tools/archiver/tests/directory") + ytc.execute( + command=[ + self.archiver_path, + "--output", "archive", + "--recursive", + contents, + ] + ) + with open('result', 'w') as archive_list: + ytc.execute( + command=[ + self.archiver_path, + "--list", + "archive", + ], + stdout=archive_list, + stderr=None, + ) + archive_list = sorted(open('result').read().strip().split('\n')) assert len(archive_list) == 3 - assert archive_list[0] == 'file1' - assert archive_list[1] == 'file2' + assert archive_list[0] == 'file1' + assert archive_list[1] == 'file2' assert archive_list[2] == 'file3' def test_deduplicate(self): diff --git a/tools/archiver/tests/ya.make b/tools/archiver/tests/ya.make index 76b276aa12..445b4d3e70 100644 --- a/tools/archiver/tests/ya.make +++ b/tools/archiver/tests/ya.make @@ -1,9 +1,9 @@ OWNER(mvel) - + PY2TEST() - + TEST_SRCS(test.py) - + DATA(arcadia/tools/archiver/tests) DEPENDS(tools/archiver) diff --git a/tools/archiver/ya.make b/tools/archiver/ya.make index 07aac3a635..757378c1b3 100644 --- a/tools/archiver/ya.make +++ b/tools/archiver/ya.make @@ -1,9 +1,9 @@ PROGRAM() -OWNER( - pg - mvel -) +OWNER( + pg + mvel +) PEERDIR( library/cpp/archive diff --git a/tools/enum_parser/enum_parser/main.cpp b/tools/enum_parser/enum_parser/main.cpp index fca1161b6e..0943c69c1d 100644 --- a/tools/enum_parser/enum_parser/main.cpp +++ b/tools/enum_parser/enum_parser/main.cpp @@ -1,42 +1,42 @@ #include <library/cpp/json/writer/json_value.h> #include <library/cpp/json/writer/json.h> #include <library/cpp/getopt/small/last_getopt.h> - -#include <tools/enum_parser/parse_enum/parse_enum.h> - -#include <util/stream/file.h> -#include <util/stream/output.h> -#include <util/stream/input.h> -#include <util/stream/mem.h> - -#include <util/charset/wide.h> + +#include <tools/enum_parser/parse_enum/parse_enum.h> + +#include <util/stream/file.h> +#include <util/stream/output.h> +#include <util/stream/input.h> +#include <util/stream/mem.h> + +#include <util/charset/wide.h> #include <util/string/builder.h> -#include <util/string/strip.h> -#include <util/string/cast.h> +#include <util/string/strip.h> +#include <util/string/cast.h> #include <util/string/join.h> -#include <util/string/subst.h> -#include <util/generic/map.h> +#include <util/string/subst.h> +#include <util/generic/map.h> #include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/generic/ptr.h> -#include <util/generic/yexception.h> -#include <util/generic/maybe.h> -#include <util/system/fs.h> -#include <util/folder/path.h> - +#include <util/generic/vector.h> +#include <util/generic/ptr.h> +#include <util/generic/yexception.h> +#include <util/generic/maybe.h> +#include <util/system/fs.h> +#include <util/folder/path.h> + void WriteHeader(const TString& headerName, IOutputStream& out, IOutputStream* headerOutPtr = nullptr) { - out << "// This file was auto-generated. Do not edit!!!\n"; + out << "// This file was auto-generated. Do not edit!!!\n"; out << "#include " << headerName << "\n"; out << "#include <tools/enum_parser/enum_serialization_runtime/enum_runtime.h>\n\n"; out << "#include <tools/enum_parser/enum_parser/stdlib_deps.h>\n\n"; - out << "#include <util/generic/typetraits.h>\n"; - out << "#include <util/generic/singleton.h>\n"; + out << "#include <util/generic/typetraits.h>\n"; + out << "#include <util/generic/singleton.h>\n"; out << "#include <util/generic/string.h>\n"; out << "#include <util/generic/vector.h>\n"; - out << "#include <util/generic/map.h>\n"; + out << "#include <util/generic/map.h>\n"; out << "#include <util/generic/serialized_enum.h>\n"; - out << "#include <util/string/cast.h>\n"; - out << "#include <util/stream/output.h>\n\n"; + out << "#include <util/string/cast.h>\n"; + out << "#include <util/stream/output.h>\n\n"; if (headerOutPtr) { auto& outHeader = *headerOutPtr; @@ -45,182 +45,182 @@ void WriteHeader(const TString& headerName, IOutputStream& out, IOutputStream* h outHeader << "#include <util/generic/serialized_enum.h>\n"; outHeader << "#include " << headerName << "\n"; } -} - +} + static inline void JsonEscape(TString& s) { - SubstGlobal(s, "\\", "\\\\"); - SubstGlobal(s, "\"", "\\\""); - SubstGlobal(s, "\r", "\\r"); - SubstGlobal(s, "\n", "\\n"); - SubstGlobal(s, "\t", "\\t"); -} - + SubstGlobal(s, "\\", "\\\\"); + SubstGlobal(s, "\"", "\\\""); + SubstGlobal(s, "\r", "\\r"); + SubstGlobal(s, "\n", "\\n"); + SubstGlobal(s, "\t", "\\t"); +} + static inline TString JsonQuote(const TString& s) { TString quoted = s; - JsonEscape(quoted); - return "\"" + quoted + "\""; // do not use .Quote() here, it performs escaping! -} - - -/// Simplifed JSON map encoder for generic types -template<typename T> + JsonEscape(quoted); + return "\"" + quoted + "\""; // do not use .Quote() here, it performs escaping! +} + + +/// Simplifed JSON map encoder for generic types +template<typename T> void OutKey(IOutputStream& out, const TString& key, const T& value, bool escape = true) { TString quoted = ToString(value); - if (escape) { - quoted = JsonQuote(quoted); - } - out << "\"" << key << "\": " << quoted << ",\n"; -} - -/// Simplifed JSON map encoder for TMaybe + if (escape) { + quoted = JsonQuote(quoted); + } + out << "\"" << key << "\": " << quoted << ",\n"; +} + +/// Simplifed JSON map encoder for TMaybe void OutKey(IOutputStream& out, const TString& key, const TMaybe<TString>& value) { TString quoted; - if (value) { - quoted = JsonQuote(ToString(*value)); - } else { - quoted = "null"; - } - out << "\"" << key << "\": " << quoted << ",\n"; -} - - -/// Simplifed JSON map encoder for bool values + if (value) { + quoted = JsonQuote(ToString(*value)); + } else { + quoted = "null"; + } + out << "\"" << key << "\": " << quoted << ",\n"; +} + + +/// Simplifed JSON map encoder for bool values void OutKey(IOutputStream& out, const TString& key, const bool& value) { - out << "\"" << key << "\": " << (value ? "true" : "false") << ",\n"; -} - - -/// Simplifed JSON map encoder for array items -template<typename T> + out << "\"" << key << "\": " << (value ? "true" : "false") << ",\n"; +} + + +/// Simplifed JSON map encoder for array items +template<typename T> void OutItem(IOutputStream& out, const T& value, bool escape = true) { TString quoted = ToString(value); - if (escape) { - quoted = JsonQuote(quoted); - } - out << quoted << ",\n"; -} - -/// Cut trailing ",\n" or "," -static inline void FinishItems(TStringStream& out) { + if (escape) { + quoted = JsonQuote(quoted); + } + out << quoted << ",\n"; +} + +/// Cut trailing ",\n" or "," +static inline void FinishItems(TStringStream& out) { TString& s = out.Str(); - if (s.EndsWith(",\n")) { + if (s.EndsWith(",\n")) { s.remove(s.size() - 2, 2); - } - if (s.EndsWith(",")) { - s.pop_back(); - } -} - - -static inline void OpenMap(TStringStream& out) { - out << "{\n"; -} - -static inline void CloseMap(TStringStream& out) { - out << "}\n"; -} - -static inline void OpenArray(TStringStream& out) { - out << "[\n"; -} - -static inline void CloseArray(TStringStream& out) { - out << "]\n"; -} - + } + if (s.EndsWith(",")) { + s.pop_back(); + } +} + + +static inline void OpenMap(TStringStream& out) { + out << "{\n"; +} + +static inline void CloseMap(TStringStream& out) { + out << "}\n"; +} + +static inline void OpenArray(TStringStream& out) { + out << "[\n"; +} + +static inline void CloseArray(TStringStream& out) { + out << "]\n"; +} + static TString WrapStringBuf(const TStringBuf str) { return TString::Join("TStringBuf(\"", str, "\")"); } -void GenerateEnum( - const TEnumParser::TEnum& en, +void GenerateEnum( + const TEnumParser::TEnum& en, IOutputStream& out, IOutputStream* jsonEnumOut = nullptr, IOutputStream* headerOutPtr = nullptr -) { - TStringStream jEnum; - OpenMap(jEnum); - +) { + TStringStream jEnum; + OpenMap(jEnum); + size_t count = en.Items.size(); - OutKey(jEnum, "count", count); + OutKey(jEnum, "count", count); const TString name = TEnumParser::ScopeStr(en.Scope) + en.CppName; - OutKey(jEnum, "full_name", name); - OutKey(jEnum, "cpp_name", en.CppName); - TStringStream scopeJson; - OpenArray(scopeJson); - for (const auto& scopeItem : en.Scope) { - OutItem(scopeJson, scopeItem); - } - FinishItems(scopeJson); - CloseArray(scopeJson); - - OutKey(jEnum, "scope", scopeJson.Str(), false); - OutKey(jEnum, "enum_class", en.EnumClass); - - TEnumParser::TScope outerScope = en.Scope; - if (en.EnumClass) { - outerScope.push_back(en.CppName); - } - + OutKey(jEnum, "full_name", name); + OutKey(jEnum, "cpp_name", en.CppName); + TStringStream scopeJson; + OpenArray(scopeJson); + for (const auto& scopeItem : en.Scope) { + OutItem(scopeJson, scopeItem); + } + FinishItems(scopeJson); + CloseArray(scopeJson); + + OutKey(jEnum, "scope", scopeJson.Str(), false); + OutKey(jEnum, "enum_class", en.EnumClass); + + TEnumParser::TScope outerScope = en.Scope; + if (en.EnumClass) { + outerScope.push_back(en.CppName); + } + TString outerScopeStr = TEnumParser::ScopeStr(outerScope); - + TString cName = name; - SubstGlobal(cName, "::", ""); - - out << "// I/O for " << name << "\n"; - + SubstGlobal(cName, "::", ""); + + out << "// I/O for " << name << "\n"; + TString nsName = "N" + cName + "Private"; - - out << "namespace { namespace " << nsName << " {\n"; - + + out << "namespace { namespace " << nsName << " {\n"; + TVector<TString> nameInitializerPairs; TVector<TString> valueInitializerPairs; TVector<TString> cppNamesInitializer; - - TStringStream jItems; - OpenArray(jItems); - - for (const auto& it : en.Items) { - TStringStream jEnumItem; - OpenMap(jEnumItem); - - OutKey(jEnumItem, "cpp_name", it.CppName); - OutKey(jEnumItem, "value", it.Value); - OutKey(jEnumItem, "comment_text", it.CommentText); - - TStringStream jAliases; - OpenArray(jAliases); - + + TStringStream jItems; + OpenArray(jItems); + + for (const auto& it : en.Items) { + TStringStream jEnumItem; + OpenMap(jEnumItem); + + OutKey(jEnumItem, "cpp_name", it.CppName); + OutKey(jEnumItem, "value", it.Value); + OutKey(jEnumItem, "comment_text", it.CommentText); + + TStringStream jAliases; + OpenArray(jAliases); + TString strValue = it.CppName; - if (it.Aliases) { - // first alias is main - strValue = it.Aliases[0]; - OutKey(jEnumItem, "str_value", strValue); - } + if (it.Aliases) { + // first alias is main + strValue = it.Aliases[0]; + OutKey(jEnumItem, "str_value", strValue); + } nameInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(strValue) + ")"); cppNamesInitializer.push_back(WrapStringBuf(it.CppName)); - - for (const auto& alias : it.Aliases) { + + for (const auto& alias : it.Aliases) { valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(alias) + ")"); - OutItem(jAliases, alias); - } - FinishItems(jAliases); - CloseArray(jAliases); - - if (!it.Aliases) { + OutItem(jAliases, alias); + } + FinishItems(jAliases); + CloseArray(jAliases); + + if (!it.Aliases) { valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(it.CppName) + ")"); - } - OutKey(jEnumItem, "aliases", jAliases.Str(), false); - - FinishItems(jEnumItem); - CloseMap(jEnumItem); - - OutItem(jItems, jEnumItem.Str(), false); - } - FinishItems(jItems); - CloseArray(jItems); - OutKey(jEnum, "items", jItems.Str(), false); - + } + OutKey(jEnumItem, "aliases", jAliases.Str(), false); + + FinishItems(jEnumItem); + CloseMap(jEnumItem); + + OutItem(jItems, jEnumItem.Str(), false); + } + FinishItems(jItems); + CloseArray(jItems); + OutKey(jEnum, "items", jItems.Str(), false); + auto defineConstArray = [&out, payloadCache = TMap<std::pair<TString, TVector<TString>>, TString>()](const TStringBuf indent, const TStringBuf elementType, const TStringBuf name, const TVector<TString>& items) mutable { if (items.empty()) { // ISO C++ forbids zero-size array out << indent << "static constexpr const TArrayRef<const " << elementType << "> " << name << ";\n"; @@ -244,7 +244,7 @@ void GenerateEnum( out << " public:\n"; out << " using TBase = ::NEnumSerializationRuntime::TEnumDescription<" << name << ">;\n\n"; out << " inline TNameBufs();\n\n"; - + // Instance out << " static inline const TNameBufs& Instance() {\n"; out << " return *SingletonWithPriority<TNameBufs, 0>();\n"; // destroy enum serializers last, because it may be used from destructor of another global object @@ -269,60 +269,60 @@ void GenerateEnum( out << " : TBase(ENUM_INITIALIZATION_DATA)\n"; out << " {\n"; out << " }\n\n"; - - out << "}}\n\n"; - + + out << "}}\n\n"; + if (headerOutPtr) { (*headerOutPtr) << "// I/O for " << name << "\n"; } - // outer ToString + // outer ToString if (headerOutPtr) { (*headerOutPtr) << "const TString& ToString(" << name << ");\n"; } out << "const TString& ToString(" << name << " x) {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.ToString(x);\n"; - out << "}\n\n"; - - // outer FromString + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.ToString(x);\n"; + out << "}\n\n"; + + // outer FromString if (headerOutPtr) { (*headerOutPtr) << "bool FromString(const TString& name, " << name << "& ret);\n"; } out << "bool FromString(const TString& name, " << name << "& ret) {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.FromString(name, ret);\n"; - out << "}\n\n"; - - // outer FromString + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.FromString(name, ret);\n"; + out << "}\n\n"; + + // outer FromString if (headerOutPtr) { (*headerOutPtr) << "bool FromString(const TStringBuf& name, " << name << "& ret);\n"; } - out << "bool FromString(const TStringBuf& name, " << name << "& ret) {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.FromString(name, ret);\n"; - out << "}\n\n"; - - // specialization for internal FromStringImpl - out << "template<>\n"; - out << name << " FromStringImpl<" << name << ">(const char* data, size_t len) {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.FromString(TStringBuf(data, len));\n"; - out << "}\n\n"; - - // specialization for internal TryFromStringImpl - out << "template<>\n"; - out << "bool TryFromStringImpl<" << name << ">(const char* data, size_t len, " << name << "& result) {\n"; - out << " return FromString(TStringBuf(data, len), result);\n"; - out << "}\n\n"; - - // outer Out - out << "template<>\n"; + out << "bool FromString(const TStringBuf& name, " << name << "& ret) {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.FromString(name, ret);\n"; + out << "}\n\n"; + + // specialization for internal FromStringImpl + out << "template<>\n"; + out << name << " FromStringImpl<" << name << ">(const char* data, size_t len) {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.FromString(TStringBuf(data, len));\n"; + out << "}\n\n"; + + // specialization for internal TryFromStringImpl + out << "template<>\n"; + out << "bool TryFromStringImpl<" << name << ">(const char* data, size_t len, " << name << "& result) {\n"; + out << " return FromString(TStringBuf(data, len), result);\n"; + out << "}\n\n"; + + // outer Out + out << "template<>\n"; out << "void Out<" << name << ">(IOutputStream& os, TTypeTraits<" << name << ">::TFuncParam n) {\n"; out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; out << " return names.Out(&os, n);\n"; - out << "}\n\n"; - + out << "}\n\n"; + // specializations for NEnumSerializationRuntime function family out << "namespace NEnumSerializationRuntime {\n"; // template<> GetEnumAllValues @@ -338,7 +338,7 @@ void GenerateEnum( out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; out << " return names.AllEnumNames();\n"; out << " }\n\n"; - + // template<> GetEnumNames<EnumType> out << " template<>\n"; out << " TMappedDictView<" << name << ", TString> GetEnumNamesImpl<" << name << ">() {\n"; @@ -353,8 +353,8 @@ void GenerateEnum( out << " return names.AllEnumCppNames();\n"; out << " }\n"; - out << "}\n\n"; - + out << "}\n\n"; + if (headerOutPtr) { // <EnumType>Count auto& outHeader = *headerOutPtr; @@ -363,30 +363,30 @@ void GenerateEnum( outHeader << " return " << en.Items.size() << ";\n"; outHeader << "}\n"; } - - FinishItems(jEnum); - jEnum << "}\n"; - - if (jsonEnumOut) { - *jsonEnumOut << jEnum.Str(); - } -} - -int main(int argc, char** argv) { - try { - using namespace NLastGetopt; - TOpts opts = NLastGetopt::TOpts::Default(); - opts.AddHelpOption(); - + + FinishItems(jEnum); + jEnum << "}\n"; + + if (jsonEnumOut) { + *jsonEnumOut << jEnum.Str(); + } +} + +int main(int argc, char** argv) { + try { + using namespace NLastGetopt; + TOpts opts = NLastGetopt::TOpts::Default(); + opts.AddHelpOption(); + TString outputFileName; TString outputHeaderFileName; TString outputJsonFileName; TString includePath; - opts.AddLongOption('o', "output").OptionalArgument("<output-file>").StoreResult(&outputFileName) - .Help( - "Output generated code to specified file.\n" - "When not set, standard output is used." - ); + opts.AddLongOption('o', "output").OptionalArgument("<output-file>").StoreResult(&outputFileName) + .Help( + "Output generated code to specified file.\n" + "When not set, standard output is used." + ); opts.AddLongOption('h', "header").OptionalArgument("<output-header>").StoreResult(&outputHeaderFileName) .Help( "Generate appropriate header to specified file.\n" @@ -397,75 +397,75 @@ int main(int argc, char** argv) { "Include input header using this path in angle brackets.\n" "When not set, header basename is used in double quotes." ); - - opts.AddLongOption('j', "json-output").OptionalArgument("<json-output>").StoreResult(&outputJsonFileName) - .Help( - "Generate enum data in JSON format." - ); - - opts.SetFreeArgsNum(1); - opts.SetFreeArgTitle(0, "<input-file>", "Input header file with enum declarations"); - - TOptsParseResult res(&opts, argc, argv); - + + opts.AddLongOption('j', "json-output").OptionalArgument("<json-output>").StoreResult(&outputJsonFileName) + .Help( + "Generate enum data in JSON format." + ); + + opts.SetFreeArgsNum(1); + opts.SetFreeArgTitle(0, "<input-file>", "Input header file with enum declarations"); + + TOptsParseResult res(&opts, argc, argv); + TVector<TString> freeArgs = res.GetFreeArgs(); TString inputFileName = freeArgs[0]; - + THolder<IOutputStream> hOut; IOutputStream* out = &Cout; - + THolder<IOutputStream> headerOut; THolder<IOutputStream> jsonOut; - - - if (outputFileName) { + + + if (outputFileName) { NFs::Remove(outputFileName); hOut.Reset(new TFileOutput(outputFileName)); - out = hOut.Get(); + out = hOut.Get(); if (outputHeaderFileName) { headerOut.Reset(new TFileOutput(outputHeaderFileName)); } - - if (outputJsonFileName) { + + if (outputJsonFileName) { jsonOut.Reset(new TFileOutput(outputJsonFileName)); - } - } - + } + } + if (!includePath) { includePath = TString() + '"' + TFsPath(inputFileName).Basename() + '"'; } else { includePath = TString() + '<' + includePath + '>'; } - TEnumParser parser(inputFileName); - WriteHeader(includePath, *out, headerOut.Get()); - - TStringStream jEnums; - OpenArray(jEnums); - - for (const auto& en : parser.Enums) { - if (!en.CppName) { - // skip unnamed enum declarations - continue; - } - - TStringStream jEnum; - GenerateEnum(en, *out, &jEnum, headerOut.Get()); - OutItem(jEnums, jEnum.Str(), false); - } - FinishItems(jEnums); - CloseArray(jEnums); - - if (jsonOut) { - *jsonOut << jEnums.Str() << Endl; - } - - return 0; - } catch (...) { - Cerr << CurrentExceptionMessage() << Endl; - } - - return 1; -} + TEnumParser parser(inputFileName); + WriteHeader(includePath, *out, headerOut.Get()); + + TStringStream jEnums; + OpenArray(jEnums); + + for (const auto& en : parser.Enums) { + if (!en.CppName) { + // skip unnamed enum declarations + continue; + } + + TStringStream jEnum; + GenerateEnum(en, *out, &jEnum, headerOut.Get()); + OutItem(jEnums, jEnum.Str(), false); + } + FinishItems(jEnums); + CloseArray(jEnums); + + if (jsonOut) { + *jsonOut << jEnums.Str() << Endl; + } + + return 0; + } catch (...) { + Cerr << CurrentExceptionMessage() << Endl; + } + + return 1; +} diff --git a/tools/enum_parser/enum_parser/ya.make b/tools/enum_parser/enum_parser/ya.make index 8e7b19358f..82bac4e0f7 100644 --- a/tools/enum_parser/enum_parser/ya.make +++ b/tools/enum_parser/enum_parser/ya.make @@ -1,12 +1,12 @@ -OWNER( +OWNER( g:util - mvel -) - + mvel +) + IF (USE_PREBUILT_TOOLS) INCLUDE(${ARCADIA_ROOT}/build/prebuilt/tools/enum_parser/enum_parser/ya.make.prebuilt) ENDIF() - + IF (NOT PREBUILT) INCLUDE(${ARCADIA_ROOT}/tools/enum_parser/enum_parser/bin/ya.make) ENDIF() diff --git a/tools/enum_parser/ya.make b/tools/enum_parser/ya.make index 56c0286b82..762b282b3e 100644 --- a/tools/enum_parser/ya.make +++ b/tools/enum_parser/ya.make @@ -1,6 +1,6 @@ -RECURSE( - parse_enum +RECURSE( + parse_enum parse_enum/ut - enum_parser + enum_parser enum_serialization_runtime -) +) diff --git a/tools/ya.make b/tools/ya.make index 24d69b69e1..51a6b8b426 100644 --- a/tools/ya.make +++ b/tools/ya.make @@ -3,14 +3,14 @@ RECURSE( arcdocidstrip archiver archiver/alignment_test - archiver/tests + archiver/tests base64 bigram_compiler blender bmdump bstr c++filt - calendar_extractor + calendar_extractor check_formula_md5 check_json check_yaml @@ -35,7 +35,7 @@ RECURSE( dsindexer easyparser enforce_fsync - enum_parser + enum_parser event2cpp fast_diff fastcksum @@ -166,7 +166,7 @@ RECURSE( uc unpackrichtree unpackrrr - unpack_staff_cert + unpack_staff_cert untranslit_test untranslit_test/tests url @@ -186,4 +186,4 @@ IF (NOT OS_WINDOWS) RECURSE( netgdb ) -ENDIF() +ENDIF() diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp index d49bfe80fd..38ecc3ab96 100644 --- a/util/datetime/base.cpp +++ b/util/datetime/base.cpp @@ -6,7 +6,7 @@ #include <util/system/compat.h> #include <util/memory/tempbuf.h> #include <util/generic/string.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/yexception.h> TString Strftime(const char* format, const struct tm* tm) { @@ -23,14 +23,14 @@ TString Strftime(const char* format, const struct tm* tm) { template <> TDuration FromStringImpl<TDuration, char>(const char* s, size_t len) { - return TDuration::Parse(TStringBuf(s, len)); + return TDuration::Parse(TStringBuf(s, len)); } template <> -bool TryFromStringImpl<TDuration, char>(const char* s, size_t len, TDuration& result) { - return TDuration::TryParse(TStringBuf(s, len), result); -} - +bool TryFromStringImpl<TDuration, char>(const char* s, size_t len, TDuration& result) { + return TDuration::TryParse(TStringBuf(s, len), result); +} + namespace { template <size_t N> struct TPad { diff --git a/util/datetime/base.h b/util/datetime/base.h index a16db8df98..5e902b8f63 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -167,10 +167,10 @@ public: return MicroSecondsOfSecond() * (TValue)1000; } - constexpr explicit operator bool() const noexcept { - return Value_; - } - + constexpr explicit operator bool() const noexcept { + return Value_; + } + protected: TValue Value_; // microseconds count }; @@ -311,7 +311,7 @@ public: static TDuration Parse(const TStringBuf input); static bool TryParse(const TStringBuf input, TDuration& result); - + // note global Out method is defined for TDuration, so it could be written to IOutputStream as text template <class T> diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp index b8f92e7ebb..afc3f802eb 100644 --- a/util/datetime/base_ut.cpp +++ b/util/datetime/base_ut.cpp @@ -14,13 +14,13 @@ using namespace std::chrono_literals; -struct TTestTime { - const time_t T_ = 987654321; - const char* Date_ = "Thu Apr 19 04:25:21 2001\n"; - const char* SprintDate_ = "20010419"; - const long SprintSecs_ = 15921; - struct tm Tm_; - TTestTime() { +struct TTestTime { + const time_t T_ = 987654321; + const char* Date_ = "Thu Apr 19 04:25:21 2001\n"; + const char* SprintDate_ = "20010419"; + const long SprintSecs_ = 15921; + struct tm Tm_; + TTestTime() { Tm_.tm_sec = 21; Tm_.tm_min = 25; Tm_.tm_hour = 4; @@ -30,7 +30,7 @@ struct TTestTime { Tm_.tm_wday = 4; Tm_.tm_yday = 108; } -}; +}; namespace { inline void OldDate8601(char* buf, time_t when) { @@ -176,7 +176,7 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) { a.tm_wday == b.tm_wday && a.tm_yday == b.tm_yday); } - + static inline TString Str(const struct tm& a) { return TStringBuilder() << "(" << a.tm_sec << ", " @@ -303,13 +303,13 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) { return t0 && t1 && CompareTM(*t0, *t1) && (t0->tm_isdst == t1->tm_isdst) -#ifndef _win_ +#ifndef _win_ && (t0->tm_gmtoff == t1->tm_gmtoff) && TimeZoneEq(t0->tm_zone, t1->tm_zone) -#endif // _win_ +#endif // _win_ && true; } - + Y_UNIT_TEST(TestGmTimeR) { time_t starttime = static_cast<time_t>(Max<i64>(-12244089600LL, Min<time_t>())); // 1-Jan-1582 time_t finishtime = static_cast<time_t>(Min<i64>(0xFFFFFFFF * 20, Max<time_t>())); @@ -375,7 +375,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { static const struct T { const char* const Str; const TDuration::TValue MicroSeconds; - const bool Parseable; + const bool Parseable; } tests[] = { {"0", 0, true}, {"1", 1000000, true}, @@ -385,21 +385,21 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { }; for (const T* t = tests; t != std::end(tests); ++t) { - // FromString - bool parsed = false; - try { - TDuration time = FromString<TDuration>(t->Str); - parsed = true; - UNIT_ASSERT_EQUAL(t->MicroSeconds, time.MicroSeconds()); - } catch (const yexception&) { - UNIT_ASSERT_VALUES_EQUAL(parsed, t->Parseable); - } - // TryFromString - TDuration tryTime; - UNIT_ASSERT_VALUES_EQUAL(TryFromString<TDuration>(t->Str, tryTime), t->Parseable); - if (t->Parseable) { - UNIT_ASSERT_EQUAL(t->MicroSeconds, tryTime.MicroSeconds()); - } + // FromString + bool parsed = false; + try { + TDuration time = FromString<TDuration>(t->Str); + parsed = true; + UNIT_ASSERT_EQUAL(t->MicroSeconds, time.MicroSeconds()); + } catch (const yexception&) { + UNIT_ASSERT_VALUES_EQUAL(parsed, t->Parseable); + } + // TryFromString + TDuration tryTime; + UNIT_ASSERT_VALUES_EQUAL(TryFromString<TDuration>(t->Str, tryTime), t->Parseable); + if (t->Parseable) { + UNIT_ASSERT_EQUAL(t->MicroSeconds, tryTime.MicroSeconds()); + } } } @@ -430,22 +430,22 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { } Y_UNIT_TEST(TestDurationMath) { - TDuration empty; - UNIT_ASSERT(!empty); - // ensure that this compiles too - if (empty) { - UNIT_ASSERT(false); - } - TDuration nonEmpty = TDuration::MicroSeconds(1); - UNIT_ASSERT(nonEmpty); - + TDuration empty; + UNIT_ASSERT(!empty); + // ensure that this compiles too + if (empty) { + UNIT_ASSERT(false); + } + TDuration nonEmpty = TDuration::MicroSeconds(1); + UNIT_ASSERT(nonEmpty); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(110), TDuration::Seconds(77) + TDuration::Seconds(33)); // overflow UNIT_ASSERT_VALUES_EQUAL(TDuration::Max(), TDuration::Max() - TDuration::Seconds(1) + TDuration::Seconds(10)); // underflow UNIT_ASSERT_VALUES_EQUAL(TDuration::Zero(), TDuration::Seconds(20) - TDuration::Seconds(200)); - // division - UNIT_ASSERT_DOUBLES_EQUAL(TDuration::Minutes(1) / TDuration::Seconds(10), 6.0, 1e-9); + // division + UNIT_ASSERT_DOUBLES_EQUAL(TDuration::Minutes(1) / TDuration::Seconds(10), 6.0, 1e-9); } Y_UNIT_TEST(TestDurationGetters) { diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp index a3e7c10d50..516d372c37 100644 --- a/util/datetime/cputimer.cpp +++ b/util/datetime/cputimer.cpp @@ -128,7 +128,7 @@ TTimeLogger::~TTimeLogger() { ui64 endCycles = GetCycleCount(); if (Verbose) { const char* prefix = (OK) ? "" : "!"; - fprintf(stderr, "%s%s ended: %.24s (%lu) (%d) (took %lus = %s)\n", + fprintf(stderr, "%s%s ended: %.24s (%lu) (%d) (took %lus = %s)\n", prefix, Message.data(), ctime(&tim), (unsigned long)tim, (int)getpid(), (unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data()); fprintf(stderr, "%s=========================================================\n", prefix); diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6 index ac41dd380f..931f09eae1 100644 --- a/util/datetime/parser.rl6 +++ b/util/datetime/parser.rl6 @@ -790,11 +790,11 @@ TDuration TDurationParser::GetResult(TDuration defaultValue) const { bool TDuration::TryParse(const TStringBuf input, TDuration& result) { TDuration r = ::Parse<TDurationParser, TDuration>(input.data(), input.size(), TDuration::Max()); - if (r == TDuration::Max()) - return false; - result = r; - return true; -} + if (r == TDuration::Max()) + return false; + result = r; + return true; +} TDuration TDuration::Parse(const TStringBuf input) { return ParseUnsafe<TDurationParser, TDuration>(input.data(), input.size()); diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp index 6df1ee2181..6ee7e8fc6e 100644 --- a/util/datetime/systime.cpp +++ b/util/datetime/systime.cpp @@ -131,10 +131,10 @@ struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf) { return tmbuf; } - + TString CTimeR(const time_t* timer) { - char sTime[32]; - sTime[0] = 0; - ctime_r(timer, &sTime[0]); - return sTime; -} + char sTime[32]; + sTime[0] = 0; + ctime_r(timer, &sTime[0]); + return sTime; +} diff --git a/util/datetime/systime.h b/util/datetime/systime.h index 0cb962cdd0..491d36e802 100644 --- a/util/datetime/systime.h +++ b/util/datetime/systime.h @@ -8,7 +8,7 @@ // timegm and gmtime_r versions that don't need access to filesystem or a big stack time_t TimeGM(const struct tm* t); struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf); -// safe version of ctime, convinient version of ctime_r +// safe version of ctime, convinient version of ctime_r TString CTimeR(const time_t* timer); #ifdef _win_ diff --git a/util/digest/fnv.h b/util/digest/fnv.h index efedb95ac9..87b41a3de7 100644 --- a/util/digest/fnv.h +++ b/util/digest/fnv.h @@ -66,8 +66,8 @@ template <class T> static constexpr T FnvHash(const void* buf, size_t len) { return FnvHash<T>((const unsigned char*)buf, (const unsigned char*)buf + len); } - -template <class T, class Buf> + +template <class T, class Buf> static constexpr T FnvHash(const Buf& buf) { return FnvHash<T>(buf.data(), buf.size() * sizeof(*buf.data())); -} +} diff --git a/util/digest/fnv_ut.cpp b/util/digest/fnv_ut.cpp index d295586efd..ce56642b3e 100644 --- a/util/digest/fnv_ut.cpp +++ b/util/digest/fnv_ut.cpp @@ -4,7 +4,7 @@ Y_UNIT_TEST_SUITE(TFnvTest) { Y_UNIT_TEST(TestFnv32) { - const auto h32 = ULL(2849763999); + const auto h32 = ULL(2849763999); UNIT_ASSERT_EQUAL(FnvHash<ui32>("1234567", 7), h32); UNIT_ASSERT_EQUAL(FnvHash<ui32>(TStringBuf("1234567")), h32); @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TFnvTest) { const auto h64 = ULL(2449551094593701855); UNIT_ASSERT_EQUAL(FnvHash<ui64>("1234567", 7), h64); UNIT_ASSERT_EQUAL(FnvHash<ui64>(TStringBuf("1234567")), h64); - + UNIT_ASSERT_EQUAL(FnvHash<ui64>(nullptr, 0), FNV64INIT); UNIT_ASSERT_EQUAL(FnvHash<ui64>(TStringBuf()), FNV64INIT); } diff --git a/util/draft/enum.h b/util/draft/enum.h index 9778cbc590..18002b7df2 100644 --- a/util/draft/enum.h +++ b/util/draft/enum.h @@ -27,7 +27,7 @@ const V* FindEnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t return nullptr; } -// special version for const char* +// 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++) @@ -39,28 +39,28 @@ const V* FindEnumFromStringImpl(const char* key, const std::pair<const char*, V> template <class K, class V> TString PrintEnumItemsImpl(const std::pair<K, V>* entries, size_t arraySize) { TString result; - TStringOutput out(result); - for (size_t i = 0; i < arraySize; i++) - out << (i ? ", " : "") << "'" << entries[i].first << "'"; - return result; -} - -// special version for const char* + TStringOutput out(result); + for (size_t i = 0; i < arraySize; i++) + out << (i ? ", " : "") << "'" << entries[i].first << "'"; + return result; +} + +// special version for const char* template <class V> TString PrintEnumItemsImpl(const std::pair<const char*, V>* entries, size_t arraySize) { TString result; - TStringOutput out(result); - for (size_t i = 0; i < arraySize; i++) + TStringOutput out(result); + for (size_t i = 0; i < arraySize; i++) out << (i ? ", " : "") << "'" << (entries[i].first ? entries[i].first : "<null>") << "'"; - return result; -} - + return result; +} + 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; - + ythrow TEnumNotFoundException() << "Key '" << key << "' not found in enum. Valid options are: " << PrintEnumItemsImpl(entries, arraySize) << ". "; } @@ -69,13 +69,13 @@ const K* EnumToStringImpl(V value, const std::pair<K, V>* entries, size_t arrayS 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: "; - for (size_t i = 0; i < arraySize; i++) - exc << (i ? ", " : "") << int(entries[i].second); - exc << ". "; - ythrow exc; + + TEnumNotFoundException exc; + exc << "Value '" << int(value) << "' not found in enum. Valid values are: "; + for (size_t i = 0; i < arraySize; i++) + exc << (i ? ", " : "") << int(entries[i].second); + exc << ". "; + ythrow exc; } /////////////////////////////////// diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h index 645b2c72fb..1c62055bd9 100644 --- a/util/draft/holder_vector.h +++ b/util/draft/holder_vector.h @@ -83,7 +83,7 @@ public: } using TBase::operator[]; - using TBase::operator bool; + using TBase::operator bool; using TBase::at; using TBase::back; using TBase::begin; diff --git a/util/draft/holder_vector_ut.cpp b/util/draft/holder_vector_ut.cpp index 9e71188536..f64393860a 100644 --- a/util/draft/holder_vector_ut.cpp +++ b/util/draft/holder_vector_ut.cpp @@ -6,13 +6,13 @@ Y_UNIT_TEST_SUITE(THolderVectorTest) { Y_UNIT_TEST(TestCreateEmpty) { THolderVector<int> ints; UNIT_ASSERT_EQUAL(ints.Size(), 0); - UNIT_ASSERT(!ints); + UNIT_ASSERT(!ints); } Y_UNIT_TEST(TestCreateNonEmpty) { THolderVector<int> ints(5); UNIT_ASSERT_EQUAL(ints.Size(), 5); - UNIT_ASSERT(ints); + UNIT_ASSERT(ints); for (size_t i = 0; i < ints.Size(); ++i) { UNIT_ASSERT_EQUAL(ints[i], (int*)nullptr); diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp index 89810e64bf..b21fcdbf20 100644 --- a/util/folder/filelist.cpp +++ b/util/folder/filelist.cpp @@ -5,26 +5,26 @@ #include <util/system/defaults.h> void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort) { - TDirIterator::TOptions opts; - opts.SetMaxLevel(depth); + TDirIterator::TOptions opts; + opts.SetMaxLevel(depth); if (sort) { - opts.SetSortByName(); + opts.SetSortByName(); } - TDirIterator dir(dirname, opts); + TDirIterator dir(dirname, opts); Clear(); - size_t dirNameLength = dirname.length(); + size_t dirNameLength = dirname.length(); while (dirNameLength && (dirname[dirNameLength - 1] == '\\' || dirname[dirNameLength - 1] == '/')) { --dirNameLength; } for (auto file = dir.begin(); file != dir.end(); ++file) { - if (file->fts_pathlen == file->fts_namelen || file->fts_pathlen <= dirNameLength) { + if (file->fts_pathlen == file->fts_namelen || file->fts_pathlen <= dirNameLength) { continue; } - TStringBuf filename = file->fts_path + dirNameLength + 1; + TStringBuf filename = file->fts_path + dirNameLength + 1; if (filename.empty() || !filename.StartsWith(prefix) || !filename.EndsWith(suffix)) { continue; diff --git a/util/folder/fts.cpp b/util/folder/fts.cpp index 8f3f10c643..0e6a6f86eb 100644 --- a/util/folder/fts.cpp +++ b/util/folder/fts.cpp @@ -62,7 +62,7 @@ #ifndef _win_ -static const dird invalidDirD = -1; +static const dird invalidDirD = -1; dird get_cwdd() { return open(".", O_RDONLY, 0); @@ -88,7 +88,7 @@ int cmp_dird(dird fd1, dird fd2) { return fd1 - fd2; } -#else // ndef _win_ +#else // ndef _win_ int stat64UTF(const char* path, struct _stat64* _Stat) { int len_converted = MultiByteToWideChar(CP_UTF8, 0, path, -1, 0, 0); @@ -164,7 +164,7 @@ dird get_dird(char* path) { return ret; } -#endif // ndef _win_ +#endif // ndef _win_ #ifdef _win_ #define S_ISDIR(st_mode) ((st_mode & _S_IFMT) == _S_IFDIR) @@ -873,8 +873,8 @@ fts_build(FTS* sp, int type) dirp = nullptr; #ifdef _win_ close_dird(dirpd); - dirpd = invalidDirD; -#else + dirpd = invalidDirD; +#else Y_UNUSED(invalidDirD); #endif } else { diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index 65721bd5bb..e6a3451016 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -200,7 +200,7 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "/db/BASE/primus121-025-1380131338/test"); #endif } - + Y_UNIT_TEST(TestSlashesAndBasenameWin) { TFsPath p("\\db\\BASE\\primus121-025-1380131338\\\\"); TFsPath testP = p / "test"; diff --git a/util/generic/buffer_ut.cpp b/util/generic/buffer_ut.cpp index d4330dc100..437d7122ec 100644 --- a/util/generic/buffer_ut.cpp +++ b/util/generic/buffer_ut.cpp @@ -18,114 +18,114 @@ Y_UNIT_TEST_SUITE(TBufferTest) { } Y_UNIT_TEST(TestAppend) { - const char data[] = "1234567890qwertyuiop"; + const char data[] = "1234567890qwertyuiop"; - TBuffer buf(13); + TBuffer buf(13); TString str; - for (size_t i = 0; i < 10; ++i) { - for (size_t j = 0; j < sizeof(data) - 1; ++j) { - buf.Append(data, j); - buf.Append('q'); - str.append(data, j); - str.append('q'); - } - } + for (size_t i = 0; i < 10; ++i) { + for (size_t j = 0; j < sizeof(data) - 1; ++j) { + buf.Append(data, j); + buf.Append('q'); + str.append(data, j); + str.append('q'); + } + } UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), str); } Y_UNIT_TEST(TestReset) { - char content[] = "some text"; - TBuffer buf; + char content[] = "some text"; + TBuffer buf; - buf.Append(content, sizeof(content)); - buf.Clear(); + buf.Append(content, sizeof(content)); + buf.Clear(); - UNIT_ASSERT(buf.Capacity() != 0); + UNIT_ASSERT(buf.Capacity() != 0); - buf.Append(content, sizeof(content)); - buf.Reset(); + buf.Append(content, sizeof(content)); + buf.Reset(); - UNIT_ASSERT_EQUAL(buf.Capacity(), 0); - } + UNIT_ASSERT_EQUAL(buf.Capacity(), 0); + } Y_UNIT_TEST(TestResize) { - char content[] = "some text"; - TBuffer buf; + char content[] = "some text"; + TBuffer buf; - buf.Resize(10); + buf.Resize(10); UNIT_ASSERT_VALUES_EQUAL(buf.size(), 10u); - buf.Resize(0); + buf.Resize(0); UNIT_ASSERT_VALUES_EQUAL(buf.size(), 0u); - buf.Resize(9); + buf.Resize(9); memcpy(buf.data(), content, 9); UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some text"); - buf.Resize(4); + buf.Resize(4); UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some"); - } + } Y_UNIT_TEST(TestReserve) { - TBuffer buf; - UNIT_ASSERT_EQUAL(buf.Capacity(), 0); + TBuffer buf; + UNIT_ASSERT_EQUAL(buf.Capacity(), 0); - buf.Reserve(4); - UNIT_ASSERT_EQUAL(buf.Capacity(), 4); + buf.Reserve(4); + UNIT_ASSERT_EQUAL(buf.Capacity(), 4); - buf.Reserve(6); - UNIT_ASSERT_EQUAL(buf.Capacity(), 8); + buf.Reserve(6); + UNIT_ASSERT_EQUAL(buf.Capacity(), 8); - buf.Reserve(32); - UNIT_ASSERT_EQUAL(buf.Capacity(), 32); + buf.Reserve(32); + UNIT_ASSERT_EQUAL(buf.Capacity(), 32); - buf.Reserve(33); - UNIT_ASSERT_EQUAL(buf.Capacity(), 64); - buf.Reserve(64); - UNIT_ASSERT_EQUAL(buf.Capacity(), 64); + buf.Reserve(33); + UNIT_ASSERT_EQUAL(buf.Capacity(), 64); + buf.Reserve(64); + UNIT_ASSERT_EQUAL(buf.Capacity(), 64); - buf.Resize(128); - UNIT_ASSERT_EQUAL(buf.Capacity(), 128); + buf.Resize(128); + UNIT_ASSERT_EQUAL(buf.Capacity(), 128); - buf.Append('a'); - UNIT_ASSERT_EQUAL(buf.Capacity(), 256); + buf.Append('a'); + UNIT_ASSERT_EQUAL(buf.Capacity(), 256); TString tmp1 = "abcdef"; buf.Append(tmp1.data(), tmp1.size()); - UNIT_ASSERT_EQUAL(buf.Capacity(), 256); + UNIT_ASSERT_EQUAL(buf.Capacity(), 256); TString tmp2 = "30498290sfokdsflj2308w"; - buf.Resize(1020); + buf.Resize(1020); buf.Append(tmp2.data(), tmp2.size()); - UNIT_ASSERT_EQUAL(buf.Capacity(), 2048); - } + UNIT_ASSERT_EQUAL(buf.Capacity(), 2048); + } Y_UNIT_TEST(TestShrinkToFit) { - TBuffer buf; + TBuffer buf; TString content = "some text"; buf.Append(content.data(), content.size()); - UNIT_ASSERT_EQUAL(buf.Size(), 9); - UNIT_ASSERT_EQUAL(buf.Capacity(), 16); + UNIT_ASSERT_EQUAL(buf.Size(), 9); + UNIT_ASSERT_EQUAL(buf.Capacity(), 16); - buf.ShrinkToFit(); - UNIT_ASSERT_EQUAL(buf.Size(), 9); - UNIT_ASSERT_EQUAL(buf.Capacity(), 9); + buf.ShrinkToFit(); + UNIT_ASSERT_EQUAL(buf.Size(), 9); + UNIT_ASSERT_EQUAL(buf.Capacity(), 9); UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), content); - const size_t MB = 1024 * 1024; - buf.Resize(MB); - UNIT_ASSERT_EQUAL(buf.Capacity(), MB); - buf.ShrinkToFit(); - UNIT_ASSERT_EQUAL(buf.Capacity(), MB); - buf.Resize(MB + 100); - UNIT_ASSERT_EQUAL(buf.Capacity(), 2 * MB); - buf.ShrinkToFit(); - UNIT_ASSERT_EQUAL(buf.Capacity(), MB + 100); - } - -#if 0 + const size_t MB = 1024 * 1024; + buf.Resize(MB); + UNIT_ASSERT_EQUAL(buf.Capacity(), MB); + buf.ShrinkToFit(); + UNIT_ASSERT_EQUAL(buf.Capacity(), MB); + buf.Resize(MB + 100); + UNIT_ASSERT_EQUAL(buf.Capacity(), 2 * MB); + buf.ShrinkToFit(); + UNIT_ASSERT_EQUAL(buf.Capacity(), MB + 100); + } + +#if 0 Y_UNIT_TEST(TestAlignUp) { char content[] = "some text"; TBuffer buf; @@ -142,9 +142,9 @@ Y_UNIT_TEST(TestAlignUp) { UNIT_ASSERT(buf.Size() % 4 == 0); UNIT_ASSERT_VALUES_EQUAL(TString(~buf, +buf), "some text!!!1234"); } -#endif +#endif -#if 0 +#if 0 Y_UNIT_TEST(TestSpeed) { const char data[] = "1234567890qwertyuiop"; const size_t c = 100000; @@ -177,19 +177,19 @@ Y_UNIT_TEST(TestSpeed) { UNIT_ASSERT(t1 < t2); } -#endif +#endif Y_UNIT_TEST(TestFillAndChop) { - TBuffer buf; - buf.Append("Some ", 5); - buf.Fill('!', 5); - buf.Append(" text.", 6); + TBuffer buf; + buf.Append("Some ", 5); + buf.Fill('!', 5); + buf.Append(" text.", 6); UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some !!!!! text."); - buf.Chop(5, 6); + buf.Chop(5, 6); UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some text."); - } - + } + Y_UNIT_TEST(TestComparison) { TBuffer buf1("abcd", 4); TBuffer buf2("abcde", 5); diff --git a/util/generic/guid.h b/util/generic/guid.h index d2e884c83b..2bf6c8ad99 100644 --- a/util/generic/guid.h +++ b/util/generic/guid.h @@ -4,15 +4,15 @@ #include <util/str_stl.h> -/** - * UUID generation - * - * NOTE: It is not a real GUID (RFC 4122), as described in - * https://en.wikipedia.org/wiki/Universally_unique_identifier - * https://en.wikipedia.org/wiki/Globally_unique_identifier - * - * See https://clubs.at.yandex-team.ru/stackoverflow/10238/10240 - * and https://st.yandex-team.ru/IGNIETFERRO-768 for details. +/** + * UUID generation + * + * NOTE: It is not a real GUID (RFC 4122), as described in + * https://en.wikipedia.org/wiki/Universally_unique_identifier + * https://en.wikipedia.org/wiki/Globally_unique_identifier + * + * See https://clubs.at.yandex-team.ru/stackoverflow/10238/10240 + * and https://st.yandex-team.ru/IGNIETFERRO-768 for details. */ struct TGUID { ui32 dw[4] = {}; diff --git a/util/generic/map.h b/util/generic/map.h index 140c7668ce..b5001b56c0 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -37,7 +37,7 @@ public: inline explicit operator bool() const noexcept { return !this->empty(); } - + inline bool contains(const K& key) const { return this->find(key) != this->end(); } diff --git a/util/generic/map_ut.cpp b/util/generic/map_ut.cpp index 7808192e74..79e832b024 100644 --- a/util/generic/map_ut.cpp +++ b/util/generic/map_ut.cpp @@ -5,35 +5,35 @@ #include <algorithm> Y_UNIT_TEST_SUITE(TYMapTest) { - template <typename TAlloc> + template <typename TAlloc> void DoTestMap1(TMap<char, int, TLess<char>, TAlloc>& m); - template <typename TAlloc> + template <typename TAlloc> void DoTestMMap1(TMultiMap<char, int, TLess<char>, TAlloc>& mm); Y_UNIT_TEST(TestMap1) { - { + { TMap<char, int, TLess<char>> m; - DoTestMap1(m); + DoTestMap1(m); } - { - TMemoryPool p(100); + { + TMemoryPool p(100); TMap<char, int, TLess<char>, TPoolAllocator> m(&p); - DoTestMap1(m); - } - } + DoTestMap1(m); + } + } Y_UNIT_TEST(TestMMap1) { - { + { TMultiMap<char, int, TLess<char>> mm; - DoTestMMap1(mm); + DoTestMMap1(mm); } - { - TMemoryPool p(100); + { + TMemoryPool p(100); TMultiMap<char, int, TLess<char>, TPoolAllocator> mm(&p); - DoTestMMap1(mm); - } - } + DoTestMMap1(mm); + } + } template <typename TAlloc> void DoTestMap1(TMap<char, int, TLess<char>, TAlloc>& m) { diff --git a/util/generic/ptr.h b/util/generic/ptr.h index f75af6f862..19db0e3ec5 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -1119,7 +1119,7 @@ private: TPtr T_; }; -// saves .Get() on argument passing. Intended usage: Func(TPtrArg<X> p); ... TIntrusivePtr<X> p2; Func(p2); +// saves .Get() on argument passing. Intended usage: Func(TPtrArg<X> p); ... TIntrusivePtr<X> p2; Func(p2); template <class T> class TPtrArg { T* Ptr; diff --git a/util/generic/set.h b/util/generic/set.h index 42ecb2759e..4c437ca26f 100644 --- a/util/generic/set.h +++ b/util/generic/set.h @@ -19,7 +19,7 @@ public: return !this->empty(); } - template <class TheKey> + template <class TheKey> inline bool contains(const TheKey& key) const { return this->find(key) != this->end(); } diff --git a/util/generic/set_ut.cpp b/util/generic/set_ut.cpp index 6a8c503608..d2769d327f 100644 --- a/util/generic/set_ut.cpp +++ b/util/generic/set_ut.cpp @@ -77,23 +77,23 @@ Y_UNIT_TEST_SUITE(YSetTest) { TSet<int> const& crs = s; UNIT_ASSERT(!crs.contains(0)); - + s.insert(1); s.insert(42); s.insert(100); s.insert(2); - + UNIT_ASSERT(s.contains(1)); UNIT_ASSERT(s.contains(2)); UNIT_ASSERT(s.contains(42)); UNIT_ASSERT(s.contains(100)); } - + Y_UNIT_TEST(TestBounds) { int array1[] = {1, 3, 6, 7}; TSet<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0])); TSet<int> const& crs = s; - + TSet<int>::iterator sit; TSet<int>::const_iterator scit; std::pair<TSet<int>::iterator, TSet<int>::iterator> pit; diff --git a/util/generic/strbase.h b/util/generic/strbase.h index a2b1ec160d..ab39fc7537 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -123,7 +123,7 @@ public: return std::basic_string<TCharType, TCharTraits, Allocator>(Ptr(), Len()); } - /** + /** * @param Pointer to character inside the string, or nullptr. * @return Offset from string beginning (in chars), or npos on nullptr. */ diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index d8e38a00c1..70b9360d58 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -434,19 +434,19 @@ public: } public: // string subsequences - /// Cut last @c shift characters (or less if length is less than @c shift) + /// Cut last @c shift characters (or less if length is less than @c shift) inline TdSelf& Chop(size_t shift) noexcept { this->remove_suffix(std::min(shift, size())); return *this; } - /// Cut first @c shift characters (or less if length is less than @c shift) + /// Cut first @c shift characters (or less if length is less than @c shift) inline TdSelf& Skip(size_t shift) noexcept { this->remove_prefix(std::min(shift, size())); return *this; } - /// Sets the start pointer to a position relative to the end + /// Sets the start pointer to a position relative to the end inline TdSelf& RSeek(size_t tailSize) noexcept { if (size() > tailSize) { //WARN: removing TStringView:: will lead to an infinite recursion diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 6b6109a06f..69cde785af 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -56,10 +56,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_VALUES_EQUAL(str.After('x'), TStringBuf("qwerty")); UNIT_ASSERT_VALUES_EQUAL(str.After('y'), TStringBuf()); UNIT_ASSERT_STRINGS_EQUAL(str.After('='), str); - - // Also works properly on empty strings - TStringBuf empty; - UNIT_ASSERT_STRINGS_EQUAL(empty.After('x'), empty); + + // Also works properly on empty strings + TStringBuf empty; + UNIT_ASSERT_STRINGS_EQUAL(empty.After('x'), empty); } Y_UNIT_TEST(TestBefore) { @@ -168,10 +168,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { rt = lt.SplitOff('r'); UNIT_ASSERT_EQUAL(lt, TStringBuf("qwe")); UNIT_ASSERT_EQUAL(rt, TStringBuf("ty")); - - rt = qw; - lt = rt.NextTok('r'); - TStringBuf ty = rt.NextTok('r'); // no 'r' in "ty" + + rt = qw; + lt = rt.NextTok('r'); + TStringBuf ty = rt.NextTok('r'); // no 'r' in "ty" UNIT_ASSERT_EQUAL(rt.size(), 0); UNIT_ASSERT_EQUAL(ty, TStringBuf("ty")); } diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index d98106ac1f..44bb10bdeb 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -526,9 +526,9 @@ public: void TestConstructors() { TStringType s0(nullptr); - UNIT_ASSERT(s0.size() == 0); + UNIT_ASSERT(s0.size() == 0); UNIT_ASSERT_EQUAL(s0, TStringType()); - + TStringType s; TStringType s1(*Data._0()); TStringType s2(Data._0()); @@ -895,8 +895,8 @@ public: TStringType sS = s2; // type 'TStringType' is used as is ComputeHash(sS); /*size_t hash_val = sS.hash(); - - try { + + try { //UNIT_ASSERT(hash_val == Data.HashOf_0123456()); } catch (...) { Cerr << hash_val << Endl; diff --git a/util/generic/utility_ut.cpp b/util/generic/utility_ut.cpp index 270f57e64a..8e9d5afff9 100644 --- a/util/generic/utility_ut.cpp +++ b/util/generic/utility_ut.cpp @@ -5,23 +5,23 @@ // DO_NOT_STYLE -class TTest { -public: - inline TTest(int val) - : Val(val) - { - } +class TTest { +public: + inline TTest(int val) + : Val(val) + { + } - inline void Swap(TTest& t) { - DoSwap(Val, t.Val); - } + inline void Swap(TTest& t) { + DoSwap(Val, t.Val); + } - int Val; + int Val; -private: - TTest(const TTest&); - TTest& operator=(const TTest&); -}; +private: + TTest(const TTest&); + TTest& operator=(const TTest&); +}; struct TUnorderedTag { TStringBuf Tag; @@ -34,7 +34,7 @@ static bool operator<(const TUnorderedTag, const TUnorderedTag) { static bool operator>(const TUnorderedTag, const TUnorderedTag) = delete; Y_UNIT_TEST_SUITE(TUtilityTest) { - + Y_UNIT_TEST(TestSwapPrimitive) { int i = 0; int j = 1; diff --git a/util/memory/blob_ut.cpp b/util/memory/blob_ut.cpp index 8764e1d205..023f9a0487 100644 --- a/util/memory/blob_ut.cpp +++ b/util/memory/blob_ut.cpp @@ -6,7 +6,7 @@ #include <util/folder/path.h> #include <util/stream/output.h> #include <util/stream/file.h> -#include <util/generic/buffer.h> +#include <util/generic/buffer.h> #include <util/generic/array_ref.h> Y_UNIT_TEST_SUITE(TBlobTest) { @@ -38,12 +38,12 @@ Y_UNIT_TEST_SUITE(TBlobTest) { Y_UNIT_TEST(TestFromString) { TString s("dsfkjhgsadftusadtf"); TBlob b(TBlob::FromString(s)); - + UNIT_ASSERT_EQUAL(TString((const char*)b.Data(), b.Size()), s); const auto expectedRef = TArrayRef<const ui8>{(ui8*)s.data(), s.size()}; UNIT_ASSERT_EQUAL(TArrayRef<const ui8>{b}, expectedRef); } - + Y_UNIT_TEST(TestFromBuffer) { const size_t sz = 1234u; TBuffer buf; diff --git a/util/network/sock_ut.cpp b/util/network/sock_ut.cpp index f64a4993db..fd8c783747 100644 --- a/util/network/sock_ut.cpp +++ b/util/network/sock_ut.cpp @@ -83,7 +83,7 @@ Y_UNIT_TEST_SUITE(TSocketTest) { cliSock.CheckSock(); servSock.CheckSock(); newSock.CheckSock(); - + // server int yes = 1; CheckedSetSockOpt(servSock, SOL_SOCKET, SO_REUSEADDR, yes, "servSock, SO_REUSEADDR"); diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 9ad5ff276c..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -432,22 +432,22 @@ void SetSocketPriority(SOCKET s, int priority) { #endif } -bool HasLocalAddress(SOCKET socket) { - TOpaqueAddr localAddr; - if (getsockname(socket, localAddr.MutableAddr(), localAddr.LenPtr()) != 0) { - ythrow TSystemError() << "HasLocalAddress: getsockname() failed. "; - } - if (IsLoopback(localAddr)) { - return true; - } - - TOpaqueAddr remoteAddr; - if (getpeername(socket, remoteAddr.MutableAddr(), remoteAddr.LenPtr()) != 0) { - ythrow TSystemError() << "HasLocalAddress: getpeername() failed. "; - } - return IsSame(localAddr, remoteAddr); -} - +bool HasLocalAddress(SOCKET socket) { + TOpaqueAddr localAddr; + if (getsockname(socket, localAddr.MutableAddr(), localAddr.LenPtr()) != 0) { + ythrow TSystemError() << "HasLocalAddress: getsockname() failed. "; + } + if (IsLoopback(localAddr)) { + return true; + } + + TOpaqueAddr remoteAddr; + if (getpeername(socket, remoteAddr.MutableAddr(), remoteAddr.LenPtr()) != 0) { + ythrow TSystemError() << "HasLocalAddress: getpeername() failed. "; + } + return IsSame(localAddr, remoteAddr); +} + namespace { #if defined(_linux_) #if !defined(TCP_FASTOPEN) diff --git a/util/network/socket.h b/util/network/socket.h index 646869bbaa..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -118,7 +118,7 @@ int GetSocketToS(SOCKET s); int GetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr); void SetSocketPriority(SOCKET s, int priority); void SetTcpFastOpen(SOCKET s, int qlen); -/** +/** * Deprecated, consider using HasSocketDataToRead instead. **/ bool IsNotSocketClosedByOtherSide(SOCKET s); @@ -132,9 +132,9 @@ enum class ESocketReadStatus { **/ ESocketReadStatus HasSocketDataToRead(SOCKET s); /** - * Determines whether connection on socket is local (same machine) or not. - **/ -bool HasLocalAddress(SOCKET socket); + * Determines whether connection on socket is local (same machine) or not. + **/ +bool HasLocalAddress(SOCKET socket); /** * Runtime check if current kernel supports SO_REUSEPORT option. diff --git a/util/random/mersenne.h b/util/random/mersenne.h index b0296a6dfb..b2044604ac 100644 --- a/util/random/mersenne.h +++ b/util/random/mersenne.h @@ -10,21 +10,21 @@ namespace NPrivate { template <> struct TMersenneTraits<ui64> { - using TImpl = TMersenne64; + using TImpl = TMersenne64; }; template <> struct TMersenneTraits<ui32> { - using TImpl = TMersenne32; + using TImpl = TMersenne32; }; } class IInputStream; template <class T> -class TMersenne: public TCommonRNG<T, TMersenne<T>>, public ::NPrivate::TMersenneTraits<T>::TImpl { +class TMersenne: public TCommonRNG<T, TMersenne<T>>, public ::NPrivate::TMersenneTraits<T>::TImpl { public: - using TBase = typename ::NPrivate::TMersenneTraits<T>::TImpl; + using TBase = typename ::NPrivate::TMersenneTraits<T>::TImpl; inline TMersenne() noexcept { } diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp index ada45c76e7..139f4296e5 100644 --- a/util/stream/ios_ut.cpp +++ b/util/stream/ios_ut.cpp @@ -52,7 +52,7 @@ public: UNIT_TEST_SUITE_REGISTRATION(TStreamsTest); -void TStreamsTest::TestIStreamOperators() { +void TStreamsTest::TestIStreamOperators() { TString data("first line\r\nsecond\t\xd1\x82\xd0\xb5\xd1\x81\xd1\x82 line\r\n 1 -4 59 4320000000009999999 c\n -1.5 1e-110"); TStringInput si(data); @@ -103,20 +103,20 @@ void TStreamsTest::TestStringStream() { UNIT_ASSERT_EQUAL(s.ReadLine(), "123.1"); UNIT_ASSERT_EQUAL(s.Str(), "qw\r\n1234\n34\r\n123.1"); - - // Test stream copying - TStringStream sc = s; - - s << "-666-" << 13; - sc << "-777-" << 0 << "JackPot"; - - UNIT_ASSERT_EQUAL(s.Str(), "qw\r\n1234\n34\r\n123.1-666-13"); - UNIT_ASSERT_EQUAL(sc.Str(), "qw\r\n1234\n34\r\n123.1-777-0JackPot"); - - TStringStream ss; - ss = s; - s << "... and some trash"; - UNIT_ASSERT_EQUAL(ss.Str(), "qw\r\n1234\n34\r\n123.1-666-13"); + + // Test stream copying + TStringStream sc = s; + + s << "-666-" << 13; + sc << "-777-" << 0 << "JackPot"; + + UNIT_ASSERT_EQUAL(s.Str(), "qw\r\n1234\n34\r\n123.1-666-13"); + UNIT_ASSERT_EQUAL(sc.Str(), "qw\r\n1234\n34\r\n123.1-777-0JackPot"); + + TStringStream ss; + ss = s; + s << "... and some trash"; + UNIT_ASSERT_EQUAL(ss.Str(), "qw\r\n1234\n34\r\n123.1-666-13"); } void TStreamsTest::TestGenericRead() { diff --git a/util/stream/str.h b/util/stream/str.h index 19bbc4643b..028bd572c0 100644 --- a/util/stream/str.h +++ b/util/stream/str.h @@ -4,10 +4,10 @@ #include "zerocopy_output.h" #include <util/generic/string.h> -#include <util/generic/noncopyable.h> +#include <util/generic/noncopyable.h> #include <util/generic/store_policy.h> -/** +/** * @addtogroup Streams_Strings * @{ */ @@ -54,11 +54,11 @@ protected: private: const TString* S_; size_t Pos_; - - friend class TStringStream; + + friend class TStringStream; }; -/** +/** * Stream for writing data into a string. */ class TStringOutput: public IZeroCopyOutput { @@ -131,7 +131,7 @@ public: , TStringOutput(*TEmbeddedString::Ptr()) { } - + inline TStringStream& operator=(const TStringStream& other) { // All references remain alive, we need to change position only Str() = other.Str(); @@ -139,7 +139,7 @@ public: return *this; } - + ~TStringStream() override; /** diff --git a/util/stream/zlib.h b/util/stream/zlib.h index 0961de7d4b..e7de7c81b7 100644 --- a/util/stream/zlib.h +++ b/util/stream/zlib.h @@ -37,9 +37,9 @@ namespace ZLib { }; } -/** +/** * Non-buffered ZLib decompressing stream. - * + * * Please don't use `TZLibDecompress` if you read text data from stream using * `ReadLine`, it is VERY slow (approx 10 times slower, according to synthetic * benchmark). For fast buffered ZLib stream reading use `TBufferedZLibDecompress` diff --git a/util/string/ascii.cpp b/util/string/ascii.cpp index 9f04f7ec4f..95edb95cc8 100644 --- a/util/string/ascii.cpp +++ b/util/string/ascii.cpp @@ -1,8 +1,8 @@ #include "ascii.h" -#include <util/system/yassert.h> -#include <util/system/compat.h> - +#include <util/system/yassert.h> +#include <util/system/compat.h> + // clang-format off extern const unsigned char NPrivate::ASCII_CLASS[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, @@ -22,7 +22,7 @@ extern const unsigned char NPrivate::ASCII_CLASS[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - + extern const unsigned char NPrivate::ASCII_LOWER[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, @@ -46,14 +46,14 @@ extern const unsigned char NPrivate::ASCII_LOWER[256] = { int AsciiCompareIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept { if (s1.size() <= s2.size()) { if (int cmp = strnicmp(s1.data(), s2.data(), s1.size())) { - return cmp; - } + return cmp; + } return (s1.size() < s2.size()) ? -1 : 0; - } - + } + Y_ASSERT(s1.size() > s2.size()); if (int cmp = strnicmp(s1.data(), s2.data(), s2.size())) { - return cmp; - } - return 1; -} + return cmp; + } + return 1; +} diff --git a/util/string/ascii.h b/util/string/ascii.h index 0bd70bc9ed..10344384d3 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/defaults.h> -#include <util/system/compat.h> +#include <util/system/compat.h> #include <util/generic/string.h> // ctype.h-like functions, locale-independent: @@ -156,72 +156,72 @@ template <class T> inline ::NPrivate::TDereferenced<T> AsciiToUpper(T c) noexcept { return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; } - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). * - * BUGS: Currently will NOT work properly with strings that contain - * 0-terminator character inside. See IGNIETFERRO-1641 for details. - * + * BUGS: Currently will NOT work properly with strings that contain + * 0-terminator character inside. See IGNIETFERRO-1641 for details. + * * @return true iff @c s1 ans @c s2 are case-insensitively equal. */ -static inline bool AsciiEqualsIgnoreCase(const char* s1, const char* s2) noexcept { - return stricmp(s1, s2) == 0; -} - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings +static inline bool AsciiEqualsIgnoreCase(const char* s1, const char* s2) noexcept { + return stricmp(s1, s2) == 0; +} + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). * - * BUGS: Currently will NOT work properly with strings that contain - * 0-terminator character inside. See IGNIETFERRO-1641 for details. - * + * BUGS: Currently will NOT work properly with strings that contain + * 0-terminator character inside. See IGNIETFERRO-1641 for details. + * * @return true iff @c s1 ans @c s2 are case-insensitively equal. */ static inline bool AsciiEqualsIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept { return (s1.size() == s2.size()) && strnicmp(s1.data(), s2.data(), s1.size()) == 0; -} - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings +} + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). * - * BUGS: Currently will NOT work properly with strings that contain - * 0-terminator character inside. See IGNIETFERRO-1641 for details. - * + * BUGS: Currently will NOT work properly with strings that contain + * 0-terminator character inside. See IGNIETFERRO-1641 for details. + * * @return 0 if strings are equal, negative if @c s1 < @c s2 * and positive otherwise. * (same value as @c stricmp does). */ -static inline int AsciiCompareIgnoreCase(const char* s1, const char* s2) noexcept { - return stricmp(s1, s2); -} - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings +static inline int AsciiCompareIgnoreCase(const char* s1, const char* s2) noexcept { + return stricmp(s1, s2); +} + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). * - * BUGS: Currently will NOT work properly with strings that contain - * 0-terminator character inside. See IGNIETFERRO-1641 for details. - * - * @return - * - zero if strings are equal - * - negative if @c s1 < @c s2 - * - positive otherwise, - * similar to stricmp. + * BUGS: Currently will NOT work properly with strings that contain + * 0-terminator character inside. See IGNIETFERRO-1641 for details. + * + * @return + * - zero if strings are equal + * - negative if @c s1 < @c s2 + * - positive otherwise, + * similar to stricmp. */ Y_PURE_FUNCTION int AsciiCompareIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept; /** - * ASCII case-sensitive string comparison (for proper UTF8 strings - * case-sensitive comparison consider using @c library/cpp/charset). - * - * BUGS: Currently will NOT work properly with strings that contain - * 0-terminator character inside. See IGNIETFERRO-1641 for details. - * - * @return true iff @c s2 are case-sensitively prefix of @c s1. - */ + * ASCII case-sensitive string comparison (for proper UTF8 strings + * case-sensitive comparison consider using @c library/cpp/charset). + * + * BUGS: Currently will NOT work properly with strings that contain + * 0-terminator character inside. See IGNIETFERRO-1641 for details. + * + * @return true iff @c s2 are case-sensitively prefix of @c s1. + */ static inline bool AsciiHasPrefix(const TStringBuf s1, const TStringBuf s2) noexcept { return (s1.size() >= s2.size()) && memcmp(s1.data(), s2.data(), s2.size()) == 0; } diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 41732f6f4e..89069fee50 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -61,14 +61,14 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT(!IsAsciiPunct(i)); } } - + Y_UNIT_TEST(CompareTest) { - UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", "qQq")); + UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", "qQq")); UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", TStringBuf("qQq"))); TString qq = "qq"; TString qQ = "qQ"; - UNIT_ASSERT(AsciiEqualsIgnoreCase(qq, qQ)); - + UNIT_ASSERT(AsciiEqualsIgnoreCase(qq, qQ)); + TString x = "qqqA"; TString y = "qQqB"; TString z = "qQnB"; @@ -77,13 +77,13 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { TStringBuf xs = TStringBuf(x.data(), 3); TStringBuf ys = TStringBuf(y.data(), 3); TStringBuf zs = TStringBuf(z.data(), 3); - UNIT_ASSERT(AsciiCompareIgnoreCase(xs, ys) == 0); - UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zs) > 0); - UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zz) < 0); - UNIT_ASSERT(AsciiCompareIgnoreCase(zzz, zz) > 0); - - UNIT_ASSERT(AsciiCompareIgnoreCase("qqQ", "qq") > 0); - UNIT_ASSERT(AsciiCompareIgnoreCase("qq", "qq") == 0); + UNIT_ASSERT(AsciiCompareIgnoreCase(xs, ys) == 0); + UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zs) > 0); + UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zz) < 0); + UNIT_ASSERT(AsciiCompareIgnoreCase(zzz, zz) > 0); + + UNIT_ASSERT(AsciiCompareIgnoreCase("qqQ", "qq") > 0); + UNIT_ASSERT(AsciiCompareIgnoreCase("qq", "qq") == 0); UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qwe"), true); UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qWe"), false); @@ -94,5 +94,5 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); - } + } } diff --git a/util/string/cast.cpp b/util/string/cast.cpp index 7443dbafb0..aa1e65a8e9 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -308,7 +308,7 @@ namespace { TUnsigned result; EParseStatus error = TBasicIntParser<TUnsigned, base, TChar>::Parse(&pos, end, max, &result); if (error != PS_OK) { - *ppos = pos; + *ppos = pos; return error; } @@ -484,38 +484,38 @@ size_t ToStringImpl<bool>(bool t, char* buf, size_t len) { */ template <> -bool TryFromStringImpl<bool>(const char* data, size_t len, bool& result) { +bool TryFromStringImpl<bool>(const char* data, size_t len, bool& result) { if (len == 1) { if (data[0] == '0') { - result = false; - return true; + result = false; + return true; } else if (data[0] == '1') { - result = true; + result = true; return true; } } TStringBuf buf(data, len); - if (IsTrue(buf)) { - result = true; + if (IsTrue(buf)) { + result = true; + return true; + } else if (IsFalse(buf)) { + result = false; return true; - } else if (IsFalse(buf)) { - result = false; - return true; } - return false; + return false; } -template <> -bool FromStringImpl<bool>(const char* data, size_t len) { - bool result; +template <> +bool FromStringImpl<bool>(const char* data, size_t len) { + bool result; if (!TryFromStringImpl<bool>(data, len, result)) { ythrow TFromStringException() << TStringBuf("Cannot parse bool(") << TStringBuf(data, len) << TStringBuf("). "); } - return result; -} - + return result; +} + template <> TString FromStringImpl<TString>(const char* data, size_t len) { return TString(data, len); @@ -541,8 +541,8 @@ TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { return TWtringBuf(data, len); } -// Try-versions -template <> +// Try-versions +template <> bool TryFromStringImpl<TStringBuf>(const char* data, size_t len, TStringBuf& result) { result = {data, len}; return true; @@ -551,10 +551,10 @@ bool TryFromStringImpl<TStringBuf>(const char* data, size_t len, TStringBuf& res template <> bool TryFromStringImpl<TString>(const char* data, size_t len, TString& result) { result = TString(data, len); - return true; -} - -template <> + return true; +} + +template <> bool TryFromStringImpl<std::string>(const char* data, size_t len, std::string& result) { result.assign(data, len); return true; @@ -569,9 +569,9 @@ bool TryFromStringImpl<TWtringBuf>(const wchar16* data, size_t len, TWtringBuf& template <> bool TryFromStringImpl<TUtf16String>(const wchar16* data, size_t len, TUtf16String& result) { result = TUtf16String(data, len); - return true; -} - + return true; +} + #define DEF_INT_SPEC_III(CHAR, TYPE, ITYPE, BOUNDS, BASE) \ template <> \ TYPE IntFromString<TYPE, BASE>(const CHAR* data, size_t len) { \ @@ -641,48 +641,48 @@ DEF_FLT_SPEC(long double) #undef DEF_FLT_SPEC // Using StrToD for float and double because it is faster than sscanf. -// Exception-free, specialized for float types +// Exception-free, specialized for float types template <> -bool TryFromStringImpl<double>(const char* data, size_t len, double& result) { - if (!len) { - return false; - } - +bool TryFromStringImpl<double>(const char* data, size_t len, double& result) { + if (!len) { + return false; + } + char* se = nullptr; - double d = StrToD(data, data + len, &se); - - if (se != data + len) { - return false; - } - result = d; - return true; -} - -template <> -bool TryFromStringImpl<float>(const char* data, size_t len, float& result) { - double d; - if (TryFromStringImpl<double>(data, len, d)) { - result = static_cast<float>(d); - return true; - } - return false; -} - -template <> -bool TryFromStringImpl<long double>(const char* data, size_t len, long double& result) { - double d; - if (TryFromStringImpl<double>(data, len, d)) { - result = static_cast<long double>(d); - return true; - } - return false; -} - -// Exception-throwing, specialized for float types -template <> + double d = StrToD(data, data + len, &se); + + if (se != data + len) { + return false; + } + result = d; + return true; +} + +template <> +bool TryFromStringImpl<float>(const char* data, size_t len, float& result) { + double d; + if (TryFromStringImpl<double>(data, len, d)) { + result = static_cast<float>(d); + return true; + } + return false; +} + +template <> +bool TryFromStringImpl<long double>(const char* data, size_t len, long double& result) { + double d; + if (TryFromStringImpl<double>(data, len, d)) { + result = static_cast<long double>(d); + return true; + } + return false; +} + +// Exception-throwing, specialized for float types +template <> double FromStringImpl<double>(const char* data, size_t len) { - double d = 0.0; - if (!TryFromStringImpl(data, len, d)) { + double d = 0.0; + if (!TryFromStringImpl(data, len, d)) { ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")"); } return d; @@ -690,7 +690,7 @@ double FromStringImpl<double>(const char* data, size_t len) { template <> float FromStringImpl<float>(const char* data, size_t len) { - return static_cast<float>(FromStringImpl<double>(data, len)); + return static_cast<float>(FromStringImpl<double>(data, len)); } double StrToD(const char* b, const char* e, char** se) { diff --git a/util/string/cast.h b/util/string/cast.h index 860af45dd6..90e925c194 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -14,7 +14,7 @@ template <class T> size_t ToStringImpl(T t, char* buf, size_t len); -/** +/** * Converts @c t to string writing not more than @c len bytes to output buffer @c buf. * No NULL terminator appended! Throws exception on buffer overflow. * @return number of bytes written @@ -215,27 +215,27 @@ inline ::NPrivate::TFromString<typename T::TChar> FromString(const T& s) { return ::NPrivate::TFromString<typename T::TChar>(s.data(), s.size()); } -// Conversion exception free versions -template <typename T, typename TChar> -bool TryFromStringImpl(const TChar* data, size_t len, T& result); - -/** - * @param data Source string buffer pointer - * @param len Source string length, in characters - * @param result Place to store conversion result value. - * If conversion error occurs, no value stored in @c result - * @return @c true in case of successful conversion, @c false otherwise - **/ -template <typename T, typename TChar> -inline bool TryFromString(const TChar* data, size_t len, T& result) { - return TryFromStringImpl<T>(data, len, result); -} - -template <typename T, typename TChar> -inline bool TryFromString(const TChar* data, T& result) { +// Conversion exception free versions +template <typename T, typename TChar> +bool TryFromStringImpl(const TChar* data, size_t len, T& result); + +/** + * @param data Source string buffer pointer + * @param len Source string length, in characters + * @param result Place to store conversion result value. + * If conversion error occurs, no value stored in @c result + * @return @c true in case of successful conversion, @c false otherwise + **/ +template <typename T, typename TChar> +inline bool TryFromString(const TChar* data, size_t len, T& result) { + return TryFromStringImpl<T>(data, len, result); +} + +template <typename T, typename TChar> +inline bool TryFromString(const TChar* data, T& result) { return TryFromString<T>(data, std::char_traits<TChar>::length(data), result); -} - +} + template <class T, class TChar> inline bool TryFromString(const TChar* data, const size_t len, T& result, const T& def) { if (TryFromString<T>(data, len, result)) { @@ -245,31 +245,31 @@ inline bool TryFromString(const TChar* data, const size_t len, T& result, const return false; } -template <class T> -inline bool TryFromString(const TStringBuf& s, T& result) { +template <class T> +inline bool TryFromString(const TStringBuf& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); -} - -template <class T> +} + +template <class T> inline bool TryFromString(const TString& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); -} - -template <class T> +} + +template <class T> inline bool TryFromString(const std::string& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); } template <class T> -inline bool TryFromString(const TWtringBuf& s, T& result) { +inline bool TryFromString(const TWtringBuf& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); -} - -template <class T> +} + +template <class T> inline bool TryFromString(const TUtf16String& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); -} - +} + template <class T, class TStringType> inline bool TryFromStringWithDefault(const TStringType& s, T& result, const T& def) { return TryFromString<T>(s.data(), s.size(), result, def); diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 56daa2dfec..033450c38c 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -3,16 +3,16 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/charset/wide.h> -#include <util/system/defaults.h> +#include <util/system/defaults.h> #include <limits> -// positive test (return true or no exception) +// positive test (return true or no exception) #define test1(t, v) \ F<t>().CheckTryOK(v); \ F<t>().CheckOK(v) -// negative test (return false or exception) +// negative test (return false or exception) #define test2(t, v) \ F<t>().CheckTryFail(v); \ F<t>().CheckExc(v) @@ -22,7 +22,7 @@ #define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) #define OK_HEX_CHECK(type, val, base) UNIT_ASSERT_EQUAL((IntFromStringForCheck<base>(IntToString<base>(val))), val); -#define EXC_HEX_CHECK(type, val, base) UNIT_ASSERT_EXCEPTION((IntFromString<type, base>(IntToString<base>(val))), yexception); +#define EXC_HEX_CHECK(type, val, base) UNIT_ASSERT_EXCEPTION((IntFromString<type, base>(IntToString<base>(val))), yexception); #define TRY_HEX_MACROS_MAP(mac, type, val, result, def) \ mac(type, val, result, def, 2) \ @@ -53,33 +53,33 @@ struct TRet { } template <class B> - inline void CheckOK(B v) { + 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); + HEX_MACROS_MAP(OK_HEX_CHECK, A, v); } 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) { + 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) { static const A defaultV = 42; - A convV; + A convV; UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToString(v), convV), true); // char UNIT_ASSERT_VALUES_EQUAL(v, convV); UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToWtring(v), convV), true); // wide char UNIT_ASSERT_VALUES_EQUAL(v, convV); - + TRY_HEX_MACROS_MAP(TRY_OK_HEX_CHECK, A, v, convV, defaultV); - } - - template <class B> - inline void CheckTryFail(B v) { + } + + template <class B> + inline void CheckTryFail(B v) { static const A defaultV = 42; A convV = defaultV; // to check that original value is not trashed on bad cast UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToString(v), convV), false); // char @@ -88,35 +88,35 @@ struct TRet { UNIT_ASSERT_VALUES_EQUAL(defaultV, convV); TRY_HEX_MACROS_MAP(TRY_FAIL_HEX_CHECK, A, v, convV, defaultV); - } + } }; template <> struct TRet<bool> { template <class B> - inline void CheckOK(B v) { + inline void CheckOK(B v) { UNIT_ASSERT_VALUES_EQUAL(FromString<bool>(ToString(v)), v); } template <class B> - inline void CheckTryOK(B v) { - B convV; + inline void CheckTryOK(B v) { + B convV; UNIT_ASSERT_VALUES_EQUAL(TryFromString<bool>(ToString(v), convV), true); UNIT_ASSERT_VALUES_EQUAL(v, convV); - } - - template <class B> - inline void CheckExc(B v) { + } + + template <class B> + inline void CheckExc(B v) { UNIT_ASSERT_EXCEPTION(FromString<bool>(ToString(v)), yexception); } - - template <class B> - inline void CheckTryFail(B v) { + + template <class B> + inline void CheckTryFail(B v) { static const bool defaultV = false; bool convV = defaultV; UNIT_ASSERT_VALUES_EQUAL(TryFromString<bool>(ToString(v), convV), false); UNIT_ASSERT_VALUES_EQUAL(defaultV, convV); - } + } }; template <class A> @@ -125,30 +125,30 @@ inline TRet<A> F() { }; #if 0 -template <class T> +template <class T> inline void CheckConvertToBuffer(const T& value, const size_t size, const TString& canonValue) { - const size_t maxSize = 256; - char buffer[maxSize]; - const char magic = 0x7F; - memset(buffer, magic, maxSize); - size_t length = 0; - if (canonValue.size() > size) { // overflow will occur - UNIT_ASSERT_EXCEPTION(length = ToString(value, buffer, size), yexception); - // check that no bytes after size was trashed - for (size_t i = size; i < maxSize; ++i) + const size_t maxSize = 256; + char buffer[maxSize]; + const char magic = 0x7F; + memset(buffer, magic, maxSize); + size_t length = 0; + if (canonValue.size() > size) { // overflow will occur + UNIT_ASSERT_EXCEPTION(length = ToString(value, buffer, size), yexception); + // check that no bytes after size was trashed + for (size_t i = size; i < maxSize; ++i) UNIT_ASSERT_VALUES_EQUAL(buffer[i], magic); - } else { - length = ToString(value, buffer, size); - UNIT_ASSERT(length < maxSize); - // check that no bytes after length was trashed - for (size_t i = length; i < maxSize; ++i) + } else { + length = ToString(value, buffer, size); + UNIT_ASSERT(length < maxSize); + // check that no bytes after length was trashed + for (size_t i = length; i < maxSize; ++i) UNIT_ASSERT_VALUES_EQUAL(buffer[i], magic); - TStringBuf result(buffer, length); + TStringBuf result(buffer, length); UNIT_ASSERT_VALUES_EQUAL(result, TStringBuf(canonValue)); - } -} + } +} #endif - + Y_UNIT_TEST_SUITE(TCastTest) { template <class A> inline TRet<A> F() { @@ -332,14 +332,14 @@ Y_UNIT_TEST_SUITE(TCastTest) { CheckConvertToBuffer<float>(1.f, 5, "1"); CheckConvertToBuffer<float>(1.005f, 3, "1.005"); CheckConvertToBuffer<float>(1.00000000f, 3, "1"); - + CheckConvertToBuffer<double>(1.f, 5, "1"); CheckConvertToBuffer<double>(1.005f, 3, "1.005"); CheckConvertToBuffer<double>(1.00000000f, 3, "1"); - + CheckConvertToBuffer<int>(2, 5, "2"); CheckConvertToBuffer<int>(1005, 3, "1005"); - + CheckConvertToBuffer<size_t>(2, 5, "2"); CheckConvertToBuffer<ui64>(1005000000000000ull, 32, "1005000000000000"); CheckConvertToBuffer<ui64>(1005000000000000ull, 3, "1005000000000000"); @@ -348,29 +348,29 @@ Y_UNIT_TEST_SUITE(TCastTest) { // UNIT_ASSERT_EXCEPTION(FromString<double>(longNumber), yexception); } #endif - + Y_UNIT_TEST(TestWide) { TUtf16String iw = u"-100500"; int iv = 0; UNIT_ASSERT_VALUES_EQUAL(TryFromString(iw, iv), true); UNIT_ASSERT_VALUES_EQUAL(iv, -100500); - + ui64 uv = 0; TUtf16String uw = u"21474836470"; UNIT_ASSERT_VALUES_EQUAL(TryFromString(uw, uv), true); UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull); - + TWtringBuf bw(uw.data(), uw.size()); uv = 0; UNIT_ASSERT_VALUES_EQUAL(TryFromString(uw, uv), true); UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull); - + const wchar16* beg = uw.data(); uv = 0; UNIT_ASSERT_VALUES_EQUAL(TryFromString(beg, uw.size(), uv), true); UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull); } - + Y_UNIT_TEST(TestDefault) { size_t res = 0; const size_t def1 = 42; @@ -438,17 +438,17 @@ Y_UNIT_TEST_SUITE(TCastTest) { } Y_UNIT_TEST(TestBool) { - // True cases - UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("yes"), true); - UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("1"), true); - // False cases - UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("no"), false); - UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("0"), false); - // Strange cases - UNIT_ASSERT_EXCEPTION(FromString<bool>(""), yexception); - UNIT_ASSERT_EXCEPTION(FromString<bool>("something"), yexception); - } - + // True cases + UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("yes"), true); + UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("1"), true); + // False cases + UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("no"), false); + UNIT_ASSERT_VALUES_EQUAL(FromString<bool>("0"), false); + // Strange cases + UNIT_ASSERT_EXCEPTION(FromString<bool>(""), yexception); + UNIT_ASSERT_EXCEPTION(FromString<bool>("something"), yexception); + } + Y_UNIT_TEST(TestAutoDetectType) { UNIT_ASSERT_DOUBLES_EQUAL((float)FromString("0.0001"), 0.0001, EPS); UNIT_ASSERT_DOUBLES_EQUAL((double)FromString("0.0015", sizeof("0.0015") - 2), 0.001, EPS); @@ -463,52 +463,52 @@ Y_UNIT_TEST_SUITE(TCastTest) { ui16 wideCharacterCode = FromString(u"125"); UNIT_ASSERT_VALUES_EQUAL(integer, wideCharacterCode); } - + static void CheckMessage(TFromStringException& exc, const TString& phrase) { TString message = exc.what(); - if (!message.Contains(phrase)) { - Cerr << message << Endl; - UNIT_ASSERT(false); - } - } - + if (!message.Contains(phrase)) { + Cerr << message << Endl; + UNIT_ASSERT(false); + } + } + Y_UNIT_TEST(ErrorMessages) { - try { - FromString<ui32>(""); - UNIT_ASSERT(false); + try { + FromString<ui32>(""); + UNIT_ASSERT(false); } catch (TFromStringException& e) { - CheckMessage(e, "empty string as number"); - } - - try { - FromString<ui32>("-"); - UNIT_ASSERT(false); + CheckMessage(e, "empty string as number"); + } + + try { + FromString<ui32>("-"); + UNIT_ASSERT(false); } catch (TFromStringException& e) { - // Unsigned should have no sign at all, so - is not expected - CheckMessage(e, "Unexpected symbol \"-\" at pos 0 in string \"-\""); - } - - try { - FromString<i32>("-"); - UNIT_ASSERT(false); + // Unsigned should have no sign at all, so - is not expected + CheckMessage(e, "Unexpected symbol \"-\" at pos 0 in string \"-\""); + } + + try { + FromString<i32>("-"); + UNIT_ASSERT(false); } catch (TFromStringException& e) { - CheckMessage(e, "Cannot parse string \"-\" as number"); - } - - try { - FromString<i32>("+"); - UNIT_ASSERT(false); + CheckMessage(e, "Cannot parse string \"-\" as number"); + } + + try { + FromString<i32>("+"); + UNIT_ASSERT(false); } catch (TFromStringException& e) { - CheckMessage(e, "Cannot parse string \"+\" as number"); - } - - try { - FromString<ui32>("0.328413745072"); - UNIT_ASSERT(false); + CheckMessage(e, "Cannot parse string \"+\" as number"); + } + + try { + FromString<ui32>("0.328413745072"); + UNIT_ASSERT(false); } catch (TFromStringException& e) { - CheckMessage(e, "Unexpected symbol \".\" at pos 1 in string \"0.328413745072\""); - } - } + CheckMessage(e, "Unexpected symbol \".\" at pos 1 in string \"0.328413745072\""); + } + } Y_UNIT_TEST(TryStringBuf) { { diff --git a/util/string/hex.h b/util/string/hex.h index c4605c6087..af3d2d528f 100644 --- a/util/string/hex.h +++ b/util/string/hex.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/string.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #include <util/system/yassert.h> inline static char DigitToChar(unsigned char digit) { diff --git a/util/string/strip.cpp b/util/string/strip.cpp index bcc63f0e81..c921571cf0 100644 --- a/util/string/strip.cpp +++ b/util/string/strip.cpp @@ -8,10 +8,10 @@ bool Collapse(const TString& from, TString& to, size_t maxLen) { } void CollapseText(const TString& from, TString& to, size_t maxLen) { - Collapse(from, to, maxLen); + Collapse(from, to, maxLen); StripInPlace(to); if (to.size() >= maxLen) { - to.remove(maxLen - 5); // " ..." + to.remove(maxLen - 5); // " ..." ReverseInPlace(to); size_t pos = to.find_first_of(" .,;"); if (pos != TString::npos && pos < 32) { diff --git a/util/string/strip.h b/util/string/strip.h index eb9b684941..d5ef6da96d 100644 --- a/util/string/strip.h +++ b/util/string/strip.h @@ -170,29 +170,29 @@ static inline T StripStringRight(const T& from) { template <class T, class TStripCriterion> static inline T StripStringLeft(const T& from, TStripCriterion&& criterion) { return TStripImpl<true, false>::StripString(from, criterion); -} - +} + template <class T, class TStripCriterion> static inline T StripStringRight(const T& from, TStripCriterion&& criterion) { return TStripImpl<false, true>::StripString(from, criterion); -} - +} + /// Copies the given string removing leading and trailing spaces. static inline bool Strip(const TString& from, TString& to) { - return StripString(from, to); -} + return StripString(from, to); +} /// Removes leading and trailing spaces from the string. inline TString& StripInPlace(TString& s) { - Strip(s, s); - return s; -} + Strip(s, s); + return s; +} /// Returns a copy of the given string with removed leading and trailing spaces. inline TString Strip(const TString& s) Y_WARN_UNUSED_RESULT; inline TString Strip(const TString& s) { TString ret = s; - Strip(ret, ret); + Strip(ret, ret); return ret; } @@ -234,7 +234,7 @@ bool Collapse(const TString& from, TString& to, size_t maxLen = 0); /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { - Collapse(s, s, maxLen); + Collapse(s, s, maxLen); return s; } @@ -242,7 +242,7 @@ inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT; inline TString Collapse(const TString& s, size_t maxLen) { TString ret; - Collapse(s, ret, maxLen); + Collapse(s, ret, maxLen); return ret; } @@ -252,6 +252,6 @@ void CollapseText(const TString& from, TString& to, size_t maxLen); /// @details An ellipsis is inserted at the end of the truncated line. inline void CollapseText(TString& s, size_t maxLen) { TString to; - CollapseText(s, to, maxLen); + CollapseText(s, to, maxLen); s = to; } diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index 0a6b8e362f..d1029d1498 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -6,25 +6,25 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { Y_UNIT_TEST(TestStrip) { - struct TTest { + struct TTest { const char* Str; const char* StripLeftRes; const char* StripRightRes; const char* StripRes; - }; - static const TTest tests[] = { - {" 012 ", "012 ", " 012", "012"}, - {" 012", "012", " 012", "012"}, - {"012\t\t", "012\t\t", "012", "012"}, - {"\t012\t", "012\t", "\t012", "012"}, - {"012", "012", "012", "012"}, - {"012\r\n", "012\r\n", "012", "012"}, - {"\n012\r", "012\r", "\n012", "012"}, - {"\n \t\r", "", "", ""}, - {"", "", "", ""}, - {"abc", "abc", "abc", "abc"}, - {"a c", "a c", "a c", "a c"}, - }; + }; + static const TTest tests[] = { + {" 012 ", "012 ", " 012", "012"}, + {" 012", "012", " 012", "012"}, + {"012\t\t", "012\t\t", "012", "012"}, + {"\t012\t", "012\t", "\t012", "012"}, + {"012", "012", "012", "012"}, + {"012\r\n", "012\r\n", "012", "012"}, + {"\n012\r", "012\r", "\n012", "012"}, + {"\n \t\r", "", "", ""}, + {"", "", "", ""}, + {"abc", "abc", "abc", "abc"}, + {"a c", "a c", "a c", "a c"}, + }; for (const auto& test : tests) { TString inputStr(test.Str); @@ -45,16 +45,16 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { } Y_UNIT_TEST(TestCustomStrip) { - struct TTest { + struct TTest { const char* Str; const char* Result; - }; - static const TTest tests[] = { - {"//012//", "012"}, - {"//012", "012"}, - {"012", "012"}, - {"012//", "012"}, - }; + }; + static const TTest tests[] = { + {"//012//", "012"}, + {"//012", "012"}, + {"012", "012"}, + {"012//", "012"}, + }; for (auto test : tests) { UNIT_ASSERT_EQUAL( @@ -64,28 +64,28 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { } Y_UNIT_TEST(TestCustomStripLeftRight) { - struct TTest { - const char* Str; - const char* ResultLeft; - const char* ResultRight; - }; - static const TTest tests[] = { - {"//012//", "012//", "//012"}, - {"//012", "012", "//012"}, - {"012", "012", "012"}, - {"012//", "012//", "012"}, - }; - + struct TTest { + const char* Str; + const char* ResultLeft; + const char* ResultRight; + }; + static const TTest tests[] = { + {"//012//", "012//", "//012"}, + {"//012", "012", "//012"}, + {"012", "012", "012"}, + {"012//", "012//", "012"}, + }; + for (const auto& test : tests) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( StripStringLeft(TString(test.Str), EqualsStripAdapter('/')), test.ResultLeft); - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( StripStringRight(TString(test.Str), EqualsStripAdapter('/')), test.ResultRight); - }; - } - + }; + } + Y_UNIT_TEST(TestNullStringStrip) { TStringBuf nullString(nullptr, nullptr); UNIT_ASSERT_EQUAL( @@ -128,11 +128,11 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { TString abs1("Very long description string written in unknown language."); TString abs2(abs1); TString abs3(abs1); - CollapseText(abs1, 204); - CollapseText(abs2, 54); - CollapseText(abs3, 49); - UNIT_ASSERT_EQUAL(abs1 == "Very long description string written in unknown language.", true); - UNIT_ASSERT_EQUAL(abs2 == "Very long description string written in unknown ...", true); - UNIT_ASSERT_EQUAL(abs3 == "Very long description string written in ...", true); + CollapseText(abs1, 204); + CollapseText(abs2, 54); + CollapseText(abs3, 49); + UNIT_ASSERT_EQUAL(abs1 == "Very long description string written in unknown language.", true); + UNIT_ASSERT_EQUAL(abs2 == "Very long description string written in unknown ...", true); + UNIT_ASSERT_EQUAL(abs3 == "Very long description string written in ...", true); } } diff --git a/util/string/subst.h b/util/string/subst.h index ab8ea56a56..45b622fbef 100644 --- a/util/string/subst.h +++ b/util/string/subst.h @@ -3,7 +3,7 @@ #include <util/generic/fwd.h> #include <stlfwd> - + /* Replace all occurences of substring `what` with string `with` starting from position `from`. * * @param text String to modify. @@ -18,7 +18,7 @@ size_t SubstGlobal(std::string& text, TStringBuf what, TStringBuf with, size_t f size_t SubstGlobal(TUtf16String& text, TWtringBuf what, TWtringBuf with, size_t from = 0); size_t SubstGlobal(std::u16string& text, TWtringBuf what, TWtringBuf with, size_t from = 0); size_t SubstGlobal(TUtf32String& text, TUtf32StringBuf what, TUtf32StringBuf with, size_t from = 0); - + /* Replace all occurences of character `what` with character `with` starting from position `from`. * * @param text String to modify. diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp index 04ca5cdf60..21eccef779 100644 --- a/util/string/subst_ut.cpp +++ b/util/string/subst_ut.cpp @@ -1,6 +1,6 @@ #include "join.h" #include "subst.h" -#include <string> +#include <string> #include <library/cpp/testing/unittest/registar.h> @@ -169,7 +169,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { SubstGlobal(s, 'a', 'b', 1); UNIT_ASSERT_EQUAL(s, TString("abb")); } - + Y_UNIT_TEST(TestSubstCharGlobalRet) { const TUtf16String w1 = u"abcdabcd"; const TUtf16String w2 = SubstGlobalCopy(w1, wchar16('b'), wchar16('B'), 3); @@ -181,10 +181,10 @@ Y_UNIT_TEST_SUITE(TStringSubst) { } Y_UNIT_TEST(TestSubstStdString) { - std::string s = "aaa"; - SubstGlobal(s, "a", "b", 1); - UNIT_ASSERT_EQUAL(s, "abb"); - } + std::string s = "aaa"; + SubstGlobal(s, "a", "b", 1); + UNIT_ASSERT_EQUAL(s, "abb"); + } Y_UNIT_TEST(TestSubstStdStringRet) { const std::string s1 = "aaa"; diff --git a/util/string/type_ut.cpp b/util/string/type_ut.cpp index 3916914e23..03e7af62bd 100644 --- a/util/string/type_ut.cpp +++ b/util/string/type_ut.cpp @@ -13,31 +13,31 @@ Y_UNIT_TEST_SUITE(TStringClassify) { } Y_UNIT_TEST(TestIsTrue) { - UNIT_ASSERT(IsTrue("1")); - UNIT_ASSERT(IsTrue("yes")); - UNIT_ASSERT(IsTrue("YeS")); - UNIT_ASSERT(IsTrue("on")); - UNIT_ASSERT(IsTrue("true")); + UNIT_ASSERT(IsTrue("1")); + UNIT_ASSERT(IsTrue("yes")); + UNIT_ASSERT(IsTrue("YeS")); + UNIT_ASSERT(IsTrue("on")); + UNIT_ASSERT(IsTrue("true")); UNIT_ASSERT(IsTrue("t")); - UNIT_ASSERT(IsTrue("da")); + UNIT_ASSERT(IsTrue("da")); UNIT_ASSERT(!IsTrue("")); UNIT_ASSERT(!IsTrue("tr")); - UNIT_ASSERT(!IsTrue("foobar")); + UNIT_ASSERT(!IsTrue("foobar")); } - + Y_UNIT_TEST(TestIsFalse) { - UNIT_ASSERT(IsFalse("0")); - UNIT_ASSERT(IsFalse("no")); - UNIT_ASSERT(IsFalse("off")); - UNIT_ASSERT(IsFalse("false")); + UNIT_ASSERT(IsFalse("0")); + UNIT_ASSERT(IsFalse("no")); + UNIT_ASSERT(IsFalse("off")); + UNIT_ASSERT(IsFalse("false")); UNIT_ASSERT(IsFalse("f")); - UNIT_ASSERT(IsFalse("net")); - + UNIT_ASSERT(IsFalse("net")); + UNIT_ASSERT(!IsFalse("")); UNIT_ASSERT(!IsFalse("fa")); - UNIT_ASSERT(!IsFalse("foobar")); - } + UNIT_ASSERT(!IsFalse("foobar")); + } Y_UNIT_TEST(TestIsNumber) { UNIT_ASSERT(IsNumber("0")); diff --git a/util/system/compiler.h b/util/system/compiler.h index 95a67945d7..b373edcc46 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -287,7 +287,7 @@ _YandexAbort(); #endif #else - + #if defined(thread_sanitizer_enabled) || defined(__SANITIZE_THREAD__) #define _tsan_enabled_ #endif diff --git a/util/system/datetime.h b/util/system/datetime.h index d3982a047c..aa009974e0 100644 --- a/util/system/datetime.h +++ b/util/system/datetime.h @@ -17,14 +17,14 @@ /// Current time in microseconds since epoch ui64 MicroSeconds() noexcept; -/// Current time in milliseconds since epoch -inline ui64 MilliSeconds() { - return MicroSeconds() / ui64(1000); -} -/// Current time in milliseconds since epoch (deprecated, use MilliSeconds instead) -inline ui64 millisec() { - return MilliSeconds(); -} +/// Current time in milliseconds since epoch +inline ui64 MilliSeconds() { + return MicroSeconds() / ui64(1000); +} +/// Current time in milliseconds since epoch (deprecated, use MilliSeconds instead) +inline ui64 millisec() { + return MilliSeconds(); +} /// Current time in seconds since epoch ui32 Seconds() noexcept; ///Current thread time in microseconds diff --git a/util/system/direct_io_ut.cpp b/util/system/direct_io_ut.cpp index a3c56fbd96..839c3de7ca 100644 --- a/util/system/direct_io_ut.cpp +++ b/util/system/direct_io_ut.cpp @@ -23,19 +23,19 @@ Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { writePos += writeCount; size_t readPos = RandomNumber(writePos); size_t readCount = RandomNumber(writePos - readPos); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( file.Pread(&readResult[0], readCount * sizeof(ui64), readPos * sizeof(ui64)), readCount * sizeof(ui64)); - for (size_t i = 0; i < readCount; ++i) { + for (size_t i = 0; i < readCount; ++i) { UNIT_ASSERT_VALUES_EQUAL(readResult[i], data[i + readPos]); - } + } } file.Finish(); TDirectIOBufferedFile fileNew(FileName_, RdOnly | Direct | Seq | OpenAlways, 1 << 15); for (int i = 0; i < 1000; ++i) { size_t readPos = RandomNumber(data.size()); size_t readCount = RandomNumber(data.size() - readPos); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( fileNew.Pread(&readResult[0], readCount * sizeof(ui64), readPos * sizeof(ui64)), readCount * sizeof(ui64)); for (size_t j = 0; j < readCount; ++j) { @@ -43,12 +43,12 @@ Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { } } size_t readCount = data.size(); - UNIT_ASSERT_VALUES_EQUAL( + UNIT_ASSERT_VALUES_EQUAL( fileNew.Pread(&readResult[0], readCount * sizeof(ui64), 0), readCount * sizeof(ui64)); - for (size_t i = 0; i < readCount; ++i) { + for (size_t i = 0; i < readCount; ++i) { UNIT_ASSERT_VALUES_EQUAL(readResult[i], data[i]); - } + } NFs::Remove(FileName_); } diff --git a/util/system/env.cpp b/util/system/env.cpp index edc539a702..ead9b566a5 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -1,8 +1,8 @@ -#include "env.h" - +#include "env.h" + #include <util/generic/string.h> #include <util/generic/yexception.h> - + #ifdef _win_ #include <util/generic/vector.h> #include "winint.h" @@ -10,7 +10,7 @@ #include <cerrno> #include <cstdlib> #endif - + /** * On Windows there may be many copies of enviroment variables, there at least two known, one is * manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of @@ -22,7 +22,7 @@ */ TString GetEnv(const TString& key, const TString& def) { -#ifdef _win_ +#ifdef _win_ size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0); if (len == 0) { @@ -43,25 +43,25 @@ TString GetEnv(const TString& key, const TString& def) { } while (len > bufferSize); return TString(buffer.data(), len); -#else +#else const char* env = getenv(key.data()); return env ? TString(env) : def; -#endif -} - +#endif +} + void SetEnv(const TString& key, const TString& value) { bool isOk = false; int errorCode = 0; -#ifdef _win_ +#ifdef _win_ isOk = SetEnvironmentVariable(key.data(), value.data()); if (!isOk) { errorCode = GetLastError(); } -#else +#else isOk = (0 == setenv(key.data(), value.data(), true /*replace*/)); if (!isOk) { errorCode = errno; } -#endif +#endif Y_ENSURE_EX(isOk, TSystemError() << "failed to SetEnv with error-code " << errorCode); -} +} diff --git a/util/system/env.h b/util/system/env.h index 6af09425be..e2ccdd1e95 100644 --- a/util/system/env.h +++ b/util/system/env.h @@ -1,7 +1,7 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> - + /** * Search the environment list provided by the host environment for associated variable. * diff --git a/util/system/env_ut.cpp b/util/system/env_ut.cpp index 32e3a39956..e03cc01658 100644 --- a/util/system/env_ut.cpp +++ b/util/system/env_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/testing/unittest/registar.h> - + #include <util/generic/string.h> #include "env.h" - + Y_UNIT_TEST_SUITE(EnvTest) { Y_UNIT_TEST(GetSetEnvTest) { TString key = "util_GETENV_TestVar"; @@ -28,4 +28,4 @@ Y_UNIT_TEST_SUITE(EnvTest) { SetEnv(longKey, TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); } -} +} diff --git a/util/system/execpath.h b/util/system/execpath.h index 5c476042c7..4b914b8e85 100644 --- a/util/system/execpath.h +++ b/util/system/execpath.h @@ -2,7 +2,7 @@ #include <util/generic/fwd.h> -// NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297 +// NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297 const TString& GetExecPath(); /** diff --git a/util/system/file_lock.cpp b/util/system/file_lock.cpp index 55160d287f..45d91282c5 100644 --- a/util/system/file_lock.cpp +++ b/util/system/file_lock.cpp @@ -1,8 +1,8 @@ -#include "file_lock.h" +#include "file_lock.h" #include "flock.h" - + #include <util/generic/yexception.h> - + #include <cerrno> namespace { @@ -22,13 +22,13 @@ namespace { TFileLock::TFileLock(const TString& filename, const EFileLockType type) : TFile(filename, OpenAlways | RdOnly) , Type(type) -{ -} - -void TFileLock::Acquire() { +{ +} + +void TFileLock::Acquire() { Flock(GetMode(Type)); -} - +} + bool TFileLock::TryAcquire() { try { Flock(GetMode(Type) | LOCK_NB); @@ -41,6 +41,6 @@ bool TFileLock::TryAcquire() { } } -void TFileLock::Release() { - Flock(LOCK_UN); -} +void TFileLock::Release() { + Flock(LOCK_UN); +} diff --git a/util/system/file_lock.h b/util/system/file_lock.h index ac3f95306f..b2aaff5baf 100644 --- a/util/system/file_lock.h +++ b/util/system/file_lock.h @@ -1,9 +1,9 @@ -#pragma once - +#pragma once + #include <util/generic/fwd.h> -#include <util/generic/noncopyable.h> +#include <util/generic/noncopyable.h> #include <util/system/file.h> - + enum class EFileLockType { Exclusive, Shared @@ -13,9 +13,9 @@ class TFileLock: public TFile { public: TFileLock(const TString& filename, const EFileLockType type = EFileLockType::Exclusive); - void Acquire(); + void Acquire(); bool TryAcquire(); - void Release(); + void Release(); inline void lock() { Acquire(); @@ -31,4 +31,4 @@ public: private: EFileLockType Type; -}; +}; diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index cfab1b6aca..7454a4cb94 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -74,7 +74,7 @@ namespace { TString TMemoryMapCommon::UnknownFileName() { return "Unknown_file_name"; } - + static inline i64 DownToGranularity(i64 offset) noexcept { return offset & ~((i64)(GRANULARITY - 1)); } diff --git a/util/system/filemap.h b/util/system/filemap.h index a6e97dabaf..11be64bff4 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -59,8 +59,8 @@ struct TMemoryMapCommon { oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) }; Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) - - /** + + /** * Name that will be printed in exceptions if not specified. * Overridden by name obtained from `TFile` if it's not empty. */ @@ -184,16 +184,16 @@ private: }; template <class T> -class TFileMappedArray { -private: - const T* Ptr_; - const T* End_; +class TFileMappedArray { +private: + const T* Ptr_; + const T* End_; size_t Size_; char DummyData_[sizeof(T) + PLATFORM_DATA_ALIGN]; mutable THolder<T, TDestructor> Dummy_; - THolder<TFileMap> DataHolder_; + THolder<TFileMap> DataHolder_; -public: +public: TFileMappedArray() : Ptr_(nullptr) , End_(nullptr) @@ -204,34 +204,34 @@ public: Ptr_ = nullptr; End_ = nullptr; } - void Init(const char* name) { - DataHolder_.Reset(new TFileMap(name)); - DoInit(name); + void Init(const char* name) { + DataHolder_.Reset(new TFileMap(name)); + DoInit(name); + } + void Init(const TFileMap& fileMap) { + DataHolder_.Reset(new TFileMap(fileMap)); + DoInit(fileMap.GetFile().GetName()); } - void Init(const TFileMap& fileMap) { - DataHolder_.Reset(new TFileMap(fileMap)); - DoInit(fileMap.GetFile().GetName()); - } - void Term() { - DataHolder_.Destroy(); + void Term() { + DataHolder_.Destroy(); Ptr_ = nullptr; Size_ = 0; End_ = nullptr; } - void Precharge() { - DataHolder_->Precharge(); - } + void Precharge() { + DataHolder_->Precharge(); + } const T& operator[](size_t pos) const { Y_ASSERT(pos < size()); return Ptr_[pos]; } - /// for STL compatibility only, Size() usage is recommended + /// for STL compatibility only, Size() usage is recommended size_t size() const { return Size_; } - size_t Size() const { - return Size_; - } + size_t Size() const { + return Size_; + } const T& GetAt(size_t pos) const { if (pos < Size_) return Ptr_[pos]; @@ -251,40 +251,40 @@ public: return *Dummy_; } - /// for STL compatibility only, Empty() usage is recommended + /// for STL compatibility only, Empty() usage is recommended Y_PURE_FUNCTION bool empty() const noexcept { - return Empty(); - } + return Empty(); + } Y_PURE_FUNCTION bool Empty() const noexcept { return 0 == Size_; } - /// for STL compatibility only, Begin() usage is recommended + /// for STL compatibility only, Begin() usage is recommended const T* begin() const noexcept { - return Begin(); - } + return Begin(); + } const T* Begin() const noexcept { return Ptr_; } - /// for STL compatibility only, End() usage is recommended + /// for STL compatibility only, End() usage is recommended const T* end() const noexcept { return End_; } const T* End() const noexcept { - return End_; - } + return End_; + } -private: +private: void DoInit(const TString& fileName) { - DataHolder_->Map(0, DataHolder_->Length()); - if (DataHolder_->Length() % sizeof(T)) { - Term(); - ythrow yexception() << "Incorrect size of file " << fileName.Quote(); - } - Ptr_ = (const T*)DataHolder_->Ptr(); - Size_ = DataHolder_->Length() / sizeof(T); - End_ = Ptr_ + Size_; - } + DataHolder_->Map(0, DataHolder_->Length()); + if (DataHolder_->Length() % sizeof(T)) { + Term(); + ythrow yexception() << "Incorrect size of file " << fileName.Quote(); + } + Ptr_ = (const T*)DataHolder_->Ptr(); + Size_ = DataHolder_->Length() / sizeof(T); + End_ = Ptr_ + Size_; + } }; class TMappedAllocation: TMoveOnly { diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 62755f7547..73f109dc88 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -12,7 +12,7 @@ #include <cstdio> Y_UNIT_TEST_SUITE(TFileMapTest) { - static const char* FileName_("./mappped_file"); + static const char* FileName_("./mappped_file"); void BasicTest(TMemoryMapCommon::EOpenMode mode) { char data[] = "abcdefgh"; @@ -132,7 +132,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { //cygwin is not real unix :( #else Y_UNIT_TEST(TestNotGreedy) { - unsigned page[4096 / sizeof(unsigned)]; + unsigned page[4096 / sizeof(unsigned)]; #if defined(_unix_) // Temporary limit allowed virtual memory size to 1Gb @@ -221,49 +221,49 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { file.Write(static_cast<void*>(data), sizeof(data)); file.Close(); - mappedArray.Init(FileName_); - // actual test begin - UNIT_ASSERT(mappedArray.Size() == sz); + mappedArray.Init(FileName_); + // actual test begin + UNIT_ASSERT(mappedArray.Size() == sz); for (size_t i = 0; i < sz; ++i) { UNIT_ASSERT(mappedArray[i] == data[i]); } - - UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); - UNIT_ASSERT(*mappedArray.Begin() == data[0]); - UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); - UNIT_ASSERT(!mappedArray.Empty()); - // actual test end - mappedArray.Term(); - - // Init array via file mapping - TFileMap fileMap(FileName_); - fileMap.Map(0, fileMap.Length()); - mappedArray.Init(fileMap); - - // actual test begin - UNIT_ASSERT(mappedArray.Size() == sz); + + UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); + UNIT_ASSERT(*mappedArray.Begin() == data[0]); + UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); + UNIT_ASSERT(!mappedArray.Empty()); + // actual test end + mappedArray.Term(); + + // Init array via file mapping + TFileMap fileMap(FileName_); + fileMap.Map(0, fileMap.Length()); + mappedArray.Init(fileMap); + + // actual test begin + UNIT_ASSERT(mappedArray.Size() == sz); for (size_t i = 0; i < sz; ++i) { - UNIT_ASSERT(mappedArray[i] == data[i]); + UNIT_ASSERT(mappedArray[i] == data[i]); } - - UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); - UNIT_ASSERT(*mappedArray.Begin() == data[0]); - UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); - UNIT_ASSERT(!mappedArray.Empty()); - // actual test end - + + UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); + UNIT_ASSERT(*mappedArray.Begin() == data[0]); + UNIT_ASSERT(size_t(mappedArray.End() - mappedArray.Begin()) == sz); + UNIT_ASSERT(!mappedArray.Empty()); + // actual test end + file = TFile(FileName_, WrOnly); file.Seek(0, sEnd); file.Write("x", 1); file.Close(); - bool caught = false; + bool caught = false; try { - mappedArray.Init(FileName_); + mappedArray.Init(FileName_); } catch (const yexception&) { - caught = true; + caught = true; } - UNIT_ASSERT(caught); + UNIT_ASSERT(caught); } NFs::Remove(FileName_); } @@ -291,32 +291,32 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { } Y_UNIT_TEST(TestMemoryMap) { - TFile file(FileName_, CreateAlways | WrOnly); - file.Close(); - - FILE* f = fopen(FileName_, "rb"); + TFile file(FileName_, CreateAlways | WrOnly); + file.Close(); + + FILE* f = fopen(FileName_, "rb"); UNIT_ASSERT(f != nullptr); - try { - TMemoryMap mappedMem(f); - mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow + try { + TMemoryMap mappedMem(f); + mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { TString text = exc.what(); // exception should contain failed file name UNIT_ASSERT(text.find(TMemoryMapCommon::UnknownFileName()) != TString::npos); - fclose(f); - } - - TFile fileForMap(FileName_, OpenExisting); - try { - TMemoryMap mappedMem(fileForMap); - mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow + fclose(f); + } + + TFile fileForMap(FileName_, OpenExisting); + try { + TMemoryMap mappedMem(fileForMap); + mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow UNIT_ASSERT(0); // should not go here } catch (yexception& exc) { TString text = exc.what(); // exception should contain failed file name UNIT_ASSERT(text.find(FileName_) != TString::npos); - } + } NFs::Remove(FileName_); - } + } Y_UNIT_TEST(TestMemoryMapIsWritable) { TFile file(FileName_, CreateAlways | WrOnly); diff --git a/util/system/flock.h b/util/system/flock.h index 210e834825..797b1970a1 100644 --- a/util/system/flock.h +++ b/util/system/flock.h @@ -2,7 +2,7 @@ #include "error.h" #include "defaults.h" -#include "file.h" +#include "file.h" #if defined(_unix_) @@ -13,7 +13,7 @@ static inline int Flock(int fd, int op) { return flock(fd, op); } -#else // not _unix_ +#else // not _unix_ #ifdef __cplusplus extern "C" { @@ -32,4 +32,4 @@ extern "C" { } #endif -#endif // not _unix_ +#endif // not _unix_ diff --git a/util/system/flock_ut.cpp b/util/system/flock_ut.cpp index 2bb705944c..b5f6cb5328 100644 --- a/util/system/flock_ut.cpp +++ b/util/system/flock_ut.cpp @@ -1,6 +1,6 @@ #include "flock.h" -#include "file_lock.h" -#include "guard.h" +#include "file_lock.h" +#include "guard.h" #include "tempfile.h" #include <library/cpp/testing/unittest/registar.h> @@ -14,15 +14,15 @@ Y_UNIT_TEST_SUITE(TFileLockTest) { } Y_UNIT_TEST(TestFileLocker) { - TTempFileHandle tmp("./file.locker"); + TTempFileHandle tmp("./file.locker"); TFileLock fileLockExclusive1("./file.locker"); TFileLock fileLockExclusive2("./file.locker"); TFileLock fileLockShared1("./file.locker", EFileLockType::Shared); TFileLock fileLockShared2("./file.locker", EFileLockType::Shared); TFileLock fileLockShared3("./file.locker", EFileLockType::Shared); - { + { TGuard<TFileLock> guard(fileLockExclusive1); - } + } { TTryGuard<TFileLock> tryGuard(fileLockExclusive1); UNIT_ASSERT(tryGuard.WasAcquired()); @@ -53,5 +53,5 @@ Y_UNIT_TEST_SUITE(TFileLockTest) { UNIT_ASSERT(!guard2.WasAcquired()); UNIT_ASSERT(guard3.WasAcquired()); } - } -} + } +} diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 27f0de682b..81e98cbc6b 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -3,7 +3,7 @@ #include <sys/stat.h> -#include <util/folder/path.h> +#include <util/folder/path.h> #include <cerrno> @@ -82,7 +82,7 @@ static bool GetStatByHandle(TSystemFStat& fs, FHANDLE f) { #endif } -static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) { +static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) { #ifdef _win_ TFileHandle h = NFsPrivate::CreateFileWithUtf8Name(fileName, FILE_READ_ATTRIBUTES | FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, @@ -92,7 +92,7 @@ static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) } return GetStatByHandle(fs, h); #else - return !(nofollow ? lstat : stat)(fileName, &fs); + return !(nofollow ? lstat : stat)(fileName, &fs); #endif } @@ -111,27 +111,27 @@ TFileStat::TFileStat(FHANDLE f) { } } -void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) { +void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) { TSystemFStat st; - if (GetStatByName(st, fileName, nofollow)) { + if (GetStatByName(st, fileName, nofollow)) { MakeStat(*this, st); } else { *this = TFileStat(); } } -TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) { +TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) { MakeFromFileName(fileName.GetPath().data(), nofollow); -} - +} + TFileStat::TFileStat(const TString& fileName, bool nofollow) { MakeFromFileName(fileName.data(), nofollow); -} - -TFileStat::TFileStat(const char* fileName, bool nofollow) { - MakeFromFileName(fileName, nofollow); -} - +} + +TFileStat::TFileStat(const char* fileName, bool nofollow) { + MakeFromFileName(fileName, nofollow); +} + bool TFileStat::IsNull() const noexcept { return *this == TFileStat(); } diff --git a/util/system/fstat.h b/util/system/fstat.h index b9ef3f3987..64e79e1b55 100644 --- a/util/system/fstat.h +++ b/util/system/fstat.h @@ -4,7 +4,7 @@ #include <util/system/fhandle.h> class TFile; -class TFsPath; +class TFsPath; struct TFileStat { ui32 Mode = 0; /* protection */ @@ -29,17 +29,17 @@ public: bool IsDir() const noexcept; bool IsSymlink() const noexcept; - explicit TFileStat(const TFile& f); - explicit TFileStat(FHANDLE f); - TFileStat(const TFsPath& fileName, bool nofollow = false); + explicit TFileStat(const TFile& f); + explicit TFileStat(FHANDLE f); + TFileStat(const TFsPath& fileName, bool nofollow = false); TFileStat(const TString& fileName, bool nofollow = false); - TFileStat(const char* fileName, bool nofollow = false); + TFileStat(const char* fileName, bool nofollow = false); friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept; friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept; -private: - void MakeFromFileName(const char* fileName, bool nofollow); +private: + void MakeFromFileName(const char* fileName, bool nofollow); }; i64 GetFileLength(FHANDLE fd); diff --git a/util/system/info.cpp b/util/system/info.cpp index 0d4ac42885..cf6681e89a 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -148,9 +148,9 @@ size_t NSystemInfo::LoadAverage(double* la, size_t len) { #if defined(_win_) || defined(_musl_) || defined(_bionic_) int ret = -1; #else - for (size_t i = 0; i < len; ++i) { - la[i] = 0; - } + for (size_t i = 0; i < len; ++i) { + la[i] = 0; + } int ret = getloadavg(la, len); #endif diff --git a/util/system/platform.h b/util/system/platform.h index c3b2dd33b2..58f310ab34 100644 --- a/util/system/platform.h +++ b/util/system/platform.h @@ -1,84 +1,84 @@ #pragma once -// ya style breaks indentation in ifdef's and code becomes unreadable -// clang-format off - +// ya style breaks indentation in ifdef's and code becomes unreadable +// clang-format off + // What OS ? // our definition has the form _{osname}_ #if defined(_WIN64) - #define _win64_ - #define _win32_ + #define _win64_ + #define _win32_ #elif defined(__WIN32__) || defined(_WIN32) // _WIN32 is also defined by the 64-bit compiler for backward compatibility - #define _win32_ + #define _win32_ #else - #define _unix_ - - #if defined(__sun__) || defined(sun) || defined(sparc) || defined(__sparc) - #define _sun_ - #endif - - #if defined(__hpux__) - #define _hpux_ - #endif - - #if defined(__linux__) - // Stands for "Linux" in the means of Linux kernel (i. e. Android is included) - #define _linux_ - #endif - - #if defined(__FreeBSD__) - #define _freebsd_ - #endif - - #if defined(__CYGWIN__) - #define _cygwin_ - #endif - - #if defined(__APPLE__) - #define _darwin_ - #endif - - #if defined(__ANDROID__) - #define _android_ - #endif + #define _unix_ + + #if defined(__sun__) || defined(sun) || defined(sparc) || defined(__sparc) + #define _sun_ + #endif + + #if defined(__hpux__) + #define _hpux_ + #endif + + #if defined(__linux__) + // Stands for "Linux" in the means of Linux kernel (i. e. Android is included) + #define _linux_ + #endif + + #if defined(__FreeBSD__) + #define _freebsd_ + #endif + + #if defined(__CYGWIN__) + #define _cygwin_ + #endif + + #if defined(__APPLE__) + #define _darwin_ + #endif + + #if defined(__ANDROID__) + #define _android_ + #endif #endif #if defined(__IOS__) - #define _ios_ + #define _ios_ #endif #if defined(_linux_) - #if defined(_musl_) - // nothing to do - #elif defined(_android_) - // Please do not mix with android-based systems. - // This definition describes Standard Library (libc) type. - #define _bionic_ - #else - #define _glibc_ - #endif + #if defined(_musl_) + // nothing to do + #elif defined(_android_) + // Please do not mix with android-based systems. + // This definition describes Standard Library (libc) type. + #define _bionic_ + #else + #define _glibc_ + #endif #endif #if defined(_darwin_) - #define unix - #define __unix__ + #define unix + #define __unix__ #endif #if defined(_win32_) || defined(_win64_) - #define _win_ + #define _win_ #endif #if defined(__arm__) || defined(__ARM__) || defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM) - #if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) - #define _arm64_ - #else - #define _arm32_ - #endif + #if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) + #define _arm64_ + #else + #define _arm32_ + #endif #endif #if defined(_arm64_) || defined(_arm32_) - #define _arm_ + #define _arm_ #endif /* __ia64__ and __x86_64__ - defined by GNU C. @@ -88,105 +88,105 @@ * or _M_X64 (starting in Visual Studio 8). */ #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) - #define _x86_64_ + #define _x86_64_ #endif #if defined(__i386__) || defined(_M_IX86) - #define _i386_ + #define _i386_ #endif #if defined(__ia64__) || defined(_M_IA64) - #define _ia64_ + #define _ia64_ #endif #if defined(__powerpc__) - #define _ppc_ + #define _ppc_ #endif #if defined(__powerpc64__) - #define _ppc64_ + #define _ppc64_ #endif #if !defined(sparc) && !defined(__sparc) && !defined(__hpux__) && !defined(__alpha__) && !defined(_ia64_) && !defined(_x86_64_) && !defined(_arm_) && !defined(_i386_) && !defined(_ppc_) && !defined(_ppc64_) - #error "platform not defined, please, define one" + #error "platform not defined, please, define one" #endif #if defined(_x86_64_) || defined(_i386_) - #define _x86_ + #define _x86_ #endif #if defined(__MIC__) - #define _mic_ - #define _k1om_ + #define _mic_ + #define _k1om_ #endif // stdio or MessageBox #if defined(__CONSOLE__) || defined(_CONSOLE) - #define _console_ + #define _console_ #endif #if (defined(_win_) && !defined(_console_)) - #define _windows_ + #define _windows_ #elif !defined(_console_) - #define _console_ + #define _console_ #endif #if defined(__SSE__) || defined(SSE_ENABLED) - #define _sse_ + #define _sse_ #endif #if defined(__SSE2__) || defined(SSE2_ENABLED) - #define _sse2_ + #define _sse2_ #endif #if defined(__SSE3__) || defined(SSE3_ENABLED) - #define _sse3_ + #define _sse3_ #endif #if defined(__SSSE3__) || defined(SSSE3_ENABLED) - #define _ssse3_ + #define _ssse3_ #endif #if defined(__SSE4_1__) || defined(SSE41_ENABLED) - #define _sse4_1_ + #define _sse4_1_ #endif #if defined(__SSE4_2__) || defined(SSE42_ENABLED) - #define _sse4_2_ + #define _sse4_2_ #endif #if defined(__POPCNT__) || defined(POPCNT_ENABLED) - #define _popcnt_ + #define _popcnt_ #endif #if defined(__PCLMUL__) || defined(PCLMUL_ENABLED) - #define _pclmul_ + #define _pclmul_ #endif #if defined(__AES__) || defined(AES_ENABLED) - #define _aes_ + #define _aes_ #endif #if defined(__AVX__) || defined(AVX_ENABLED) - #define _avx_ + #define _avx_ #endif #if defined(__AVX2__) || defined(AVX2_ENABLED) - #define _avx2_ + #define _avx2_ #endif #if defined(__FMA__) || defined(FMA_ENABLED) - #define _fma_ + #define _fma_ #endif #if defined(__DLL__) || defined(_DLL) - #define _dll_ + #define _dll_ #endif // 16, 32 or 64 #if defined(__sparc_v9__) || defined(_x86_64_) || defined(_ia64_) || defined(_arm64_) || defined(_ppc64_) - #define _64_ + #define _64_ #else - #define _32_ + #define _32_ #endif /* All modern 64-bit Unix systems use scheme LP64 (long, pointers are 64-bit). @@ -202,15 +202,15 @@ */ #if defined(_32_) - #define SIZEOF_PTR 4 + #define SIZEOF_PTR 4 #elif defined(_64_) - #define SIZEOF_PTR 8 + #define SIZEOF_PTR 8 #endif #define PLATFORM_DATA_ALIGN SIZEOF_PTR #if !defined(SIZEOF_PTR) - #error todo + #error todo #endif #define SIZEOF_CHAR 1 @@ -221,20 +221,20 @@ #define SIZEOF_UNSIGNED_INT 4 #if defined(_32_) - #define SIZEOF_LONG 4 - #define SIZEOF_UNSIGNED_LONG 4 + #define SIZEOF_LONG 4 + #define SIZEOF_UNSIGNED_LONG 4 #elif defined(_64_) - #if defined(_win_) - #define SIZEOF_LONG 4 - #define SIZEOF_UNSIGNED_LONG 4 - #else - #define SIZEOF_LONG 8 - #define SIZEOF_UNSIGNED_LONG 8 - #endif // _win_ + #if defined(_win_) + #define SIZEOF_LONG 4 + #define SIZEOF_UNSIGNED_LONG 4 + #else + #define SIZEOF_LONG 8 + #define SIZEOF_UNSIGNED_LONG 8 + #endif // _win_ #endif // _32_ #if !defined(SIZEOF_LONG) - #error todo + #error todo #endif #define SIZEOF_LONG_LONG 8 @@ -243,4 +243,4 @@ #undef SIZEOF_SIZE_T // in case we include <Python.h> which defines it, too #define SIZEOF_SIZE_T SIZEOF_PTR -// clang-format on +// clang-format on diff --git a/util/system/protect.cpp b/util/system/protect.cpp index 615a8231bb..bbb8d410df 100644 --- a/util/system/protect.cpp +++ b/util/system/protect.cpp @@ -1,66 +1,66 @@ -#include "protect.h" - -#include <util/generic/yexception.h> +#include "protect.h" + +#include <util/generic/yexception.h> #include <util/generic/string.h> -#include <util/stream/output.h> - -#include "yassert.h" - +#include <util/stream/output.h> + +#include "yassert.h" + #if defined(_unix_) || defined(_darwin_) #include <sys/mman.h> -#endif - -#ifdef _win_ +#endif + +#ifdef _win_ #include <Windows.h> -#endif - +#endif + static TString ModeToString(const EProtectMemory mode) { TString strMode; if (mode == PM_NONE) { - return "PM_NONE"; + return "PM_NONE"; } - + if (mode & PM_READ) { - strMode += "PM_READ|"; + strMode += "PM_READ|"; } if (mode & PM_WRITE) { - strMode += "PM_WRITE|"; + strMode += "PM_WRITE|"; } if (mode & PM_EXEC) { - strMode += "PM_EXEC|"; + strMode += "PM_EXEC|"; } return strMode.substr(0, strMode.size() - 1); -} - +} + void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { Y_VERIFY(!(mode & ~(PM_READ | PM_WRITE | PM_EXEC)), "Invalid memory protection flag combination. "); - -#if defined(_unix_) || defined(_darwin_) - int mpMode = PROT_NONE; + +#if defined(_unix_) || defined(_darwin_) + int mpMode = PROT_NONE; if (mode & PM_READ) { - mpMode |= PROT_READ; + mpMode |= PROT_READ; } if (mode & PM_WRITE) { - mpMode |= PROT_WRITE; + mpMode |= PROT_WRITE; } if (mode & PM_EXEC) { - mpMode |= PROT_EXEC; + mpMode |= PROT_EXEC; } - // some old manpages for mprotect say 'const void* addr', but that's wrong + // some old manpages for mprotect say 'const void* addr', but that's wrong if (mprotect(addr, length, mpMode) == -1) { - ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; + ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; } -#endif - -#ifdef _win_ - DWORD mpMode = PAGE_NOACCESS; +#endif + +#ifdef _win_ + DWORD mpMode = PAGE_NOACCESS; // windows developers are not aware of bit flags :( - - /* - * It's unclear that we should NOT fail on Windows that does not support write-only - * memory protection. As we don't know, what behavior is more correct, we choose - * one of them. A discussion was here: REVIEW: 39725 - */ + + /* + * It's unclear that we should NOT fail on Windows that does not support write-only + * memory protection. As we don't know, what behavior is more correct, we choose + * one of them. A discussion was here: REVIEW: 39725 + */ switch (mode.ToBaseType()) { case PM_READ: mpMode = PAGE_READONLY; @@ -68,8 +68,8 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { case PM_WRITE: mpMode = PAGE_READWRITE; break; // BUG: no write-only support - /*case PM_WRITE: - ythrow TSystemError() << "Write-only protection mode is not supported under Windows. ";*/ + /*case PM_WRITE: + ythrow TSystemError() << "Write-only protection mode is not supported under Windows. ";*/ case PM_READ | PM_WRITE: mpMode = PAGE_READWRITE; break; @@ -82,14 +82,14 @@ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) { case PM_WRITE | PM_EXEC: mpMode = PAGE_EXECUTE_READWRITE; break; // BUG: no write-only support - /*case PM_WRITE | PM_EXEC: - ythrow TSystemError() << "Write-execute-only protection mode is not supported under Windows. ";*/ + /*case PM_WRITE | PM_EXEC: + ythrow TSystemError() << "Write-execute-only protection mode is not supported under Windows. ";*/ case PM_READ | PM_WRITE | PM_EXEC: mpMode = PAGE_EXECUTE_READWRITE; break; - } - DWORD oldMode = 0; - if (!VirtualProtect(addr, length, mpMode, &oldMode)) - ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; -#endif -} + } + DWORD oldMode = 0; + if (!VirtualProtect(addr, length, mpMode, &oldMode)) + ythrow TSystemError() << "Memory protection failed for mode " << ModeToString(mode) << ". "; +#endif +} diff --git a/util/system/protect.h b/util/system/protect.h index da024548de..26714f3e92 100644 --- a/util/system/protect.h +++ b/util/system/protect.h @@ -1,25 +1,25 @@ -#pragma once - +#pragma once + #include "defaults.h" - + #include <util/generic/flags.h> -enum EProtectMemoryMode { +enum EProtectMemoryMode { PM_NONE = 0x00, // no access allowed PM_READ = 0x01, // read access allowed - PM_WRITE = 0x02, // write access allowed + PM_WRITE = 0x02, // write access allowed PM_EXEC = 0x04 // execute access allowed -}; - +}; + Y_DECLARE_FLAGS(EProtectMemory, EProtectMemoryMode) Y_DECLARE_OPERATORS_FOR_FLAGS(EProtectMemory) -/** - * Set protection mode on memory block - * @param addr Block address to be protected - * @param length Block size in bytes - * @param mode A bitwise combination of @c EProtectMemoryMode flags - * @note On Windows there is no write-only protection mode, - * so PM_WRITE will be translated to (PM_READ | PM_WRITE) on Windows. - **/ +/** + * Set protection mode on memory block + * @param addr Block address to be protected + * @param length Block size in bytes + * @param mode A bitwise combination of @c EProtectMemoryMode flags + * @note On Windows there is no write-only protection mode, + * so PM_WRITE will be translated to (PM_READ | PM_WRITE) on Windows. + **/ void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode); diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index 45588154ad..b1989b5c8c 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -508,8 +508,8 @@ public: } return nullptr; } - - TString GetQuotedCommand() const; + + TString GetQuotedCommand() const; }; #if defined(_win_) @@ -1194,7 +1194,7 @@ TShellCommand& TShellCommand::CloseInput() { Impl->CloseInput(); return *this; } - -TString TShellCommand::GetQuotedCommand() const { - return Impl->GetQuotedCommand(); -} + +TString TShellCommand::GetQuotedCommand() const { + return Impl->GetQuotedCommand(); +} diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 0e2a232538..8730627fe5 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -464,11 +464,11 @@ public: */ TShellCommand& CloseInput(); - /** - * @brief Get quoted command (for debug/view purposes only!) - **/ - TString GetQuotedCommand() const; - + /** + * @brief Get quoted command (for debug/view purposes only!) + **/ + TString GetQuotedCommand() const; + private: class TImpl; using TImplRef = TSimpleIntrusivePtr<TImpl>; diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 412ba161e6..9d849279d2 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -80,8 +80,8 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput(), "hello" NL); UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); - - UNIT_ASSERT_VALUES_EQUAL(cmd.GetQuotedCommand(), "echo hello"); + + UNIT_ASSERT_VALUES_EQUAL(cmd.GetQuotedCommand(), "echo hello"); } Y_UNIT_TEST(TestOnlyNecessaryQuotes) { diff --git a/util/thread/lfqueue_ut.cpp b/util/thread/lfqueue_ut.cpp index d266848f22..83bca100cf 100644 --- a/util/thread/lfqueue_ut.cpp +++ b/util/thread/lfqueue_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/generic/algorithm.h> -#include <util/generic/vector.h> -#include <util/generic/ptr.h> +#include <util/generic/vector.h> +#include <util/generic/ptr.h> #include <util/system/atomic.h> #include <util/thread/pool.h> @@ -124,10 +124,10 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) { Y_UNIT_TEST(TestSimpleEnqueueDequeue) { TLockFreeQueue<int> queue; - int i = -1; + int i = -1; UNIT_ASSERT(!queue.Dequeue(&i)); - UNIT_ASSERT_VALUES_EQUAL(i, -1); + UNIT_ASSERT_VALUES_EQUAL(i, -1); queue.Enqueue(10); queue.Enqueue(11); @@ -156,10 +156,10 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) { Y_UNIT_TEST(TestSimpleEnqueueAllDequeue) { TLockFreeQueue<int> queue; - int i = -1; + int i = -1; UNIT_ASSERT(!queue.Dequeue(&i)); - UNIT_ASSERT_VALUES_EQUAL(i, -1); + UNIT_ASSERT_VALUES_EQUAL(i, -1); TVector<int> v; v.push_back(20); diff --git a/util/thread/pool.h b/util/thread/pool.h index 364530e68b..d1ea3a67cb 100644 --- a/util/thread/pool.h +++ b/util/thread/pool.h @@ -175,7 +175,7 @@ public: bool AddAndOwn(THolder<IObjectInQueue> obj) Y_WARN_UNUSED_RESULT; virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; - /** Wait for completion of all scheduled objects, and then exit */ + /** Wait for completion of all scheduled objects, and then exit */ virtual void Stop() noexcept = 0; /** Number of tasks currently in queue */ virtual size_t Size() const noexcept = 0; diff --git a/util/thread/pool_ut.cpp b/util/thread/pool_ut.cpp index b273dcf3c7..893770d0c4 100644 --- a/util/thread/pool_ut.cpp +++ b/util/thread/pool_ut.cpp @@ -10,12 +10,12 @@ #include <util/system/condvar.h> struct TThreadPoolTest { - TSpinLock Lock; - long R = -1; + TSpinLock Lock; + long R = -1; struct TTask: public IObjectInQueue { TThreadPoolTest* Test = nullptr; - long Value = 0; + long Value = 0; TTask(TThreadPoolTest* test, int value) : Test(test) @@ -26,8 +26,8 @@ struct TThreadPoolTest { void Process(void*) override { THolder<TTask> This(this); - TGuard<TSpinLock> guard(Test->Lock); - Test->R ^= Value; + TGuard<TSpinLock> guard(Test->Lock); + Test->R ^= Value; } }; @@ -54,7 +54,7 @@ struct TThreadPoolTest { TReallyFastRng32 rand(17); const size_t cnt = 1000; - R = 0; + R = 0; for (size_t i = 0; i < cnt; ++i) { R ^= (long)rand.GenRand(); @@ -69,48 +69,48 @@ struct TThreadPoolTest { queue->Stop(); - UNIT_ASSERT_EQUAL(0, R); + UNIT_ASSERT_EQUAL(0, R); } -}; +}; class TFailAddQueue: public IThreadPool { -public: +public: bool Add(IObjectInQueue* /*obj*/) override Y_WARN_UNUSED_RESULT { - return false; + return false; } void Start(size_t, size_t) override { - } + } void Stop() noexcept override { } size_t Size() const noexcept override { - return 0; - } -}; - + return 0; + } +}; + Y_UNIT_TEST_SUITE(TThreadPoolTest) { Y_UNIT_TEST(TestTThreadPool) { TThreadPoolTest t; TThreadPool q; - t.TestAnyQueue(&q); - } - + t.TestAnyQueue(&q); + } + Y_UNIT_TEST(TestTThreadPoolBlocking) { TThreadPoolTest t; TThreadPool q(TThreadPool::TParams().SetBlocking(true)); - t.TestAnyQueue(&q, 100); - } - - // disabled by pg@ long time ago due to test flaps - // Tried to enable: REVIEW:78772 + t.TestAnyQueue(&q, 100); + } + + // disabled by pg@ long time ago due to test flaps + // Tried to enable: REVIEW:78772 Y_UNIT_TEST(TestTAdaptiveThreadPool) { - if (false) { + if (false) { TThreadPoolTest t; TAdaptiveThreadPool q; - t.TestAnyQueue(&q); - } + t.TestAnyQueue(&q); + } } Y_UNIT_TEST(TestAddAndOwn) { @@ -126,12 +126,12 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { } Y_UNIT_TEST(TestAddFunc) { - TFailAddQueue queue; - bool added = queue.AddFunc( + TFailAddQueue queue; + bool added = queue.AddFunc( []() {} // Lambda, I call him 'Lambda'! ); - UNIT_ASSERT_VALUES_EQUAL(added, false); - } + UNIT_ASSERT_VALUES_EQUAL(added, false); + } Y_UNIT_TEST(TestSafeAddFuncThrows) { TFailAddQueue queue; @@ -254,4 +254,4 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { TestEnumeratedThreadName(pool, expectedNames); } } -} +} |