diff --git a/CMakeLists.txt b/CMakeLists.txt index 152a6866e5e..137feba447a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,15 +18,10 @@ set(YDB-CPP-SDK_AVAILABLE_COMPONENTS "" CACHE INTERNAL "") set(YDB-CPP-SDK_COMPONENT_TARGETS "" CACHE INTERNAL "") file(READ "src/client/resources/ydb_sdk_version.txt" YDB_SDK_VERSION) -file(MAKE_DIRECTORY ${YDB_SDK_BINARY_DIR}/ydb-cpp-sdk) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) list(APPEND CMAKE_MODULE_PATH ${YDB_SDK_SOURCE_DIR}/cmake) -include_directories(${YDB_SDK_SOURCE_DIR} ${YDB_SDK_SOURCE_DIR}/include ${YDB_SDK_BINARY_DIR}) - -if (YDB_SDK_INSTALL) - include(GNUInstallDirs) - include(CMakePackageConfigHelpers) -endif() include(cmake/global_flags.cmake) include(cmake/global_vars.cmake) @@ -37,28 +32,29 @@ include(cmake/protobuf.cmake) include(cmake/testing.cmake) include(cmake/external_libs.cmake) +if (YDB_SDK_TESTS) + enable_testing() +endif() + add_subdirectory(tools) -add_subdirectory(contrib) +add_subdirectory(contrib/libs) +add_subdirectory(library/cpp) add_subdirectory(src) +add_subdirectory(util) + +_ydb_sdk_validate_public_headers() if (YDB_SDK_EXAMPLES) add_subdirectory(examples) endif() if (YDB_SDK_TESTS) - enable_testing() add_subdirectory(tests/unit) add_subdirectory(tests/integration) endif() if (YDB_SDK_INSTALL) - _ydb_sdk_directory_install(DIRECTORY ${YDB_SDK_SOURCE_DIR}/include/ydb-cpp-sdk - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - _ydb_sdk_directory_install(DIRECTORY ${YDB_SDK_BINARY_DIR}/ydb-cpp-sdk - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - PATTERN "*.h" - ) + _ydb_sdk_install_headers(${CMAKE_INSTALL_INCLUDEDIR}) install(EXPORT ydb-cpp-sdk-targets FILE ydb-cpp-sdk-targets.cmake CONFIGURATIONS RELEASE diff --git a/cmake/common.cmake b/cmake/common.cmake index feabcfbcd3d..dea372f162e 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -163,7 +163,7 @@ function(resources Tgt Output) list(APPEND ResourcesList ${Key}) endforeach() - get_built_tool_path(rescompiler_bin tools/rescompiler/bin rescompiler) + get_built_tool_path(rescompiler_bin tools/rescompiler rescompiler) add_custom_command( OUTPUT ${Output} @@ -179,3 +179,77 @@ function(_ydb_sdk_make_client_component CmpName Tgt) set(YDB-CPP-SDK_AVAILABLE_COMPONENTS ${YDB-CPP-SDK_AVAILABLE_COMPONENTS} ${CmpName} CACHE INTERNAL "") set(YDB-CPP-SDK_COMPONENT_TARGETS ${YDB-CPP-SDK_COMPONENT_TARGETS} ${Tgt} CACHE INTERNAL "") endfunction() + +function(_ydb_sdk_add_library Tgt) + cmake_parse_arguments(ARG + "INTERFACE" "" "" + ${ARGN} + ) + + set(libraryMode "") + set(includeMode "PUBLIC") + if (ARG_INTERFACE) + set(libraryMode "INTERFACE") + set(includeMode "INTERFACE") + endif() + add_library(${Tgt} ${libraryMode}) + target_include_directories(${Tgt} ${includeMode} + $ + $ + $ + ) +endfunction() + +function(_ydb_sdk_validate_public_headers) + file(GLOB_RECURSE allHeaders RELATIVE ${YDB_SDK_SOURCE_DIR}/include ${YDB_SDK_SOURCE_DIR}/include/ydb-cpp-sdk/*) + file(STRINGS ${YDB_SDK_SOURCE_DIR}/cmake/public_headers.txt specialHeaders) + file(STRINGS ${YDB_SDK_SOURCE_DIR}/cmake/protos_public_headers.txt protosHeaders) + if (NOT MSVC) + list(REMOVE_ITEM specialHeaders library/cpp/deprecated/atomic/atomic_win.h) + endif() + list(APPEND allHeaders ${specialHeaders}) + file(COPY ${YDB_SDK_SOURCE_DIR}/include/ydb-cpp-sdk DESTINATION ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include) + foreach(path ${specialHeaders}) + get_filename_component(relPath ${path} DIRECTORY) + file(COPY ${YDB_SDK_SOURCE_DIR}/${path} + DESTINATION ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include/${relPath} + ) + endforeach() + + add_custom_target(make_validate_proto_headers + COMMAND ${CMAKE_COMMAND} -E + WORKING_DIRECTORY ${YDB_SDK_BINARY_DIR} + ) + foreach(path ${protosHeaders}) + get_filename_component(relPath ${path} DIRECTORY) + add_custom_command(OUTPUT ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include/${path} + COMMAND ${CMAKE_COMMAND} -E + copy "${path}" "__validate_headers_dir/include/${relPath}" + DEPENDS "${path}" + WORKING_DIRECTORY ${YDB_SDK_BINARY_DIR} + ) + endforeach() + + list(REMOVE_ITEM allHeaders + library/cpp/threading/future/core/future-inl.h + library/cpp/threading/future/wait/wait-inl.h + library/cpp/yt/misc/guid-inl.h + ) + + set(targetHeaders ${allHeaders}) + list(APPEND targetHeaders ${protosHeaders}) + list(TRANSFORM targetHeaders PREPEND "${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include/") + + list(TRANSFORM allHeaders PREPEND "#include <") + list(TRANSFORM allHeaders APPEND ">") + list(JOIN allHeaders "\n" fileContent) + + file(WRITE ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/main.cpp ${fileContent}) + + add_library(validate_public_interface MODULE + ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/main.cpp + ${targetHeaders} + ) + target_include_directories(validate_public_interface PUBLIC ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include) +endfunction() + diff --git a/cmake/global_vars.cmake b/cmake/global_vars.cmake index 7ec35a5aa0d..c0efd1e2c92 100644 --- a/cmake/global_vars.cmake +++ b/cmake/global_vars.cmake @@ -1,11 +1,4 @@ -# This file was generated by the build system used internally in the Yandex monorepo. -# Only simple modifications are allowed (adding source-files to targets, adding simple properties -# like target_include_directories). These modifications will be ported to original -# ya.make files by maintainers. Any complex modifications which can't be ported back to the -# original buildsystem will not be accepted. - - if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(YASM_FLAGS -f elf64 -D UNIX -D _x86_64_ -D_YASM_ -g dwarf2) set(RAGEL_FLAGS -L -I ${YDB_SDK_SOURCE_DIR}/) diff --git a/cmake/install.cmake b/cmake/install.cmake index 1d7bdd72945..2c1334f01bd 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -22,7 +22,9 @@ function(_ydb_sdk_install_targets) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + INCLUDES DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR} + ${CMAKE_INSTALL_INCLUDEDIR}/__ydb_sdk_special_headers ) endfunction() @@ -54,3 +56,32 @@ function(_ydb_sdk_directory_install) endif() endif() endfunction() + +function(_ydb_sdk_install_headers ArgIncludeDir) + if (NOT ${YDB_SDK_INSTALL}) + return() + endif() + _ydb_sdk_directory_install(DIRECTORY ${YDB_SDK_SOURCE_DIR}/include/ydb-cpp-sdk + DESTINATION ${ArgIncludeDir} + ) + + file(STRINGS ${YDB_SDK_SOURCE_DIR}/cmake/public_headers.txt PublicHeaders) + file(STRINGS ${YDB_SDK_SOURCE_DIR}/cmake/protos_public_headers.txt ProtosPublicHeaders) + if (NOT MSVC) + list(REMOVE_ITEM PublicHeaders library/cpp/deprecated/atomic/atomic_win.h) + endif() + foreach(HeaderPath ${PublicHeaders}) + get_filename_component(RelInstallPath ${HeaderPath} DIRECTORY) + _ydb_sdk_directory_install(FILES + ${YDB_SDK_SOURCE_DIR}/${HeaderPath} + DESTINATION ${ArgIncludeDir}/__ydb_sdk_special_headers/${RelInstallPath} + ) + endforeach() + foreach(HeaderPath ${ProtosPublicHeaders}) + get_filename_component(RelInstallPath ${HeaderPath} DIRECTORY) + _ydb_sdk_directory_install(FILES + ${YDB_SDK_BINARY_DIR}/${HeaderPath} + DESTINATION ${ArgIncludeDir}/__ydb_sdk_special_headers/${RelInstallPath} + ) + endforeach() +endfunction() diff --git a/cmake/protobuf.cmake b/cmake/protobuf.cmake index 97e310d23cd..71d43d3ce8b 100644 --- a/cmake/protobuf.cmake +++ b/cmake/protobuf.cmake @@ -49,7 +49,7 @@ function(_ydb_sdk_gen_proto_messages Tgt Scope Grpc) endfunction() function(_ydb_sdk_init_proto_library_impl Tgt USE_API_COMMON_PROTOS) - add_library(${Tgt}) + _ydb_sdk_add_library(${Tgt}) target_link_libraries(${Tgt} PUBLIC protobuf::libprotobuf ) diff --git a/cmake/protos_public_headers.txt b/cmake/protos_public_headers.txt new file mode 100644 index 00000000000..ef746225fc3 --- /dev/null +++ b/cmake/protos_public_headers.txt @@ -0,0 +1,24 @@ +src/api/grpc/draft/ydb_datastreams_v1.grpc.pb.h +src/api/grpc/draft/ydb_datastreams_v1.pb.h +src/api/grpc/ydb_topic_v1.grpc.pb.h +src/api/grpc/ydb_topic_v1.pb.h +src/api/protos/annotations/validation.pb.h +src/api/protos/draft/datastreams.pb.h +src/api/protos/ydb_common.pb.h +src/api/protos/ydb_federation_discovery.pb.h +src/api/protos/ydb_operation.pb.h +src/api/protos/ydb_value.pb.h +src/api/protos/ydb_query.pb.h +src/api/protos/ydb_topic.pb.h +src/api/protos/ydb_table.pb.h +src/api/protos/ydb_scheme.pb.h +src/api/protos/ydb_query_stats.pb.h +src/api/protos/ydb_import.pb.h +src/api/protos/ydb_formats.pb.h +src/api/protos/ydb_issue_message.pb.h +src/api/protos/ydb_export.pb.h +src/api/protos/ydb_coordination.pb.h +src/api/protos/ydb_status_codes.pb.h +src/api/protos/draft/ydb_replication.pb.h +src/library/operation_id/protos/operation_id.pb.h +src/library/yql/public/issue/protos/issue_severity.pb.h \ No newline at end of file diff --git a/cmake/public_headers.txt b/cmake/public_headers.txt new file mode 100644 index 00000000000..d926140d27d --- /dev/null +++ b/cmake/public_headers.txt @@ -0,0 +1,207 @@ +contrib/libs/libc_compat/string.h +library/cpp/cgiparam/cgiparam.h +library/cpp/containers/stack_vector/stack_vec.h +library/cpp/coroutine/listener/listen.h +library/cpp/deprecated/atomic/atomic.h +library/cpp/deprecated/atomic/atomic_gcc.h +library/cpp/deprecated/atomic/atomic_ops.h +library/cpp/deprecated/atomic/atomic_win.h +library/cpp/http/fetch/exthttpcodes.h +library/cpp/http/fetch/httpheader.h +library/cpp/http/io/headers.h +library/cpp/http/io/stream.h +library/cpp/http/misc/httpcodes.h +library/cpp/http/server/conn.h +library/cpp/http/server/http.h +library/cpp/http/server/options.h +library/cpp/http/server/response.h +library/cpp/iterator/iterate_values.h +library/cpp/iterator/mapped.h +library/cpp/json/common/defs.h +library/cpp/json/fast_sax/parser.h +library/cpp/json/writer/json.h +library/cpp/json/writer/json_value.h +library/cpp/json/json_reader.h +library/cpp/json/json_value.h +library/cpp/logger/all.h +library/cpp/logger/backend.h +library/cpp/logger/element.h +library/cpp/logger/file.h +library/cpp/logger/log.h +library/cpp/logger/null.h +library/cpp/logger/priority.h +library/cpp/logger/record.h +library/cpp/logger/reopen.h +library/cpp/logger/stream.h +library/cpp/logger/sync_page_cache_file.h +library/cpp/logger/system.h +library/cpp/logger/thread.h +library/cpp/mime/types/mime.h +library/cpp/monlib/counters/counters.h +library/cpp/monlib/dynamic_counters/counters.h +library/cpp/monlib/encode/json/json.h +library/cpp/monlib/encode/encoder.h +library/cpp/monlib/encode/format.h +library/cpp/monlib/metrics/histogram_collector.h +library/cpp/monlib/metrics/histogram_snapshot.h +library/cpp/monlib/metrics/labels.h +library/cpp/monlib/metrics/log_histogram_snapshot.h +library/cpp/monlib/metrics/metric.h +library/cpp/monlib/metrics/metric_consumer.h +library/cpp/monlib/metrics/metric_registry.h +library/cpp/monlib/metrics/metric_type.h +library/cpp/monlib/metrics/summary_collector.h +library/cpp/monlib/metrics/summary_snapshot.h +library/cpp/monlib/service/pages/index_mon_page.h +library/cpp/monlib/service/pages/mon_page.h +library/cpp/monlib/service/auth.h +library/cpp/monlib/service/mon_service_http_request.h +library/cpp/monlib/service/monservice.h +library/cpp/monlib/service/service.h +library/cpp/resource/resource.h +library/cpp/threading/future/core/future-inl.h +library/cpp/threading/future/core/future.h +library/cpp/threading/future/core/fwd.h +library/cpp/threading/future/wait/fwd.h +library/cpp/threading/future/wait/wait-inl.h +library/cpp/threading/future/wait/wait.h +library/cpp/threading/future/wait/wait_group-inl.h +library/cpp/threading/future/wait/wait_group.h +library/cpp/threading/future/wait/wait_policy.h +library/cpp/threading/future/future.h +library/cpp/threading/future/fwd.h +library/cpp/threading/light_rw_lock/lightrwlock.h +library/cpp/yson/consumer.h +library/cpp/yson/public.h +library/cpp/yson/token.h +library/cpp/yson/writer.h +library/cpp/yt/exception/attributes.h +library/cpp/yt/exception/exception.h +library/cpp/yt/misc/enum-inl.h +library/cpp/yt/misc/enum.h +library/cpp/yt/misc/guid-inl.h +library/cpp/yt/misc/guid.h +library/cpp/yt/misc/preprocessor-gen.h +library/cpp/yt/misc/preprocessor.h +library/cpp/yt/yson/consumer.h +library/cpp/yt/yson/public.h +library/cpp/yt/yson_string/public.h +util/charset/unidata.h +util/charset/unicode_table.h +util/datetime/base.h +util/datetime/systime.h +util/digest/multi.h +util/digest/numeric.h +util/digest/sequence.h +util/folder/fwd.h +util/folder/path.h +util/folder/pathsplit.h +util/generic/algorithm.h +util/generic/array_size.h +util/generic/array_ref.h +util/generic/bitops.h +util/generic/bt_exception.h +util/generic/buffer.h +util/generic/cast.h +util/generic/deque.h +util/generic/explicit_type.h +util/generic/flags.h +util/generic/function.h +util/generic/fwd.h +util/generic/hash_primes.h +util/generic/hash_table.h +util/generic/hash.h +util/generic/intrlist.h +util/generic/is_in.h +util/generic/iterator_range.h +util/generic/list.h +util/generic/map.h +util/generic/mapfindptr.h +util/generic/maybe_traits.h +util/generic/maybe.h +util/generic/mem_copy.h +util/generic/noncopyable.h +util/generic/ptr.h +util/generic/refcount.h +util/generic/reserve.h +util/generic/singleton.h +util/generic/size_literals.h +util/generic/store_policy.h +util/generic/strbase.h +util/generic/strbuf.h +util/generic/string_hash.h +util/generic/string.h +util/generic/typelist.h +util/generic/typetraits.h +util/generic/utility.h +util/generic/va_args.h +util/generic/vector.h +util/generic/xrange.h +util/generic/yexception.h +util/generic/ylimits.h +util/memory/alloc.h +util/memory/blob.h +util/memory/tempbuf.h +util/network/address.h +util/network/hostip.h +util/network/init.h +util/network/ip.h +util/network/sock.h +util/network/socket.h +util/random/random.h +util/stream/debug.h +util/stream/fwd.h +util/stream/input.h +util/stream/labeled.h +util/stream/mem.h +util/stream/output.h +util/stream/str.h +util/stream/tempbuf.h +util/stream/zerocopy_output.h +util/stream/zerocopy.h +util/string/ascii.h +util/string/builder.h +util/string/cast.h +util/string/escape.h +util/string/printf.h +util/string/strip.h +util/string/subst.h +util/string/util.h +util/system/align.h +util/system/atexit.h +util/system/backtrace.h +util/system/byteorder.h +util/system/compat.h +util/system/compiler.h +util/system/datetime.h +util/system/defaults.h +util/system/error.h +util/system/event.h +util/system/fhandle.h +util/system/file.h +util/system/flock.h +util/system/fstat.h +util/system/guard.h +util/system/maxlen.h +util/system/mutex.h +util/system/platform.h +util/system/progname.h +util/system/rwlock.h +util/system/sanitizers.h +util/system/sem.h +util/system/spin_wait.h +util/system/spinlock.h +util/system/src_location.h +util/system/src_root.h +util/system/sysstat.h +util/system/type_name.h +util/system/types.h +util/system/unaligned_mem.h +util/system/win_undef.h +util/system/winint.h +util/system/yassert.h +util/thread/factory.h +util/thread/fwd.h +util/thread/pool.h +util/str_stl.h +util/ysaveload.h \ No newline at end of file diff --git a/cmake/testing.cmake b/cmake/testing.cmake index bed39d0bc63..0cd06c4e1aa 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -58,7 +58,7 @@ function(set_yunittest_property) endfunction() function(add_ydb_test) - set(opts "") + set(opts GTEST) set(oneval_args NAME) set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS) cmake_parse_arguments(YDB_TEST @@ -75,7 +75,7 @@ function(add_ydb_test) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(${YDB_TEST_NAME} PRIVATE - library-cpuid_check + cpuid_check ) endif() @@ -101,19 +101,27 @@ function(add_ydb_test) SPLIT_FACTOR 1 ) - - add_yunittest( - NAME - ${YDB_TEST_NAME} - TEST_TARGET - ${YDB_TEST_NAME} - TEST_ARG - --print-before-suite - --print-before-test - --fork-tests - --print-times - --show-fails - ) + if (YDB_TEST_GTEST) + add_yunittest( + NAME + ${YDB_TEST_NAME} + TEST_TARGET + ${YDB_TEST_NAME} + ) + else() + add_yunittest( + NAME + ${YDB_TEST_NAME} + TEST_TARGET + ${YDB_TEST_NAME} + TEST_ARG + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails + ) + endif() set_yunittest_property( TEST diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt deleted file mode 100644 index c0ba0276344..00000000000 --- a/contrib/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -# This file was generated by the build system used internally in the Yandex monorepo. -# Only simple modifications are allowed (adding source-files to targets, adding simple properties -# like target_include_directories). These modifications will be ported to original -# ya.make files by maintainers. Any complex modifications which can't be ported back to the -# original buildsystem will not be accepted. - - -add_subdirectory(libs) diff --git a/contrib/libs/CMakeLists.txt b/contrib/libs/CMakeLists.txt index b7e67d54e1d..3edb4119484 100644 --- a/contrib/libs/CMakeLists.txt +++ b/contrib/libs/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(libc_compat) add_subdirectory(lzmasdk) diff --git a/contrib/libs/libc_compat/CMakeLists.txt b/contrib/libs/libc_compat/CMakeLists.txt new file mode 100644 index 00000000000..5f6ff531c2e --- /dev/null +++ b/contrib/libs/libc_compat/CMakeLists.txt @@ -0,0 +1,18 @@ +_ydb_sdk_add_library(contrib-libs-libc_compat) + +target_compile_options(contrib-libs-libc_compat PRIVATE + $,,-Wno-everything> +) + +target_sources(contrib-libs-libc_compat PRIVATE + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/string.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/explicit_bzero.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/memfd_create.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/strlcat.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/strlcpy.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/reallocarray/reallocarray.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/random/getrandom.c + ${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/random/getentropy.c +) + +_ydb_sdk_install_targets(TARGETS contrib-libs-libc_compat) diff --git a/contrib/libs/libc_compat/README.md b/contrib/libs/libc_compat/README.md new file mode 100644 index 00000000000..fe7a22fbb1e --- /dev/null +++ b/contrib/libs/libc_compat/README.md @@ -0,0 +1,24 @@ +This library implements a compatibility layer between various libc implementations. + +The rationale for the library implementation is described in https://st.yandex-team.ru/IGNIETFERRO-1439. + +The code is taken from multiple sources, thus both LICENSE() and VERSION() tags are not very representative. + + +During development one can make use of the following mapping of `OS_SDK` into glibc version. + +| Ubuntu | glibc | +| ------ | ----- | +| 20.04 | 2.30 | +| 18.04 | 2.27 | +| 16.04 | 2.23 | +| 14.04 | 2.18 | +| 12.04 | 2.15 | +| 10.04 | 2.11 | + +Use the following commands to update the table above: + +1. `ya make util -DOS_SDK=ubuntu-xx -G | grep OS_SDK_ROOT | head -n 1` +2. `cd ~/.ya/tools/v4/$RESOURCE_ID` +3. `readelf -V $(find . -name 'libc.so.6')` +4. Take the latest version from `.gnu.version_d` section prior to `GLIBC_PRIVATE` diff --git a/contrib/libs/libc_compat/explicit_bzero.c b/contrib/libs/libc_compat/explicit_bzero.c new file mode 100644 index 00000000000..95c27654090 --- /dev/null +++ b/contrib/libs/libc_compat/explicit_bzero.c @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + * + * explicit_bzero.c + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/port/explicit_bzero.c + * + *------------------------------------------------------------------------- + */ + +#include +#include + +#if defined(HAVE_MEMSET_S) + +void +explicit_bzero(void *buf, size_t len) +{ + (void) memset_s(buf, len, 0, len); +} + +#elif defined(WIN32) + +#include + +void +explicit_bzero(void *buf, size_t len) +{ + (void) SecureZeroMemory(buf, len); +} + +#else + +/* + * Indirect call through a volatile pointer to hopefully avoid dead-store + * optimisation eliminating the call. (Idea taken from OpenSSH.) We can't + * assume bzero() is present either, so for simplicity we define our own. + */ + +static void +bzero2(void *buf, size_t len) +{ + memset(buf, 0, len); +} + +static void (*volatile bzero_p) (void *, size_t) = bzero2; + +void +explicit_bzero(void *buf, size_t len) +{ + bzero_p(buf, len); +} + +#endif diff --git a/contrib/libs/libc_compat/getservbyname/getservbyname.c b/contrib/libs/libc_compat/getservbyname/getservbyname.c new file mode 100644 index 00000000000..1fff91d0058 --- /dev/null +++ b/contrib/libs/libc_compat/getservbyname/getservbyname.c @@ -0,0 +1,11 @@ +#include + +struct servent *getservbyname(const char *name, const char *prots) +{ + static struct servent se; + static char *buf[2]; + struct servent *res; + if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res)) + return 0; + return &se; +} diff --git a/contrib/libs/libc_compat/getservbyname/getservbyname_r.c b/contrib/libs/libc_compat/getservbyname/getservbyname_r.c new file mode 100644 index 00000000000..cad6317ab84 --- /dev/null +++ b/contrib/libs/libc_compat/getservbyname/getservbyname_r.c @@ -0,0 +1,55 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include "lookup.h" + +#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *)) + +int getservbyname_r(const char *name, const char *prots, + struct servent *se, char *buf, size_t buflen, struct servent **res) +{ + struct service servs[MAXSERVS]; + int cnt, proto, align; + + *res = 0; + + /* Don't treat numeric port number strings as service records. */ + char *end = ""; + strtoul(name, &end, 10); + if (!*end) return ENOENT; + + /* Align buffer */ + align = -(uintptr_t)buf & ALIGN-1; + if (buflen < 2*sizeof(char *)+align) + return ERANGE; + buf += align; + + if (!prots) proto = 0; + else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP; + else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP; + else return EINVAL; + + cnt = __lookup_serv(servs, name, proto, 0, 0); + if (cnt<0) switch (cnt) { + case EAI_MEMORY: + case EAI_SYSTEM: + return ENOMEM; + default: + return ENOENT; + } + + se->s_name = (char *)name; + se->s_aliases = (void *)buf; + se->s_aliases[0] = se->s_name; + se->s_aliases[1] = 0; + se->s_port = htons(servs[0].port); + se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp"; + + *res = se; + return 0; +} diff --git a/contrib/libs/libc_compat/getservbyname/lookup.h b/contrib/libs/libc_compat/getservbyname/lookup.h new file mode 100644 index 00000000000..7dc1fb81093 --- /dev/null +++ b/contrib/libs/libc_compat/getservbyname/lookup.h @@ -0,0 +1,57 @@ +#ifndef LOOKUP_H +#define LOOKUP_H + +#include +#include +#include +#include +#include + +#define hidden __attribute__((__visibility__("hidden"))) + +struct aibuf { + struct addrinfo ai; + union sa { + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + } sa; + volatile int lock[1]; + short slot, ref; +}; + +struct address { + int family; + unsigned scopeid; + uint8_t addr[16]; + int sortkey; +}; + +struct service { + uint16_t port; + unsigned char proto, socktype; +}; + +#define MAXNS 3 + +struct resolvconf { + struct address ns[MAXNS]; + unsigned nns, attempts, ndots; + unsigned timeout; +}; + +/* The limit of 48 results is a non-sharp bound on the number of addresses + * that can fit in one 512-byte DNS packet full of v4 results and a second + * packet full of v6 results. Due to headers, the actual limit is lower. */ +#define MAXADDRS 48 +#define MAXSERVS 2 + +hidden int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags); +hidden int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags); +hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, int family); + +hidden int __get_resolv_conf(struct resolvconf *, char *, size_t); +hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *); + +hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *); + +#endif diff --git a/contrib/libs/libc_compat/getservbyname/lookup_serv.c b/contrib/libs/libc_compat/getservbyname/lookup_serv.c new file mode 100644 index 00000000000..31d407cf28f --- /dev/null +++ b/contrib/libs/libc_compat/getservbyname/lookup_serv.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lookup.h" + +int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags) +{ + char line[128]; + int cnt = 0; + char *p, *z = ""; + unsigned long port = 0; + + switch (socktype) { + case SOCK_STREAM: + switch (proto) { + case 0: + proto = IPPROTO_TCP; + case IPPROTO_TCP: + break; + default: + return EAI_SERVICE; + } + break; + case SOCK_DGRAM: + switch (proto) { + case 0: + proto = IPPROTO_UDP; + case IPPROTO_UDP: + break; + default: + return EAI_SERVICE; + } + case 0: + break; + default: + if (name) return EAI_SERVICE; + buf[0].port = 0; + buf[0].proto = proto; + buf[0].socktype = socktype; + return 1; + } + + if (name) { + if (!*name) return EAI_SERVICE; + port = strtoul(name, &z, 10); + } + if (!*z) { + if (port > 65535) return EAI_SERVICE; + if (proto != IPPROTO_UDP) { + buf[cnt].port = port; + buf[cnt].socktype = SOCK_STREAM; + buf[cnt++].proto = IPPROTO_TCP; + } + if (proto != IPPROTO_TCP) { + buf[cnt].port = port; + buf[cnt].socktype = SOCK_DGRAM; + buf[cnt++].proto = IPPROTO_UDP; + } + return cnt; + } + + if (flags & AI_NUMERICSERV) return EAI_NONAME; + + size_t l = strlen(name); + + FILE *f = fopen("/etc/services", "rb"); + if (!f) switch (errno) { + case ENOENT: + case ENOTDIR: + case EACCES: + return EAI_SERVICE; + default: + return EAI_SYSTEM; + } + + while (fgets(line, sizeof line, f) && cnt < MAXSERVS) { + if ((p=strchr(line, '#'))) *p++='\n', *p=0; + + /* Find service name */ + for(p=line; (p=strstr(p, name)); p++) { + if (p>line && !isspace(p[-1])) continue; + if (p[l] && !isspace(p[l])) continue; + break; + } + if (!p) continue; + + /* Skip past canonical name at beginning of line */ + for (p=line; *p && !isspace(*p); p++); + + port = strtoul(p, &z, 10); + if (port > 65535 || z==p) continue; + if (!strncmp(z, "/udp", 4)) { + if (proto == IPPROTO_TCP) continue; + buf[cnt].port = port; + buf[cnt].socktype = SOCK_DGRAM; + buf[cnt++].proto = IPPROTO_UDP; + } + if (!strncmp(z, "/tcp", 4)) { + if (proto == IPPROTO_UDP) continue; + buf[cnt].port = port; + buf[cnt].socktype = SOCK_STREAM; + buf[cnt++].proto = IPPROTO_TCP; + } + } + fclose(f); + return cnt > 0 ? cnt : EAI_SERVICE; +} diff --git a/contrib/libs/libc_compat/include/ifaddrs/ifaddrs.h b/contrib/libs/libc_compat/include/ifaddrs/ifaddrs.h new file mode 100644 index 00000000000..9cd19fec129 --- /dev/null +++ b/contrib/libs/libc_compat/include/ifaddrs/ifaddrs.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1995, 1999 + * Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp + */ + +#ifndef _IFADDRS_H_ +#define _IFADDRS_H_ + +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + unsigned int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; + +/* + * This may have been defined in . Note that if is + * to be included it must be included before this header file. + */ +#ifndef ifa_broadaddr +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ +#endif + +#include + +__BEGIN_DECLS +extern int getifaddrs(struct ifaddrs **ifap); +extern void freeifaddrs(struct ifaddrs *ifa); +__END_DECLS + +#endif diff --git a/contrib/libs/libc_compat/include/readpassphrase/readpassphrase.h b/contrib/libs/libc_compat/include/readpassphrase/readpassphrase.h new file mode 100644 index 00000000000..ba1ee14ef16 --- /dev/null +++ b/contrib/libs/libc_compat/include/readpassphrase/readpassphrase.h @@ -0,0 +1,44 @@ +/* $OpenBSD: readpassphrase.h,v 1.6 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 2000, 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#ifndef _READPASSPHRASE_H_ +#define _READPASSPHRASE_H_ + +#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ +#define RPP_ECHO_ON 0x01 /* Leave echo on. */ +#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ +#define RPP_FORCELOWER 0x04 /* Force input to lower case. */ +#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ +#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ +#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif +char * readpassphrase(const char *, char *, size_t, int); +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* !_READPASSPHRASE_H_ */ diff --git a/contrib/libs/libc_compat/include/windows/sys/queue.h b/contrib/libs/libc_compat/include/windows/sys/queue.h new file mode 100644 index 00000000000..bc1568be674 --- /dev/null +++ b/contrib/libs/libc_compat/include/windows/sys/queue.h @@ -0,0 +1,631 @@ +/* $OpenBSD: queue.h,v 1.46 2020/12/30 13:33:12 millert Exp $ */ +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +/* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues and XOR simple queues. + * + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * An XOR simple queue is used in the same way as a regular simple queue. + * The difference is that the head structure also includes a "cookie" that + * is XOR'd with the queue pointer (first, last or next) to generate the + * real pointer value. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + +#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) +#define _Q_INVALID ((void *)-1) +#define _Q_INVALIDATE(a) (a) = _Q_INVALID +#else +#define _Q_INVALIDATE(a) +#endif + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List access methods. + */ +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_END(head) NULL +#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = SLIST_FIRST(head); \ + (var) != SLIST_END(head); \ + (var) = SLIST_NEXT(var, field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST(head); \ + (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) { \ + SLIST_FIRST(head) = SLIST_END(head); \ +} + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->slh_first; \ + \ + while (curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ + _Q_INVALIDATE((elm)->field.sle_next); \ +} while (0) + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List access methods. + */ +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_END(head) NULL +#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_FOREACH(var, head, field) \ + for((var) = LIST_FIRST(head); \ + (var)!= LIST_END(head); \ + (var) = LIST_NEXT(var, field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST(head); \ + (var) && ((tvar) = LIST_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * List functions. + */ +#define LIST_INIT(head) do { \ + LIST_FIRST(head) = LIST_END(head); \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +#define LIST_REPLACE(elm, elm2, field) do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = \ + &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for((var) = SIMPLEQ_FIRST(head); \ + (var) != SIMPLEQ_END(head); \ + (var) = SIMPLEQ_NEXT(var, field)) + +#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SIMPLEQ_FIRST(head); \ + (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (0) + +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ + if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ + == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_CONCAT(head1, head2) do { \ + if (!SIMPLEQ_EMPTY((head2))) { \ + *(head1)->sqh_last = (head2)->sqh_first; \ + (head1)->sqh_last = (head2)->sqh_last; \ + SIMPLEQ_INIT((head2)); \ + } \ +} while (0) + +/* + * XOR Simple queue definitions. + */ +#define XSIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqx_first; /* first element */ \ + struct type **sqx_last; /* addr of last next element */ \ + unsigned long sqx_cookie; \ +} + +#define XSIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqx_next; /* next element */ \ +} + +/* + * XOR Simple queue access methods. + */ +#define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \ + (unsigned long)(ptr))) +#define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first)) +#define XSIMPLEQ_END(head) NULL +#define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head)) +#define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next)) + + +#define XSIMPLEQ_FOREACH(var, head, field) \ + for ((var) = XSIMPLEQ_FIRST(head); \ + (var) != XSIMPLEQ_END(head); \ + (var) = XSIMPLEQ_NEXT(head, var, field)) + +#define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = XSIMPLEQ_FIRST(head); \ + (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \ + (var) = (tvar)) + +/* + * XOR Simple queue functions. + */ +#define XSIMPLEQ_INIT(head) do { \ + arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \ + (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ +} while (0) + +#define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqx_next = (head)->sqx_first) == \ + XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ + (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \ +} while (0) + +#define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \ + *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ +} while (0) + +#define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \ + XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ + (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \ +} while (0) + +#define XSIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqx_first = XSIMPLEQ_XOR(head, \ + (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ +} while (0) + +#define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ + if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \ + (elm)->field.sqx_next)->field.sqx_next) \ + == XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = \ + XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ +} while (0) + + +/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Tail queue access methods. + */ +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_END(head) NULL +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +/* XXX */ +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) \ + (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) \ + for((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head) && \ + ((tvar) = TAILQ_NEXT(var, field), 1); \ + (var) = (tvar)) + + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_PREV(var, headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head) && \ + ((tvar) = TAILQ_PREV(var, headname, field), 1); \ + (var) = (tvar)) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = \ + &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + } \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first; /* first element */ \ + struct type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue access methods. + */ +#define STAILQ_FIRST(head) ((head)->stqh_first) +#define STAILQ_END(head) NULL +#define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head)) +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = STAILQ_FIRST(head); \ + (var) != STAILQ_END(head); \ + (var) = STAILQ_NEXT(var, field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST(head); \ + (var) && ((tvar) = STAILQ_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((elm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((elm), field) = (elm); \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->stqh_first; \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ +} while (0) + +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->stqh_last) - offsetof(struct type, field)))) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/contrib/libs/libc_compat/include/windows/sys/uio.h b/contrib/libs/libc_compat/include/windows/sys/uio.h new file mode 100644 index 00000000000..47cc77784ad --- /dev/null +++ b/contrib/libs/libc_compat/include/windows/sys/uio.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define IOV_MAX INT_MAX + +typedef SSIZE_T ssize_t; + +struct iovec { + char* iov_base; + size_t iov_len; +}; + +ssize_t readv(SOCKET sock, struct iovec const* iov, int nvecs); +ssize_t writev(SOCKET sock, struct iovec const* iov, int nvecs); + +#ifdef __cplusplus +} +#endif diff --git a/contrib/libs/libc_compat/memfd_create.c b/contrib/libs/libc_compat/memfd_create.c new file mode 100644 index 00000000000..6805d807d6e --- /dev/null +++ b/contrib/libs/libc_compat/memfd_create.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE 1 +#include +#include "syscall.h" +#include + +int memfd_create(const char *name, unsigned flags) +{ + return syscall(__NR_memfd_create, name, flags); +} diff --git a/contrib/libs/libc_compat/memrchr.c b/contrib/libs/libc_compat/memrchr.c new file mode 100644 index 00000000000..ff3048759f4 --- /dev/null +++ b/contrib/libs/libc_compat/memrchr.c @@ -0,0 +1,39 @@ +/* $OpenBSD: memrchr.c,v 1.4 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 2007 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +/* + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void * +memrchr(const void *s, int c, size_t n) +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return(NULL); +} + diff --git a/contrib/libs/libc_compat/random/getentropy.c b/contrib/libs/libc_compat/random/getentropy.c new file mode 100644 index 00000000000..50e9c2fae25 --- /dev/null +++ b/contrib/libs/libc_compat/random/getentropy.c @@ -0,0 +1,37 @@ +#define _BSD_SOURCE +#include +#include +#include +#include + +int getentropy(void *buffer, size_t len) +{ + int cs, ret = 0; + char *pos = buffer; + + if (len > 256) { + errno = EIO; + return -1; + } + +#if defined(__linux__) && !defined(__ANDROID__) + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); +#endif + + while (len) { + ret = getrandom(pos, len, 0); + if (ret < 0) { + if (errno == EINTR) continue; + else break; + } + pos += ret; + len -= ret; + ret = 0; + } + +#if defined(__linux__) && !defined(__ANDROID__) + pthread_setcancelstate(cs, 0); +#endif + + return ret; +} diff --git a/contrib/libs/libc_compat/random/getrandom.c b/contrib/libs/libc_compat/random/getrandom.c new file mode 100644 index 00000000000..ba2d393c6b6 --- /dev/null +++ b/contrib/libs/libc_compat/random/getrandom.c @@ -0,0 +1,18 @@ +#include +#include "syscall.h" + +#if defined(__has_feature) + #if __has_feature(memory_sanitizer) + #include + #endif +#endif + +ssize_t getrandom(void *buf, size_t buflen, unsigned flags) +{ +#if defined(__has_feature) + #if __has_feature(memory_sanitizer) + __msan_unpoison(buf, buflen); + #endif +#endif + return syscall(SYS_getrandom, buf, buflen, flags); +} diff --git a/contrib/libs/libc_compat/random/sys/random.h b/contrib/libs/libc_compat/random/sys/random.h new file mode 100644 index 00000000000..c33843ea23b --- /dev/null +++ b/contrib/libs/libc_compat/random/sys/random.h @@ -0,0 +1,33 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if !defined(SYS_getrandom) +#if defined(__x86_64__) + #define SYS_getrandom 318 +#elif defined(__i386__) + #define SYS_getrandom 355 +#elif defined(__aarch64__) + #define SYS_getrandom 278 +#elif defined(__arm__) + #define SYS_getrandom 384 +#elif defined(__powerpc__) + #define SYS_getrandom 359 +#else +#error Unsupported platform +#endif +#endif + +#define GRND_NONBLOCK 0x0001 +#define GRND_RANDOM 0x0002 +#define GRND_INSECURE 0x0004 + +ssize_t getrandom(void* buf, size_t buflen, unsigned int flags); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/contrib/libs/libc_compat/readpassphrase.c b/contrib/libs/libc_compat/readpassphrase.c new file mode 100644 index 00000000000..df677e9ca5e --- /dev/null +++ b/contrib/libs/libc_compat/readpassphrase.c @@ -0,0 +1,192 @@ +/* $OpenBSD: readpassphrase.c,v 1.27 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 2000-2002, 2007, 2010 + * Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef TCSASOFT +/* If we don't have TCSASOFT define it so that ORing it it below is a no-op. */ +# define TCSASOFT 0 +#endif + +/* SunOS 4.x which lacks _POSIX_VDISABLE, but has VDISABLE */ +#if !defined(_POSIX_VDISABLE) && defined(VDISABLE) +# define _POSIX_VDISABLE VDISABLE +#endif + +static volatile sig_atomic_t signo[_NSIG]; + +static void handler(int); + +char * +readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) +{ + ssize_t nr; + int input, output, save_errno, i, need_restart; + char ch, *p, *end; + struct termios term, oterm; + struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm; + struct sigaction savetstp, savettin, savettou, savepipe; + + /* I suppose we could alloc on demand in this case (XXX). */ + if (bufsiz == 0) { + errno = EINVAL; + return(NULL); + } + +restart: + for (i = 0; i < _NSIG; i++) + signo[i] = 0; + nr = -1; + save_errno = 0; + need_restart = 0; + /* + * Read and write to /dev/tty if available. If not, read from + * stdin and write to stderr unless a tty is required. + */ + if ((flags & RPP_STDIN) || + (input = output = open(_PATH_TTY, O_RDWR)) == -1) { + if (flags & RPP_REQUIRE_TTY) { + errno = ENOTTY; + return(NULL); + } + input = STDIN_FILENO; + output = STDERR_FILENO; + } + + /* + * Turn off echo if possible. + * If we are using a tty but are not the foreground pgrp this will + * generate SIGTTOU, so do it *before* installing the signal handlers. + */ + if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { + memcpy(&term, &oterm, sizeof(term)); + if (!(flags & RPP_ECHO_ON)) + term.c_lflag &= ~(ECHO | ECHONL); + (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); + } else { + memset(&term, 0, sizeof(term)); + term.c_lflag |= ECHO; + memset(&oterm, 0, sizeof(oterm)); + oterm.c_lflag |= ECHO; + } + + /* + * Catch signals that would otherwise cause the user to end + * up with echo turned off in the shell. Don't worry about + * things like SIGXCPU and SIGVTALRM for now. + */ + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; /* don't restart system calls */ + sa.sa_handler = handler; + (void)sigaction(SIGALRM, &sa, &savealrm); + (void)sigaction(SIGHUP, &sa, &savehup); + (void)sigaction(SIGINT, &sa, &saveint); + (void)sigaction(SIGPIPE, &sa, &savepipe); + (void)sigaction(SIGQUIT, &sa, &savequit); + (void)sigaction(SIGTERM, &sa, &saveterm); + (void)sigaction(SIGTSTP, &sa, &savetstp); + (void)sigaction(SIGTTIN, &sa, &savettin); + (void)sigaction(SIGTTOU, &sa, &savettou); + + if (!(flags & RPP_STDIN)) + (void)write(output, prompt, strlen(prompt)); + end = buf + bufsiz - 1; + p = buf; + while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') { + if (p < end) { + if ((flags & RPP_SEVENBIT)) + ch &= 0x7f; + if (isalpha((unsigned char)ch)) { + if ((flags & RPP_FORCELOWER)) + ch = (char)tolower((unsigned char)ch); + if ((flags & RPP_FORCEUPPER)) + ch = (char)toupper((unsigned char)ch); + } + *p++ = ch; + } + } + *p = '\0'; + save_errno = errno; + if (!(term.c_lflag & ECHO)) + (void)write(output, "\n", 1); + + /* Restore old terminal settings and signals. */ + if (memcmp(&term, &oterm, sizeof(term)) != 0) { + const int sigttou = signo[SIGTTOU]; + + /* Ignore SIGTTOU generated when we are not the fg pgrp. */ + while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 && + errno == EINTR && !signo[SIGTTOU]) + continue; + signo[SIGTTOU] = sigttou; + } + (void)sigaction(SIGALRM, &savealrm, NULL); + (void)sigaction(SIGHUP, &savehup, NULL); + (void)sigaction(SIGINT, &saveint, NULL); + (void)sigaction(SIGQUIT, &savequit, NULL); + (void)sigaction(SIGPIPE, &savepipe, NULL); + (void)sigaction(SIGTERM, &saveterm, NULL); + (void)sigaction(SIGTSTP, &savetstp, NULL); + (void)sigaction(SIGTTIN, &savettin, NULL); + (void)sigaction(SIGTTOU, &savettou, NULL); + if (input != STDIN_FILENO) + (void)close(input); + + /* + * If we were interrupted by a signal, resend it to ourselves + * now that we have restored the signal handlers. + */ + for (i = 0; i < _NSIG; i++) { + if (signo[i]) { + kill(getpid(), i); + switch (i) { + case SIGTSTP: + case SIGTTIN: + case SIGTTOU: + need_restart = 1; + } + } + } + if (need_restart) + goto restart; + + if (save_errno) + errno = save_errno; + return(nr == -1 ? NULL : buf); +} + + +static void handler(int s) +{ + + signo[s] = 1; +} diff --git a/contrib/libs/libc_compat/reallocarray/reallocarray.c b/contrib/libs/libc_compat/reallocarray/reallocarray.c new file mode 100644 index 00000000000..21b0914fe48 --- /dev/null +++ b/contrib/libs/libc_compat/reallocarray/reallocarray.c @@ -0,0 +1,39 @@ +/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ +/* + * Copyright (c) 2008 Otto Moerbeek + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +/* + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW + */ +#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) + +void * +reallocarray(void *optr, size_t nmemb, size_t size) +{ + if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + nmemb > 0 && SIZE_MAX / nmemb < size) { + errno = ENOMEM; + return NULL; + } + return realloc(optr, size * nmemb); +} + diff --git a/contrib/libs/libc_compat/reallocarray/stdlib.h b/contrib/libs/libc_compat/reallocarray/stdlib.h new file mode 100644 index 00000000000..13496a79d00 --- /dev/null +++ b/contrib/libs/libc_compat/reallocarray/stdlib.h @@ -0,0 +1,24 @@ +// The lack of #pragma once is intentional: +// its presence breaks compilation of contrib/tools/unbound somehow. + +#if defined(__GNUC__) || defined(__clang__) + #include_next +#else + #ifdef Y_UCRT_INCLUDE_NEXT + #include Y_UCRT_INCLUDE_NEXT(stdlib.h) + #else + #define Y_UCRT_INCLUDE_NEXT(x) + #include Y_UCRT_INCLUDE_NEXT(stdlib.h) + #undef Y_UCRT_INCLUDE_NEXT + #endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +void* reallocarray(void*, size_t, size_t); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/contrib/libs/libc_compat/src/windows/sys/uio.c b/contrib/libs/libc_compat/src/windows/sys/uio.c new file mode 100644 index 00000000000..50c9542dc14 --- /dev/null +++ b/contrib/libs/libc_compat/src/windows/sys/uio.c @@ -0,0 +1,36 @@ +#include + +#include +#include +#include + +ssize_t readv(SOCKET sock, struct iovec const* iov, int iovcnt) { + WSABUF* wsabuf = (WSABUF*)alloca(iovcnt * sizeof(WSABUF)); + for (int i = 0; i < iovcnt; ++i) { + wsabuf[i].buf = iov[i].iov_base; + wsabuf[i].len = (u_long)iov[i].iov_len; + } + DWORD numberOfBytesRecv; + DWORD flags = 0; + int res = WSARecv(sock, wsabuf, iovcnt, &numberOfBytesRecv, &flags, NULL, NULL); + if (res == SOCKET_ERROR) { + errno = EIO; + return -1; + } + return numberOfBytesRecv; +} + +ssize_t writev(SOCKET sock, struct iovec const* iov, int iovcnt) { + WSABUF* wsabuf = (WSABUF*)alloca(iovcnt * sizeof(WSABUF)); + for (int i = 0; i < iovcnt; ++i) { + wsabuf[i].buf = iov[i].iov_base; + wsabuf[i].len = (u_long)iov[i].iov_len; + } + DWORD numberOfBytesSent; + int res = WSASend(sock, wsabuf, iovcnt, &numberOfBytesSent, 0, NULL, NULL); + if (res == SOCKET_ERROR) { + errno = EIO; + return -1; + } + return numberOfBytesSent; +} diff --git a/contrib/libs/libc_compat/stpcpy.c b/contrib/libs/libc_compat/stpcpy.c new file mode 100644 index 00000000000..5a86541f080 --- /dev/null +++ b/contrib/libs/libc_compat/stpcpy.c @@ -0,0 +1,44 @@ +/* $OpenBSD: stpcpy.c,v 1.3 2017/11/28 06:55:49 tb Exp $ */ + +/* + * Copyright (c) 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#if defined(APIWARN) +__warn_references(stpcpy, + "stpcpy() is dangerous; do not use it"); +#endif + +char * +stpcpy(char *to, const char *from) +{ + for (; (*to = *from) != '\0'; ++from, ++to); + return(to); +} diff --git a/contrib/libs/libc_compat/strcasestr.c b/contrib/libs/libc_compat/strcasestr.c new file mode 100644 index 00000000000..ee299b1c01f --- /dev/null +++ b/contrib/libs/libc_compat/strcasestr.c @@ -0,0 +1,61 @@ +/* $OpenBSD: strcasestr.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ +/* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include "string.h" + +/* + * Find the first occurrence of find in s, ignore case. + */ +char * +strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = (char)tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + diff --git a/contrib/libs/libc_compat/string.c b/contrib/libs/libc_compat/string.c new file mode 100644 index 00000000000..291f1103617 --- /dev/null +++ b/contrib/libs/libc_compat/string.c @@ -0,0 +1,16 @@ +#include +#include + +char* strupr(char* s) { + char* d; + for (d = s; *d; ++d) + *d = (char)toupper((int)*d); + return s; +} + +char* strlwr(char* s) { + char* d; + for (d = s; *d; ++d) + *d = (char)tolower((int)*d); + return s; +} diff --git a/contrib/libs/libc_compat/string.h b/contrib/libs/libc_compat/string.h new file mode 100644 index 00000000000..ad74d9a6300 --- /dev/null +++ b/contrib/libs/libc_compat/string.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(__FreeBSD__) && !defined(__APPLE__) +size_t strlcpy(char* dst, const char* src, size_t len); +size_t strlcat(char* dst, const char* src, size_t len); +#endif + +#if (!defined(__linux__) && !defined(__FreeBSD__) && !defined(__APPLE__)) || (defined(__ANDROID__) && __ANDROID_API__ < 21) +char* stpcpy(char* dst, const char* src); +#endif + +#if !defined(_MSC_VER) + +#define stricmp strcasecmp +#define strnicmp strncasecmp + +char* strlwr(char*); +char* strupr(char*); + +#else // _MSC_VER + +#define strcasecmp stricmp +#define strncasecmp strnicmp + +char* strcasestr(const char* s1, const char* s2); +char* strsep(char** stringp, const char* delim); + +#endif // _MSC_VER + +#if defined(_MSC_VER) || defined(__APPLE__) +void* memrchr(const void* s, int c, size_t n); +#endif + +#ifdef __cplusplus +} //extern "C" +#endif diff --git a/contrib/libs/libc_compat/strlcat.c b/contrib/libs/libc_compat/strlcat.c new file mode 100644 index 00000000000..d2198a2bdcd --- /dev/null +++ b/contrib/libs/libc_compat/strlcat.c @@ -0,0 +1,56 @@ +/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +} + diff --git a/contrib/libs/libc_compat/strlcpy.c b/contrib/libs/libc_compat/strlcpy.c new file mode 100644 index 00000000000..1797b86bb6e --- /dev/null +++ b/contrib/libs/libc_compat/strlcpy.c @@ -0,0 +1,51 @@ +/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +} + diff --git a/contrib/libs/libc_compat/strsep.c b/contrib/libs/libc_compat/strsep.c new file mode 100644 index 00000000000..ed605bce977 --- /dev/null +++ b/contrib/libs/libc_compat/strsep.c @@ -0,0 +1,71 @@ +/* $OpenBSD: strsep.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char * +strsep(char **stringp, const char *delim) +{ + char *s; + const char *spanp; + int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + diff --git a/contrib/libs/libc_compat/ubuntu_14/README.md b/contrib/libs/libc_compat/ubuntu_14/README.md new file mode 100644 index 00000000000..f7b17a40cc0 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/README.md @@ -0,0 +1,91 @@ +## Общие соображения + +В библиотеку добавлены реализации символов, появившихся в `libc.so.6` Ubuntu +14.04 с момента Ubuntu 12.04. + +Если какой-либо объектный файл ссылается на один из таких символов, то при +компоновке этот символ будет взят из нашей библиотеки. В противном случае, +компоновщик сослался бы на такой символ из `libc.so.6`, добавив к исполняемому +файлу зависимость от новой версии динамической библиотеки (`GLIBC_2.16`, +`GLIBC_2.17` или `GLIBC_2.18`). Такой исполняемый файл не может быть запущен на +Ubuntu 12.04, даже если ни один из новых символов не используется в runtime. + +На Ubuntu 14.04 или более новых, в случае если процесс загружает `libc.so.6`, мы +будем в runtime иметь две реализации символов, нашу и libc. Но все добавленные +функции не имеют какого-либо состояния и никакими деталями внутренней реализации +не связаны с другими. Нет разницы, какую из реализаций использовать, и даже +попеременное использование различных реализаций в одном и том же контексте не +должно приводить к некорректной работе. + +В какой-то момент этот слой совместимости будет отключен: https://st.yandex-team.ru/DEVTOOLS-7436 + +### Разделяемая реализация + +Была идея оформить новые реализации так, чтобы в случае их наличия и в +загруженной libc динамический компоновщик выбирал для всех ссылок одну +реализацию. + +По всей видимости, для этого требуется собирать исполняемый файл как PIE. Только +в этом случае для наших реализаций будут сгенерированы дополнительные PLT +прослойки и вызовы наших реализаций будут проходить через них. + +Но в этом случае вообще все вызовы будут происходить таким образом и это +повлияет на производительность. Ухудшения производительности, наверное, можно +избежать, явно указав, какие символы в исполняемом файле должны быть публичными, +но сейчас нет способа сделать это в одном месте, учитывая, что в некоторых +случаях этот список должен дополняться. + +## `getauxval` и `secure_getenv` + +Функция `getauxval` требует загрузки и хранения «Auxiliary Vector» (см. +[здесь](https://refspecs.linuxfoundation.org/LSB_1.3.0/IA64/spec/auxiliaryvector.html)). + +Эти данные доступны в момент запуска процесса. libc из новых Ubuntu сохраняет +эти данные и предоставляет реализацию `getauxval`. В этом случае наша реализация +перенаправляет вызовы `getauxval` в libc, получив при старте исполняемого файла +соответствующий указатель. + +Если реализация libc недоступна (на старых Ubuntu или если libc не загружена), +то эти данные можно получить, прочитав `/proc/self/auxv`. Это также делается +один раз при старте. + +В обоих случаях, статически инициализируется синглтон `NUbuntuCompat::TGlibc`, +который производит эти действия в конструкторе. + +`secure_getenv` использует одно из значений `getauxval`, поэтому к нему всё это +также относится. + +Каждый метод новой libc реализован в отдельном объектом файле. `TGlibc` также +находится в отдельном файле, и ссылки на неё стоят только в местах использования. +Если при компоновке не понадобились ни `getauxval`, ни `secure_getenv`, то +объектный файл с `TGlibc` тоже не будет выбран компоновщиком, и в этом случае +никакой лишней статической инициализации выполняться не будет. + +## Патч libc.so + +Чтобы иметь возможность использовать `getauxval` (точнее его реализацию +`__getauxval`) из новой libc, если таковая уже используется процессом, +библиотека совместимости объявляет этот символ у себя как внешний и слабый. При +загрузке динамический компоновщик устанавливает значение этого символа из libc +или `nullptr`, если его там нет. Наша реализация `getauxval` проверяет +доступность реализации libc, просто сравнивая указатель с `nullptr`. + +В Аркадии также есть код, который подобным образом работает с символом +`__cxa_thread_atexit_impl`. + +Однако, если компоновать такую программу с использованием новой libc, то к таким +символам и самой программе будет приписано требование соответствующей (новой) +версии libc. Чтобы этого не произошло, при сборке с этой библиотекой +совместимости используется патченный вариант `libc.so.6`, где у таких символов +удалена версия. + +Также, файлы, проверяющие, что доступна реализация из libc, должны быть собраны +как PIC. В противном случае вместо значения, заполненного динамическим +компоновщиком, компилятор ещё на стадии компиляции использует `nullptr` и +проверка никогда не срабатывает. + +## Упоминания + +Идея о возможности добавить слой совместимости была взята из ClickHouse. +* [https://clickhouse.tech/](https://clickhouse.tech/) +* [https://wiki.yandex-team.ru/clickhouse/](https://wiki.yandex-team.ru/clickhouse/) diff --git a/contrib/libs/libc_compat/ubuntu_14/aligned_alloc.c b/contrib/libs/libc_compat/ubuntu_14/aligned_alloc.c new file mode 100644 index 00000000000..c4a1378624f --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/aligned_alloc.c @@ -0,0 +1,6 @@ +#include +#include + +__attribute__((weak)) void* aligned_alloc(size_t alignment, size_t size) { + return memalign(alignment, size); +} diff --git a/contrib/libs/libc_compat/ubuntu_14/c16rtomb.c b/contrib/libs/libc_compat/ubuntu_14/c16rtomb.c new file mode 100644 index 00000000000..39ca3758fa1 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/c16rtomb.c @@ -0,0 +1,35 @@ +#include +#include +#include + +size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) +{ + static unsigned internal_state; + if (!ps) ps = (void *)&internal_state; + unsigned *x = (unsigned *)ps; + wchar_t wc; + + if (!s) { + if (*x) goto ilseq; + return 1; + } + + if (!*x && c16 - 0xd800u < 0x400) { + *x = c16 - 0xd7c0 << 10; + return 0; + } + + if (*x) { + if (c16 - 0xdc00u >= 0x400) goto ilseq; + else wc = *x + c16 - 0xdc00; + *x = 0; + } else { + wc = c16; + } + return wcrtomb(s, wc, 0); + +ilseq: + *x = 0; + errno = EILSEQ; + return -1; +} diff --git a/contrib/libs/libc_compat/ubuntu_14/c32rtomb.c b/contrib/libs/libc_compat/ubuntu_14/c32rtomb.c new file mode 100644 index 00000000000..67851328e88 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/c32rtomb.c @@ -0,0 +1,7 @@ +#include +#include + +size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps) +{ + return wcrtomb(s, c32, ps); +} diff --git a/contrib/libs/libc_compat/ubuntu_14/features.h b/contrib/libs/libc_compat/ubuntu_14/features.h new file mode 100644 index 00000000000..9fbab45ab5b --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/features.h @@ -0,0 +1,5 @@ +#pragma once + +#define weak __attribute__((__weak__)) +#define weak_alias(old, new) \ + extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) diff --git a/contrib/libs/libc_compat/ubuntu_14/getauxval.cpp b/contrib/libs/libc_compat/ubuntu_14/getauxval.cpp new file mode 100644 index 00000000000..9f20dd01953 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/getauxval.cpp @@ -0,0 +1,10 @@ +#include + +#include "glibc.h" +#include "features.h" + +extern "C" { + unsigned long getauxval(unsigned long item) noexcept { + return NUbuntuCompat::GetGlibc().GetAuxVal(item); + } +} diff --git a/contrib/libs/libc_compat/ubuntu_14/glibc.cpp b/contrib/libs/libc_compat/ubuntu_14/glibc.cpp new file mode 100644 index 00000000000..1cc444bce1f --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/glibc.cpp @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "glibc.h" +#include "features.h" + +namespace { + void ReadAuxVector(Elf64_auxv_t** begin, Elf64_auxv_t** end) noexcept { + int fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC); + if (fd == -1) { + return; + } + + constexpr size_t item_size = sizeof(Elf64_auxv_t); + constexpr size_t block_size = item_size * 32; + + size_t bytes_read = 0; + size_t size = 0; + + struct TBuffer { + ~TBuffer() { + free(Pointer); + } + char* Pointer = nullptr; + } buffer; + + while (true) { + size_t bytes_left = size - bytes_read; + + if (!bytes_left) { + size += block_size; + char* new_buffer = (char*)realloc(buffer.Pointer, size); + if (!new_buffer) { + return; + } + buffer.Pointer = new_buffer; + continue; + } + + ssize_t r = read(fd, buffer.Pointer + bytes_read, bytes_left); + if (!r) { + break; + } else if (r < 0) { + if (errno == EINTR) { + continue; + } else { + return; + } + } + + bytes_read += r; + } + + size_t item_count = bytes_read / item_size; + *begin = (Elf64_auxv_t*)buffer.Pointer; + *end = (Elf64_auxv_t*)(buffer.Pointer + item_count * item_size); + buffer.Pointer = nullptr; + } +} + +extern "C" { + weak unsigned long __getauxval(unsigned long item); +} + +namespace NUbuntuCompat { + + TGlibc::TGlibc() noexcept + : AuxVectorBegin(nullptr) + , AuxVectorEnd(nullptr) + { + if (!__getauxval) { + ReadAuxVector((Elf64_auxv_t**)&AuxVectorBegin, (Elf64_auxv_t**)&AuxVectorEnd); + } + + Secure = (bool)GetAuxVal(AT_SECURE); + } + + TGlibc::~TGlibc() noexcept { + free(AuxVectorBegin); + } + + unsigned long TGlibc::GetAuxVal(unsigned long item) noexcept { + if (__getauxval) { + return __getauxval(item); + } + + for (Elf64_auxv_t* p = (Elf64_auxv_t*)AuxVectorBegin; p < (Elf64_auxv_t*)AuxVectorEnd; ++p) { + if (p->a_type == item) { + return p->a_un.a_val; + } + } + + errno = ENOENT; + return 0; + } + + bool TGlibc::IsSecure() noexcept { + return Secure; + } + + static TGlibc __attribute__((__init_priority__(101))) GlibcInstance; + + TGlibc& GetGlibc() noexcept { + return GlibcInstance; + } +} diff --git a/contrib/libs/libc_compat/ubuntu_14/glibc.h b/contrib/libs/libc_compat/ubuntu_14/glibc.h new file mode 100644 index 00000000000..fdabcb01581 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/glibc.h @@ -0,0 +1,20 @@ +#pragma once + +typedef unsigned long (*TGetAuxVal)(unsigned long); + +namespace NUbuntuCompat { + class TGlibc { + public: + TGlibc() noexcept; + ~TGlibc() noexcept; + unsigned long GetAuxVal(unsigned long item) noexcept; + bool IsSecure() noexcept; + + private: + void* AuxVectorBegin; + void* AuxVectorEnd; + bool Secure; + }; + + TGlibc& GetGlibc() noexcept; +} diff --git a/contrib/libs/libc_compat/ubuntu_14/mbrtoc16.c b/contrib/libs/libc_compat/ubuntu_14/mbrtoc16.c new file mode 100644 index 00000000000..765ff9037cd --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/mbrtoc16.c @@ -0,0 +1,30 @@ +#include +#include + +size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + static unsigned internal_state; + if (!ps) ps = (void *)&internal_state; + unsigned *pending = (unsigned *)ps; + + if (!s) return mbrtoc16(0, "", 1, ps); + + /* mbrtowc states for partial UTF-8 characters have the high bit set; + * we use nonzero states without high bit for pending surrogates. */ + if ((int)*pending > 0) { + if (pc16) *pc16 = *pending; + *pending = 0; + return -3; + } + + wchar_t wc; + size_t ret = mbrtowc(&wc, s, n, ps); + if (ret <= 4) { + if (wc >= 0x10000) { + *pending = (wc & 0x3ff) + 0xdc00; + wc = 0xd7c0 + (wc >> 10); + } + if (pc16) *pc16 = wc; + } + return ret; +} diff --git a/contrib/libs/libc_compat/ubuntu_14/mbrtoc32.c b/contrib/libs/libc_compat/ubuntu_14/mbrtoc32.c new file mode 100644 index 00000000000..9b6b2367398 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/mbrtoc32.c @@ -0,0 +1,13 @@ +#include +#include + +size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + static unsigned internal_state; + if (!ps) ps = (void *)&internal_state; + if (!s) return mbrtoc32(0, "", 1, ps); + wchar_t wc; + size_t ret = mbrtowc(&wc, s, n, ps); + if (ret <= 4 && pc32) *pc32 = wc; + return ret; +} diff --git a/contrib/libs/libc_compat/ubuntu_14/secure_getenv.cpp b/contrib/libs/libc_compat/ubuntu_14/secure_getenv.cpp new file mode 100644 index 00000000000..14e3e90906a --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/secure_getenv.cpp @@ -0,0 +1,12 @@ +#include + +#include "glibc.h" + +extern "C" { + char *secure_getenv(const char *name) noexcept { + if (NUbuntuCompat::GetGlibc().IsSecure()) { + return nullptr; + } + return getenv(name); + } +} diff --git a/contrib/libs/libc_compat/ubuntu_14/timespec_get.c b/contrib/libs/libc_compat/ubuntu_14/timespec_get.c new file mode 100644 index 00000000000..742b62ec847 --- /dev/null +++ b/contrib/libs/libc_compat/ubuntu_14/timespec_get.c @@ -0,0 +1,10 @@ +#include + +/* There is no other implemented value than TIME_UTC; all other values + * are considered erroneous. */ +int timespec_get(struct timespec * ts, int base) +{ + if (base != TIME_UTC) return 0; + int ret = clock_gettime(CLOCK_REALTIME, ts); + return ret < 0 ? 0 : base; +} diff --git a/contrib/libs/lzmasdk/CMakeLists.txt b/contrib/libs/lzmasdk/CMakeLists.txt index 4c09d22ef65..845b8f3b6d7 100644 --- a/contrib/libs/lzmasdk/CMakeLists.txt +++ b/contrib/libs/lzmasdk/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(contrib-libs-lzmasdk) +_ydb_sdk_add_library(contrib-libs-lzmasdk) target_compile_options(contrib-libs-lzmasdk PRIVATE -D_7ZIP_ST=1 diff --git a/contrib/libs/lzmasdk/ya.make b/contrib/libs/lzmasdk/ya.make deleted file mode 100644 index eea4951ce08..00000000000 --- a/contrib/libs/lzmasdk/ya.make +++ /dev/null @@ -1,32 +0,0 @@ -LIBRARY() - -LICENSE(Public-Domain) - -LICENSE_TEXTS(.yandex_meta/licenses.list.txt) - -# https://www.7-zip.org/sdk.html -VERSION(19.00) - -CFLAGS(-D_7ZIP_ST=1) - -NO_UTIL() - -SRCS( - 7zStream.c - Aes.c - AesOpt.c - Alloc.c - Bra.c - Bra86.c - BraIA64.c - CpuArch.c - LzFind.c - Lzma2Dec.c - Lzma2Enc.c - LzmaDec.c - LzmaEnc.c - LzmaLib.c - Sha256.c -) - -END() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 35434afb096..b143e6eb9a5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,11 +1,3 @@ - -# This file was generated by the build system used internally in the Yandex monorepo. -# Only simple modifications are allowed (adding source-files to targets, adding simple properties -# like target_include_directories). These modifications will be ported to original -# ya.make files by maintainers. Any complex modifications which can't be ported back to the -# original buildsystem will not be accepted. - - add_subdirectory(basic_example) add_subdirectory(bulk_upsert_simple) add_subdirectory(pagination) diff --git a/examples/basic_example/CMakeLists.txt b/examples/basic_example/CMakeLists.txt index 55e4af14175..7c6f6227dce 100644 --- a/examples/basic_example/CMakeLists.txt +++ b/examples/basic_example/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(basic_example) target_link_libraries(basic_example PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -16,7 +16,7 @@ vcs_info(basic_example) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(basic_example PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/basic_example/basic_example.cpp b/examples/basic_example/basic_example.cpp index e52092d8f8c..38961951d9b 100644 --- a/examples/basic_example/basic_example.cpp +++ b/examples/basic_example/basic_example.cpp @@ -1,6 +1,6 @@ #include "basic_example.h" -#include +#include #include #include @@ -24,7 +24,7 @@ static void ThrowOnError(const TStatus& status) { static void PrintStatus(const TStatus& status) { std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl; - status.GetIssues().PrintTo(std::cerr); + std::cerr << status.GetIssues().ToString(); } static std::string JoinPath(const std::string& basePath, const std::string& path) { diff --git a/examples/basic_example/main.cpp b/examples/basic_example/main.cpp index 0bfc0d3e878..86320b12a4f 100644 --- a/examples/basic_example/main.cpp +++ b/examples/basic_example/main.cpp @@ -1,6 +1,6 @@ #include "basic_example.h" -#include +#include #include #include diff --git a/examples/bulk_upsert_simple/CMakeLists.txt b/examples/bulk_upsert_simple/CMakeLists.txt index 382c91a37d0..4f7c3eca7f9 100644 --- a/examples/bulk_upsert_simple/CMakeLists.txt +++ b/examples/bulk_upsert_simple/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(bulk_upsert_simple) target_link_libraries(bulk_upsert_simple PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -14,7 +14,7 @@ vcs_info(bulk_upsert_simple) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(bulk_upsert_simple PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/bulk_upsert_simple/main.cpp b/examples/bulk_upsert_simple/main.cpp index d3a25e36cc7..7b194f7f856 100644 --- a/examples/bulk_upsert_simple/main.cpp +++ b/examples/bulk_upsert_simple/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include @@ -53,7 +53,7 @@ bool WriteLogBatch(NYdb::NTable::TTableClient& tableClient, const std::string& t auto status = tableClient.RetryOperationSync(bulkUpsertOperation, retrySettings); if (!status.IsSuccess()) { - std::cerr << std::endl << "Write failed with status: " << (const NYdb::TStatus&)status << std::endl; + std::cerr << std::endl << "Write failed with status: " << ToString(status) << std::endl; return false; } return true; @@ -77,7 +77,7 @@ bool CreateLogTable(NYdb::NTable::TTableClient& client, const std::string& table }, settings); if (!status.IsSuccess()) { - std::cerr << "Create table failed with status: " << status << std::endl; + std::cerr << "Create table failed with status: " << ToString(status) << std::endl; return false; } return true; diff --git a/examples/pagination/CMakeLists.txt b/examples/pagination/CMakeLists.txt index 6ba1fb0b509..0936f385585 100644 --- a/examples/pagination/CMakeLists.txt +++ b/examples/pagination/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(pagination) target_link_libraries(pagination PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -16,7 +16,7 @@ vcs_info(pagination) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(pagination PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/pagination/main.cpp b/examples/pagination/main.cpp index 1906666c33d..5345f5b83fa 100644 --- a/examples/pagination/main.cpp +++ b/examples/pagination/main.cpp @@ -1,6 +1,6 @@ #include "pagination.h" -#include +#include using namespace NLastGetopt; using namespace NYdb; diff --git a/examples/pagination/pagination.cpp b/examples/pagination/pagination.cpp index 051ed6f0c38..63a38285aaa 100644 --- a/examples/pagination/pagination.cpp +++ b/examples/pagination/pagination.cpp @@ -1,6 +1,6 @@ #include "pagination.h" -#include +#include #include @@ -25,7 +25,7 @@ static void ThrowOnError(const TStatus& status) { static void PrintStatus(const TStatus& status) { std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl; - status.GetIssues().PrintTo(std::cerr); + std::cerr << status.GetIssues().ToString(); } static std::string JoinPath(const std::string& basePath, const std::string& path) { diff --git a/examples/secondary_index/CMakeLists.txt b/examples/secondary_index/CMakeLists.txt index afe453b1029..6030de5f7f0 100644 --- a/examples/secondary_index/CMakeLists.txt +++ b/examples/secondary_index/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(secondary_index) target_link_libraries(secondary_index PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -21,7 +21,7 @@ vcs_info(secondary_index) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(secondary_index PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/secondary_index/secondary_index.h b/examples/secondary_index/secondary_index.h index d448934c00a..b2b1caa1e1e 100644 --- a/examples/secondary_index/secondary_index.h +++ b/examples/secondary_index/secondary_index.h @@ -3,7 +3,7 @@ #include #include -#include +#include //////////////////////////////////////////////////////////////////////////////// @@ -49,7 +49,7 @@ class TYdbErrorException : public yexception { out << "Status: " << ToString(e.Status.GetStatus()); if (e.Status.GetIssues()) { out << std::endl; - e.Status.GetIssues().PrintTo(out); + out << e.Status.GetIssues().ToString(); } return out; } diff --git a/examples/secondary_index/secondary_index_generate.cpp b/examples/secondary_index/secondary_index_generate.cpp index adf900e156d..56084fc7131 100644 --- a/examples/secondary_index/secondary_index_generate.cpp +++ b/examples/secondary_index/secondary_index_generate.cpp @@ -1,6 +1,6 @@ #include "secondary_index.h" -#include +#include #include diff --git a/examples/secondary_index/secondary_index_list.cpp b/examples/secondary_index/secondary_index_list.cpp index 8b6275816c1..e1502f5274e 100644 --- a/examples/secondary_index/secondary_index_list.cpp +++ b/examples/secondary_index/secondary_index_list.cpp @@ -1,6 +1,6 @@ #include "secondary_index.h" -#include +#include using namespace NLastGetopt; using namespace NYdb; diff --git a/examples/secondary_index_builtin/CMakeLists.txt b/examples/secondary_index_builtin/CMakeLists.txt index 0d69f81cf60..b46cc79159c 100644 --- a/examples/secondary_index_builtin/CMakeLists.txt +++ b/examples/secondary_index_builtin/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(secondary_index_builtin) target_link_libraries(secondary_index_builtin PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -20,7 +20,7 @@ vcs_info(secondary_index_builtin) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(secondary_index_builtin PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/secondary_index_builtin/secondary_index.h b/examples/secondary_index_builtin/secondary_index.h index e6d9fb72dc6..849b8e7f5e3 100644 --- a/examples/secondary_index_builtin/secondary_index.h +++ b/examples/secondary_index_builtin/secondary_index.h @@ -3,10 +3,10 @@ #include #include -#include -#include +#include +#include -#include +#include #define TABLE_USERS "users" #define TABLE_SERIES "series" @@ -60,7 +60,7 @@ class TYdbErrorException: public yexception { out << "Status:" << ToString(e.Status.GetStatus()); if (e.Status.GetIssues()) { out << std::endl; - e.Status.GetIssues().PrintTo(out); + out << e.Status.GetIssues().ToString(); } return out; } diff --git a/examples/secondary_index_builtin/secondary_index_fill.cpp b/examples/secondary_index_builtin/secondary_index_fill.cpp index 9b2cedac1cf..2da26052630 100644 --- a/examples/secondary_index_builtin/secondary_index_fill.cpp +++ b/examples/secondary_index_builtin/secondary_index_fill.cpp @@ -1,6 +1,6 @@ #include "secondary_index.h" -#include +#include using namespace NYdb; using namespace NYdb::NTable; diff --git a/examples/topic_reader/CMakeLists.txt b/examples/topic_reader/CMakeLists.txt index 4d548603b35..ce07f0ebbfe 100644 --- a/examples/topic_reader/CMakeLists.txt +++ b/examples/topic_reader/CMakeLists.txt @@ -1,11 +1,3 @@ - -# This file was generated by the build system used internally in the Yandex monorepo. -# Only simple modifications are allowed (adding source-files to targets, adding simple properties -# like target_include_directories). These modifications will be ported to original -# ya.make files by maintainers. Any complex modifications which can't be ported back to the -# original buildsystem will not be accepted. - - add_subdirectory(eventloop) add_subdirectory(simple) add_subdirectory(transaction) diff --git a/examples/topic_reader/eventloop/CMakeLists.txt b/examples/topic_reader/eventloop/CMakeLists.txt index f014ef2dcaa..2cdc984955f 100644 --- a/examples/topic_reader/eventloop/CMakeLists.txt +++ b/examples/topic_reader/eventloop/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(persqueue_reader_eventloop) target_link_libraries(persqueue_reader_eventloop PUBLIC yutil YDB-CPP-SDK::Topic - library-getopt + getopt ) target_sources(persqueue_reader_eventloop PRIVATE @@ -14,7 +14,7 @@ vcs_info(persqueue_reader_eventloop) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(persqueue_reader_eventloop PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/topic_reader/eventloop/main.cpp b/examples/topic_reader/eventloop/main.cpp index c2536a98f77..277faea6661 100644 --- a/examples/topic_reader/eventloop/main.cpp +++ b/examples/topic_reader/eventloop/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include struct TOptions { std::string Endpoint; diff --git a/examples/topic_reader/simple/CMakeLists.txt b/examples/topic_reader/simple/CMakeLists.txt index cb4d49127b9..68846ab215c 100644 --- a/examples/topic_reader/simple/CMakeLists.txt +++ b/examples/topic_reader/simple/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(simple_persqueue_reader) target_link_libraries(simple_persqueue_reader PUBLIC yutil YDB-CPP-SDK::Topic - library-getopt + getopt ) target_sources(simple_persqueue_reader PRIVATE @@ -14,7 +14,7 @@ vcs_info(simple_persqueue_reader) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(simple_persqueue_reader PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/topic_reader/simple/main.cpp b/examples/topic_reader/simple/main.cpp index 93b2b1876cf..5dfe4547446 100644 --- a/examples/topic_reader/simple/main.cpp +++ b/examples/topic_reader/simple/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include struct TOptions { std::string Endpoint; diff --git a/examples/topic_reader/transaction/CMakeLists.txt b/examples/topic_reader/transaction/CMakeLists.txt index ffff17a518b..64d30b4d8c6 100644 --- a/examples/topic_reader/transaction/CMakeLists.txt +++ b/examples/topic_reader/transaction/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(read_from_topic_in_transaction) target_link_libraries(read_from_topic_in_transaction PUBLIC yutil YDB-CPP-SDK::Topic - library-getopt + getopt ) target_sources(read_from_topic_in_transaction PRIVATE @@ -16,7 +16,7 @@ vcs_info(read_from_topic_in_transaction) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(read_from_topic_in_transaction PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/topic_reader/transaction/application.cpp b/examples/topic_reader/transaction/application.cpp index e6da70021b0..d30891d3922 100644 --- a/examples/topic_reader/transaction/application.cpp +++ b/examples/topic_reader/transaction/application.cpp @@ -13,7 +13,7 @@ TApplication::TApplication(const TOptions& options) .SetEndpoint(options.Endpoint) .SetDatabase(options.Database) .SetAuthToken(std::getenv("YDB_TOKEN") ? std::getenv("YDB_TOKEN") : "") - .SetLog(std::unique_ptr(CreateLogBackend("cerr", Min(options.LogPriority, TLOG_RESOURCES)).Release())); + .SetLog(std::unique_ptr(CreateLogBackend("cerr", std::min(options.LogPriority, TLOG_RESOURCES)).Release())); if (options.UseSecureConnection) { config.UseSecureConnection(); } @@ -120,7 +120,7 @@ void TApplication::CommitTransaction() auto result = Transaction->Commit(settings).GetValueSync(); - std::cout << "Commit: " << static_cast(result) << std::endl; + std::cout << "Commit: " << ToString(static_cast(result)) << std::endl; } void TApplication::TryCommitTransaction() diff --git a/examples/topic_reader/transaction/options.cpp b/examples/topic_reader/transaction/options.cpp index 9795b039434..2fc95d36979 100644 --- a/examples/topic_reader/transaction/options.cpp +++ b/examples/topic_reader/transaction/options.cpp @@ -1,5 +1,5 @@ #include "options.h" -#include +#include TOptions::TOptions(int argc, const char* argv[]) { diff --git a/examples/topic_reader/transaction/options.h b/examples/topic_reader/transaction/options.h index 1b1ff4aecd6..ec1901c6d6c 100644 --- a/examples/topic_reader/transaction/options.h +++ b/examples/topic_reader/transaction/options.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/examples/ttl/CMakeLists.txt b/examples/ttl/CMakeLists.txt index 5688ee7e8b5..48a004b4cc6 100644 --- a/examples/ttl/CMakeLists.txt +++ b/examples/ttl/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(ttl) target_link_libraries(ttl PUBLIC yutil - library-getopt + getopt YDB-CPP-SDK::Table ) @@ -15,7 +15,7 @@ vcs_info(ttl) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") target_link_libraries(ttl PUBLIC - library-cpuid_check + cpuid_check ) endif() diff --git a/examples/ttl/main.cpp b/examples/ttl/main.cpp index bf02375b1f9..1d98c1c01d2 100644 --- a/examples/ttl/main.cpp +++ b/examples/ttl/main.cpp @@ -1,6 +1,6 @@ #include "ttl.h" -#include +#include using namespace NLastGetopt; using namespace NYdb; diff --git a/examples/ttl/util.h b/examples/ttl/util.h index 31a7079d56e..5c25a660dd9 100644 --- a/examples/ttl/util.h +++ b/examples/ttl/util.h @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include #include @@ -28,7 +28,7 @@ inline void ThrowOnError(const TStatus& status) { inline void PrintStatus(const TStatus& status) { std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl; - status.GetIssues().PrintTo(std::cerr); + std::cerr << status.GetIssues().ToString(); } inline std::string JoinPath(const std::string& basePath, const std::string& path) { diff --git a/include/ydb-cpp-sdk/client/draft/ydb_scripting.h b/include/ydb-cpp-sdk/client/draft/ydb_scripting.h index c6f0a21765f..92fe47cb1b6 100644 --- a/include/ydb-cpp-sdk/client/draft/ydb_scripting.h +++ b/include/ydb-cpp-sdk/client/draft/ydb_scripting.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace NYdb { namespace NScripting { diff --git a/include/ydb-cpp-sdk/client/driver/driver.h b/include/ydb-cpp-sdk/client/driver/driver.h index 42723d4b5cc..8a1bc503af2 100644 --- a/include/ydb-cpp-sdk/client/driver/driver.h +++ b/include/ydb-cpp-sdk/client/driver/driver.h @@ -7,7 +7,7 @@ #include #include -#include +#include //////////////////////////////////////////////////////////////////////////////// diff --git a/include/ydb-cpp-sdk/client/extension_common/extension.h b/include/ydb-cpp-sdk/client/extension_common/extension.h index fb48c7878b3..fde78c96870 100644 --- a/include/ydb-cpp-sdk/client/extension_common/extension.h +++ b/include/ydb-cpp-sdk/client/extension_common/extension.h @@ -2,7 +2,7 @@ #include -#include +#include namespace Ydb { namespace Discovery { diff --git a/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_client.h b/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_client.h index 92ac04813a3..94ccd852a48 100644 --- a/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_client.h +++ b/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_client.h @@ -2,11 +2,11 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace NSolomonStatExtension { diff --git a/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_connector.h b/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_connector.h index e9005bef58e..35d41919cc2 100644 --- a/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_connector.h +++ b/include/ydb-cpp-sdk/client/extensions/solomon_stats/pull_connector.h @@ -2,7 +2,7 @@ #include -#include +#include namespace NSolomonStatExtension { diff --git a/include/ydb-cpp-sdk/client/federated_topic/federated_topic.h b/include/ydb-cpp-sdk/client/federated_topic/federated_topic.h index 003b14961ac..f952fd6c541 100644 --- a/include/ydb-cpp-sdk/client/federated_topic/federated_topic.h +++ b/include/ydb-cpp-sdk/client/federated_topic/federated_topic.h @@ -2,7 +2,7 @@ #include -#include +#include #include diff --git a/include/ydb-cpp-sdk/client/iam/common/iam.h b/include/ydb-cpp-sdk/client/iam/common/iam.h index 11372c13db9..af39877c0b1 100644 --- a/include/ydb-cpp-sdk/client/iam/common/iam.h +++ b/include/ydb-cpp-sdk/client/iam/common/iam.h @@ -3,13 +3,13 @@ #include #include -#include +#include #include -#include +#include -#include -#include +#include +#include #include diff --git a/include/ydb-cpp-sdk/client/proto/accessor.h b/include/ydb-cpp-sdk/client/proto/accessor.h index 56bf8f1e9ed..390f7f502cd 100644 --- a/include/ydb-cpp-sdk/client/proto/accessor.h +++ b/include/ydb-cpp-sdk/client/proto/accessor.h @@ -1,13 +1,13 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/include/ydb-cpp-sdk/client/query/query.h b/include/ydb-cpp-sdk/client/query/query.h index fda29204be0..bdb01e5b79b 100644 --- a/include/ydb-cpp-sdk/client/query/query.h +++ b/include/ydb-cpp-sdk/client/query/query.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace NYdb::NQuery { diff --git a/include/ydb-cpp-sdk/client/query/stats.h b/include/ydb-cpp-sdk/client/query/stats.h index d52eafca296..617cbd976c5 100644 --- a/include/ydb-cpp-sdk/client/query/stats.h +++ b/include/ydb-cpp-sdk/client/query/stats.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/client/query/tx.h b/include/ydb-cpp-sdk/client/query/tx.h index acc72c8e270..c73e0b8c1d9 100644 --- a/include/ydb-cpp-sdk/client/query/tx.h +++ b/include/ydb-cpp-sdk/client/query/tx.h @@ -2,7 +2,7 @@ #include -#include +#include #include diff --git a/include/ydb-cpp-sdk/client/retry/retry.h b/include/ydb-cpp-sdk/client/retry/retry.h index 102f601e7a5..36bbd23a8f6 100644 --- a/include/ydb-cpp-sdk/client/retry/retry.h +++ b/include/ydb-cpp-sdk/client/retry/retry.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace NYdb::NRetry { diff --git a/include/ydb-cpp-sdk/client/topic/codecs.h b/include/ydb-cpp-sdk/client/topic/codecs.h index bf195b0b371..a1e2e288da7 100644 --- a/include/ydb-cpp-sdk/client/topic/codecs.h +++ b/include/ydb-cpp-sdk/client/topic/codecs.h @@ -1,12 +1,12 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/client/topic/control_plane.h b/include/ydb-cpp-sdk/client/topic/control_plane.h index abeb47ecbef..8f1e37ed16b 100644 --- a/include/ydb-cpp-sdk/client/topic/control_plane.h +++ b/include/ydb-cpp-sdk/client/topic/control_plane.h @@ -6,7 +6,7 @@ #include -#include +#include #include diff --git a/include/ydb-cpp-sdk/client/topic/counters.h b/include/ydb-cpp-sdk/client/topic/counters.h index bad68a7acde..8d44dc131c2 100644 --- a/include/ydb-cpp-sdk/client/topic/counters.h +++ b/include/ydb-cpp-sdk/client/topic/counters.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace NYdb::NTopic { diff --git a/include/ydb-cpp-sdk/client/topic/events_common.h b/include/ydb-cpp-sdk/client/topic/events_common.h index 468e063f67e..384bc435239 100644 --- a/include/ydb-cpp-sdk/client/topic/events_common.h +++ b/include/ydb-cpp-sdk/client/topic/events_common.h @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include namespace NYdb::NTopic { diff --git a/include/ydb-cpp-sdk/client/topic/executor.h b/include/ydb-cpp-sdk/client/topic/executor.h index 9bf5079ca25..277ff2c48e5 100644 --- a/include/ydb-cpp-sdk/client/topic/executor.h +++ b/include/ydb-cpp-sdk/client/topic/executor.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include diff --git a/include/ydb-cpp-sdk/client/topic/read_events.h b/include/ydb-cpp-sdk/client/topic/read_events.h index 082c235a4d1..38745e3bd17 100644 --- a/include/ydb-cpp-sdk/client/topic/read_events.h +++ b/include/ydb-cpp-sdk/client/topic/read_events.h @@ -3,7 +3,7 @@ #include "codecs.h" #include "events_common.h" -#include +#include namespace NYdb::NTopic { diff --git a/include/ydb-cpp-sdk/client/topic/read_session.h b/include/ydb-cpp-sdk/client/topic/read_session.h index 73d34d43f6d..249de9b6462 100644 --- a/include/ydb-cpp-sdk/client/topic/read_session.h +++ b/include/ydb-cpp-sdk/client/topic/read_session.h @@ -9,9 +9,9 @@ #include #include -#include +#include -#include +#include namespace NYdb::NTable { class TTransaction; diff --git a/include/ydb-cpp-sdk/client/topic/retry_policy.h b/include/ydb-cpp-sdk/client/topic/retry_policy.h index e661141df70..8aef9f3556a 100644 --- a/include/ydb-cpp-sdk/client/topic/retry_policy.h +++ b/include/ydb-cpp-sdk/client/topic/retry_policy.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace NYdb::NTopic { diff --git a/include/ydb-cpp-sdk/client/topic/write_events.h b/include/ydb-cpp-sdk/client/topic/write_events.h index fa1ca8c721e..56413200cd8 100644 --- a/include/ydb-cpp-sdk/client/topic/write_events.h +++ b/include/ydb-cpp-sdk/client/topic/write_events.h @@ -5,7 +5,7 @@ #include #include -#include +#include namespace NYdb::NTopic { diff --git a/include/ydb-cpp-sdk/client/topic/write_session.h b/include/ydb-cpp-sdk/client/topic/write_session.h index 69ad80a1254..aed5cc9a8c9 100644 --- a/include/ydb-cpp-sdk/client/topic/write_session.h +++ b/include/ydb-cpp-sdk/client/topic/write_session.h @@ -9,7 +9,7 @@ #include #include -#include +#include namespace NYdb::NTable { class TTransaction; diff --git a/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/credentials.h b/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/credentials.h index 2f87493a5f6..72aa395f51d 100644 --- a/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/credentials.h +++ b/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/credentials.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include diff --git a/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/jwt_token_source.h b/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/jwt_token_source.h index 73b8826bcdb..53df0917f0e 100644 --- a/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/jwt_token_source.h +++ b/include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/jwt_token_source.h @@ -4,7 +4,7 @@ #include -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/client/types/exceptions/exceptions.h b/include/ydb-cpp-sdk/client/types/exceptions/exceptions.h index 87325b57f07..cd3c51bb857 100644 --- a/include/ydb-cpp-sdk/client/types/exceptions/exceptions.h +++ b/include/ydb-cpp-sdk/client/types/exceptions/exceptions.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/client/types/operation/operation.h b/include/ydb-cpp-sdk/client/types/operation/operation.h index 01bd0c1f347..722bf947a5e 100644 --- a/include/ydb-cpp-sdk/client/types/operation/operation.h +++ b/include/ydb-cpp-sdk/client/types/operation/operation.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/client/types/request_settings.h b/include/ydb-cpp-sdk/client/types/request_settings.h index 7650abb5b05..9543616ca52 100644 --- a/include/ydb-cpp-sdk/client/types/request_settings.h +++ b/include/ydb-cpp-sdk/client/types/request_settings.h @@ -2,7 +2,7 @@ #include "fluent_settings_helpers.h" -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/client/types/status/status.h b/include/ydb-cpp-sdk/client/types/status/status.h index 8a98365b110..611f43807a3 100644 --- a/include/ydb-cpp-sdk/client/types/status/status.h +++ b/include/ydb-cpp-sdk/client/types/status/status.h @@ -5,7 +5,7 @@ #include -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/client/value/value.h b/include/ydb-cpp-sdk/client/value/value.h index 8415e058248..907f15faa44 100644 --- a/include/ydb-cpp-sdk/client/value/value.h +++ b/include/ydb-cpp-sdk/client/value/value.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/library/cgiparam/cgiparam.h b/include/ydb-cpp-sdk/library/cgiparam/cgiparam.h deleted file mode 100644 index eec304692e0..00000000000 --- a/include/ydb-cpp-sdk/library/cgiparam/cgiparam.h +++ /dev/null @@ -1,191 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include -#include -#include -#include - -class TCgiParameters: public std::multimap> { -public: - TCgiParameters() = default; - - explicit TCgiParameters(const std::string_view cgiParamStr) { - Scan(cgiParamStr); - } - - TCgiParameters(std::initializer_list> il); - - void Flush() { - erase(begin(), end()); - } - - size_t EraseAll(const std::string_view name); - - size_t NumOfValues(const std::string_view name) const noexcept { - return count(name); - } - - std::string operator()() const { - return Print(); - } - - void Scan(const std::string_view cgiParStr, bool form = true); - void ScanAdd(const std::string_view cgiParStr); - void ScanAddUnescaped(const std::string_view cgiParStr); - void ScanAddAllUnescaped(const std::string_view cgiParStr); - void ScanAddAll(const std::string_view cgiParStr); - - /// Returns the string representation of all the stored parameters - /** - * @note The returned string has format =&=&... - * @note Names and values in the returned string are CGI-escaped. - */ - std::string Print() const; - char* Print(char* res) const; - - Y_PURE_FUNCTION - size_t PrintSize() const noexcept; - - /** The same as Print* except that RFC-3986 reserved characters are escaped. - * @param safe - set of characters to be skipped in escaping - */ - std::string QuotedPrint(const char* safe = "/") const; - - Y_PURE_FUNCTION - auto Range(const std::string_view name) const noexcept { - return IterateValues(MakeIteratorRange(equal_range(name))); - } - - Y_PURE_FUNCTION - const_iterator Find(const std::string_view name, size_t numOfValue = 0) const noexcept; - - Y_PURE_FUNCTION - bool Has(const std::string_view name, const std::string_view value) const noexcept; - - Y_PURE_FUNCTION - bool Has(const std::string_view name) const noexcept { - const auto pair = equal_range(name); - return pair.first != pair.second; - } - /** - * Returns value by name. - * - * @note The returned value is CGI-unescaped. - */ - Y_PURE_FUNCTION - const std::string& Get(const std::string_view name, size_t numOfValue = 0) const noexcept; - - void InsertEscaped(const std::string_view name, const std::string_view value); - -#if !defined(__GLIBCXX__) - template - inline void InsertUnescaped(TName&& name, TValue&& value) { - // std::string_view use as TName or TValue is C++17 actually. - // There is no pair constructor available in C++14 when required type - // is not implicitly constructible from given type. - // But libc++ pair allows this with C++14. - emplace(std::forward(name), std::forward(value)); - } -#else - template - inline void InsertUnescaped(TName&& name, TValue&& value) { - emplace(std::string(name), std::string(value)); - } -#endif - - // replace all values for a given key with new values - template - void ReplaceUnescaped(const std::string_view key, TIter valuesBegin, const TIter valuesEnd); - - void ReplaceUnescaped(const std::string_view key, std::initializer_list values) { - ReplaceUnescaped(key, values.begin(), values.end()); - } - - void ReplaceUnescaped(const std::string_view key, const std::string_view value) { - ReplaceUnescaped(key, {value}); - } - - // join multiple values into a single one using a separator - // if val is a [possibly empty] non-NULL string, append it as well - void JoinUnescaped(const std::string_view key, char sep, std::string_view val = std::string_view()); - - bool Erase(const std::string_view name, size_t numOfValue = 0); - bool Erase(const std::string_view name, const std::string_view val); - bool ErasePattern(const std::string_view name, const std::string_view pat); - - inline const char* FormField(const std::string_view name, size_t numOfValue = 0) const { - const_iterator it = Find(name, numOfValue); - - if (it == end()) { - return nullptr; - } - - return it->second.data(); - } - - inline std::string_view FormFieldBuf(const std::string_view name, size_t numOfValue = 0) const { - const_iterator it = Find(name, numOfValue); - - if (it == end()) { - return {}; - } - - return it->second.data(); - } -}; - -template -void TCgiParameters::ReplaceUnescaped(const std::string_view key, TIter valuesBegin, const TIter valuesEnd) { - const auto oldRange = equal_range(key); - auto current = oldRange.first; - - // reuse as many existing nodes as possible (probably none) - for (; valuesBegin != valuesEnd && current != oldRange.second; ++valuesBegin, ++current) { - current->second = *valuesBegin; - } - - // if there were more nodes than we need to insert then erase remaining ones - for (; current != oldRange.second; erase(current++)) { - } - - // if there were less nodes than we need to insert then emplace the rest of the range - if (valuesBegin != valuesEnd) { - const std::string keyStr = std::string(key); - for (; valuesBegin != valuesEnd; ++valuesBegin) { - emplace_hint(oldRange.second, keyStr, std::string(*valuesBegin)); - } - } -} - -/** TQuickCgiParam is a faster non-editable version of TCgiParameters. - * Care should be taken when replacing: - * - note that the result of Get() is invalidated when TQuickCgiParam object is destroyed. - */ - -class TQuickCgiParam: public std::multimap { -public: - TQuickCgiParam() = default; - - explicit TQuickCgiParam(const std::string_view cgiParamStr); - - Y_PURE_FUNCTION - bool Has(const std::string_view name, const std::string_view value) const noexcept; - - Y_PURE_FUNCTION - bool Has(const std::string_view name) const noexcept { - const auto pair = equal_range(name); - return pair.first != pair.second; - } - - Y_PURE_FUNCTION - const std::string_view& Get(const std::string_view name, size_t numOfValue = 0) const noexcept; - -private: - TTempBuf UnescapeBuf; -}; diff --git a/include/ydb-cpp-sdk/library/grpc/client/grpc_client_low.h b/include/ydb-cpp-sdk/library/grpc/client/grpc_client_low.h index 897882e35b8..180f6a51fe4 100644 --- a/include/ydb-cpp-sdk/library/grpc/client/grpc_client_low.h +++ b/include/ydb-cpp-sdk/library/grpc/client/grpc_client_low.h @@ -2,8 +2,8 @@ #include "grpc_common.h" -#include -#include +#include +#include #include #include #include diff --git a/include/ydb-cpp-sdk/library/grpc/client/grpc_common.h b/include/ydb-cpp-sdk/library/grpc/client/grpc_common.h index 97903bae64f..9f9d96198f1 100644 --- a/include/ydb-cpp-sdk/library/grpc/client/grpc_common.h +++ b/include/ydb-cpp-sdk/library/grpc/client/grpc_common.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/library/grpc/common/constants.h b/include/ydb-cpp-sdk/library/grpc/common/constants.h index 3004e85e171..14ff7105342 100644 --- a/include/ydb-cpp-sdk/library/grpc/common/constants.h +++ b/include/ydb-cpp-sdk/library/grpc/common/constants.h @@ -1,9 +1,9 @@ #pragma once -#include +#include namespace NYdbGrpc { -constexpr ui64 DEFAULT_GRPC_MESSAGE_SIZE_LIMIT = 64000000; +constexpr uint64_t DEFAULT_GRPC_MESSAGE_SIZE_LIMIT = 64000000; } diff --git a/include/ydb-cpp-sdk/library/http/io/stream.h b/include/ydb-cpp-sdk/library/http/io/stream.h deleted file mode 100644 index 737b448e493..00000000000 --- a/include/ydb-cpp-sdk/library/http/io/stream.h +++ /dev/null @@ -1,178 +0,0 @@ -#pragma once - -#include "headers.h" - -#include -#include -#include -#include -#include - -#include - -class TSocket; - -struct THttpException: public yexception { -}; - -struct THttpParseException: public THttpException { -}; - -struct THttpReadException: public THttpException { -}; - -/// Чтение ответа HTTP-сервера. -class THttpInput: public IInputStream { -public: - THttpInput(IInputStream* slave); - THttpInput(THttpInput&& httpInput); - ~THttpInput() override; - - /* - * parsed http headers - */ - /// Возвращает контейнер с заголовками ответа HTTP-сервера. - const THttpHeaders& Headers() const noexcept; - - /* - * parsed http trailers - */ - /// Возвращает контейнер (возможно пустой) с trailer'ами ответа HTTP-сервера. - /// Поток должен быть вычитан полностью прежде чем trailer'ы будут доступны. - /// Пока поток не вычитан до конца возвращается Nothing. - /// https://tools.ietf.org/html/rfc7230#section-4.1.2 - const std::optional& Trailers() const noexcept; - - /* - * first line - response or request - */ - /// Возвращает первую строку ответа HTTP-сервера. - /// @details Первая строка HTTP-сервера - строка состояния, - /// содержащая три поля: версию HTTP, код состояния и описание. - const std::string& FirstLine() const noexcept; - - /* - * connection can be keep-alive - */ - /// Проверяет, не завершено ли соединение с сервером. - /// @details Транзакция считается завершенной, если не передан заголовок - /// "Connection: Keep Alive". - bool IsKeepAlive() const noexcept; - - /* - * output data can be encoded - */ - /// Проверяет, поддерживается ли данный тип кодирования содержимого - /// ответа HTTP-сервера. - bool AcceptEncoding(const std::string& coding) const; - - /// Пытается определить наилучший тип кодирования ответа HTTP-сервера. - /// @details Если ответ сервера говорит о том, что поддерживаются - /// любые типы кодирования, выбирается gzip. В противном случае - /// из списка типов кодирования выбирается лучший из поддерживаемых сервером. - std::string BestCompressionScheme() const; - std::string BestCompressionScheme(std::span codings) const; - - /// Если заголовки содержат Content-Length, возвращает true и - /// записывает значение из заголовка в value - bool GetContentLength(ui64& value) const noexcept; - - /// Признак запакованности данных, - если выставлен, то Content-Length, при наличии в заголовках, - /// показывает объём запакованных данных, а из THttpInput мы будем вычитывать уже распакованные. - bool ContentEncoded() const noexcept; - - /// Returns true if Content-Length or Transfer-Encoding header received - bool HasContent() const noexcept; - - bool HasExpect100Continue() const noexcept; - -private: - size_t DoRead(void* buf, size_t len) override; - size_t DoSkip(size_t len) override; - -private: - class TImpl; - std::unique_ptr Impl_; -}; - -/// Передача запроса HTTP-серверу. -class THttpOutput: public IOutputStream { -public: - THttpOutput(IOutputStream* slave); - THttpOutput(IOutputStream* slave, THttpInput* request); - ~THttpOutput() override; - - /* - * sent http headers - */ - /// Возвращает контейнер с заголовками запроса к HTTP-серверу. - const THttpHeaders& SentHeaders() const noexcept; - - /// Устанавливает режим, при котором сервер выдает ответ в упакованном виде. - void EnableCompression(bool enable); - void EnableCompression(std::span schemas); - - /// Устанавливает режим, при котором соединение с сервером не завершается - /// после окончания транзакции. - void EnableKeepAlive(bool enable); - - /// Устанавливает режим, при котором тело HTTP-запроса/ответа преобразуется в соответствии - /// с заголовками Content-Encoding и Transfer-Encoding (включен по умолчанию) - void EnableBodyEncoding(bool enable); - - /// Устанавливает режим, при котором тело HTTP-ответа сжимается кодеком - /// указанным в Content-Encoding (включен по умолчанию) - void EnableCompressionHeader(bool enable); - - /// Проверяет, производится ли выдача ответов в упакованном виде. - bool IsCompressionEnabled() const noexcept; - - /// Проверяет, не завершается ли соединение с сервером после окончания транзакции. - bool IsKeepAliveEnabled() const noexcept; - - /// Проверяет, преобразуется ли тело HTTP-запроса/ответа в соответствии - /// с заголовками Content-Encoding и Transfer-Encoding - bool IsBodyEncodingEnabled() const noexcept; - - /// Проверяет, сжимается ли тело HTTP-ответа кодеком - /// указанным в Content-Encoding - bool IsCompressionHeaderEnabled() const noexcept; - - /* - * is this connection can be really keep-alive - */ - /// Проверяет, можно ли установить режим, при котором соединение с сервером - /// не завершается после окончания транзакции. - bool CanBeKeepAlive() const noexcept; - - void SendContinue(); - - /* - * first line - response or request - */ - /// Возвращает первую строку HTTP-запроса/ответа - const std::string& FirstLine() const noexcept; - - /// Возвращает размер отправленных данных (без заголовков, с учётом сжатия, без - /// учёта chunked transfer encoding) - size_t SentSize() const noexcept; - -private: - void DoWrite(const void* buf, size_t len) override; - void DoFlush() override; - void DoFinish() override; - -private: - class TImpl; - std::unique_ptr Impl_; -}; - -/// Возвращает код состояния из ответа сервера. -unsigned ParseHttpRetCode(const std::string_view& ret); - -/// Отправляет HTTP-серверу запрос с минимумом необходимых заголовков. -void SendMinimalHttpRequest(TSocket& s, const std::string_view& host, const std::string_view& request, const std::string_view& agent = "YandexSomething/1.0", const std::string_view& from = "webadmin@yandex.ru"); - -std::span SupportedCodings(); - -/// @} diff --git a/include/ydb-cpp-sdk/library/http/server/response.h b/include/ydb-cpp-sdk/library/http/server/response.h deleted file mode 100644 index c5226dac2b1..00000000000 --- a/include/ydb-cpp-sdk/library/http/server/response.h +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once - -#include -#include - -#include - -class THttpHeaders; -class IOutputStream; - -class THttpResponse { -public: - THttpResponse() noexcept - : Code(HTTP_OK) - { - } - - explicit THttpResponse(HttpCodes code) noexcept - : Code(code) - { - } - - template - THttpResponse& AddHeader(const std::string& name, const ValueType& value) { - return AddHeader(THttpInputHeader(name, ToString(value))); - } - - THttpResponse& AddHeader(const THttpInputHeader& header) { - Headers.AddHeader(header); - - return *this; - } - - template - THttpResponse& AddOrReplaceHeader(const std::string& name, const ValueType& value) { - return AddOrReplaceHeader(THttpInputHeader(name, ToString(value))); - } - - THttpResponse& AddOrReplaceHeader(const THttpInputHeader& header) { - Headers.AddOrReplaceHeader(header); - - return *this; - } - - THttpResponse& AddMultipleHeaders(const THttpHeaders& headers); - - const THttpHeaders& GetHeaders() const { - return Headers; - } - - THttpResponse& SetContentType(const std::string_view& contentType); - - /** - * @note If @arg content isn't empty its size is automatically added as a - * "Content-Length" header during output to IOutputStream. - * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&) - */ - THttpResponse& SetContent(const std::string& content) { - Content = content; - - return *this; - } - - THttpResponse& SetContent(std::string&& content) { - Content = std::move(content); - - return *this; - } - - std::string GetContent() const { - return Content; - } - - /** - * @note If @arg content isn't empty its size is automatically added as a - * "Content-Length" header during output to IOutputStream. - * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&) - */ - THttpResponse& SetContent(const std::string& content, const std::string_view& contentType) { - return SetContent(content).SetContentType(contentType); - } - - HttpCodes HttpCode() const { - return Code; - } - - THttpResponse& SetHttpCode(HttpCodes code) { - Code = code; - return *this; - } - - void OutTo(IOutputStream& out) const; - -private: - HttpCodes Code; - THttpHeaders Headers; - std::string Content; -}; diff --git a/include/ydb-cpp-sdk/library/json/common/defs.h b/include/ydb-cpp-sdk/library/json/common/defs.h deleted file mode 100644 index ac428dee17f..00000000000 --- a/include/ydb-cpp-sdk/library/json/common/defs.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include - -namespace NJson { - class TJsonException: public yexception { - }; - - class TJsonCallbacks { - public: - explicit TJsonCallbacks(bool throwException = false) - : ThrowException(throwException) - { - } - - virtual ~TJsonCallbacks(); - - virtual bool OnNull(); - virtual bool OnBoolean(bool); - virtual bool OnInteger(long long); - virtual bool OnUInteger(unsigned long long); - virtual bool OnDouble(double); - virtual bool OnString(const std::string_view&); - virtual bool OnOpenMap(); - virtual bool OnMapKey(const std::string_view&); - virtual bool OnCloseMap(); - virtual bool OnOpenArray(); - virtual bool OnCloseArray(); - virtual bool OnStringNoCopy(const std::string_view& s); - virtual bool OnMapKeyNoCopy(const std::string_view& s); - virtual bool OnEnd(); - virtual void OnError(size_t off, std::string_view reason); - - bool GetHaveErrors() const { - return HaveErrors; - } - protected: - bool ThrowException; - bool HaveErrors = false; - }; -} diff --git a/include/ydb-cpp-sdk/library/json/fast_sax/parser.h b/include/ydb-cpp-sdk/library/json/fast_sax/parser.h deleted file mode 100644 index 1189a78d302..00000000000 --- a/include/ydb-cpp-sdk/library/json/fast_sax/parser.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -namespace NJson { - bool ReadJsonFast(std::string_view in, TJsonCallbacks* callbacks); - - inline bool ValidateJsonFast(std::string_view in, bool throwOnError = false) { - Y_ASSERT(false); // this method is broken, see details in IGNIETFERRO-1243. Use NJson::ValidateJson instead, or fix this one before using - TJsonCallbacks c(throwOnError); - return ReadJsonFast(in, &c); - } -} diff --git a/include/ydb-cpp-sdk/library/json/json_reader.h b/include/ydb-cpp-sdk/library/json/json_reader.h deleted file mode 100644 index 6df4e01648f..00000000000 --- a/include/ydb-cpp-sdk/library/json/json_reader.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once - -#include "json_value.h" - -#include -#include - -#include - -namespace NJson { - struct TJsonReaderConfig { - TJsonReaderConfig(); - - bool UseIterativeParser = false; - // js-style comments (both // and /**/) - bool AllowComments = false; - bool DontValidateUtf8 = false; - //bool AllowEscapedApostrophe = false; - - ui64 MaxDepth = 0; - - void SetBufferSize(size_t bufferSize); - size_t GetBufferSize() const; - - private: - size_t BufferSize; - }; - - bool ReadJsonTree(std::string_view in, TJsonValue* out, bool throwOnError = false); - bool ReadJsonTree(std::string_view in, bool allowComments, TJsonValue* out, bool throwOnError = false); - bool ReadJsonTree(std::string_view in, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError = false); - - bool ReadJsonTree(IInputStream* in, TJsonValue* out, bool throwOnError = false); - bool ReadJsonTree(IInputStream* in, bool allowComments, TJsonValue* out, bool throwOnError = false); - bool ReadJsonTree(IInputStream* in, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError = false); - - TJsonValue ReadJsonTree(IInputStream* in, bool throwOnError = false); - TJsonValue ReadJsonTree(IInputStream* in, bool allowComments, bool throwOnError); - TJsonValue ReadJsonTree(IInputStream* in, const TJsonReaderConfig* config, bool throwOnError = false); - - bool ReadJson(IInputStream* in, TJsonCallbacks* callbacks); - bool ReadJson(IInputStream* in, bool allowComments, TJsonCallbacks* callbacks); - //bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* callbacks); - bool ReadJson(IInputStream* in, const TJsonReaderConfig* config, TJsonCallbacks* callbacks); - - enum ReaderConfigFlags { - ITERATIVE = 0b1000, - COMMENTS = 0b0100, - VALIDATE = 0b0010, - //ESCAPE = 0b0001, - }; - - inline bool ValidateJson(IInputStream* in, const TJsonReaderConfig* config, bool throwOnError = false) { - TJsonCallbacks c(throwOnError); - return ReadJson(in, config, &c); - } - - inline bool ValidateJson(std::string_view in, const TJsonReaderConfig& config = TJsonReaderConfig(), bool throwOnError = false) { - TMemoryInput min(in.data(), in.size()); - return ValidateJson(&min, &config, throwOnError); - } - - inline bool ValidateJsonThrow(IInputStream* in, const TJsonReaderConfig* config) { - return ValidateJson(in, config, true); - } - - inline bool ValidateJsonThrow(std::string_view in, const TJsonReaderConfig& config = TJsonReaderConfig()) { - return ValidateJson(in, config, true); - } - - class TParserCallbacks: public TJsonCallbacks { - public: - TParserCallbacks(TJsonValue& value, bool throwOnError = false, bool notClosedBracketIsError = false); - bool OnNull() override; - bool OnBoolean(bool val) override; - bool OnInteger(long long val) override; - bool OnUInteger(unsigned long long val) override; - bool OnString(const std::string_view& val) override; - bool OnDouble(double val) override; - bool OnOpenArray() override; - bool OnCloseArray() override; - bool OnOpenMap() override; - bool OnCloseMap() override; - bool OnMapKey(const std::string_view& val) override; - bool OnEnd() override; - - protected: - TJsonValue& Value; - std::string Key; - std::vector ValuesStack; - bool NotClosedBracketIsError; - - enum { - START, - AFTER_MAP_KEY, - IN_MAP, - IN_ARRAY, - FINISH - } CurrentState; - - template - bool SetValue(const T& value) { - switch (CurrentState) { - case START: - Value.SetValue(value); - break; - case AFTER_MAP_KEY: - ValuesStack.back()->InsertValue(Key, value); - CurrentState = IN_MAP; - break; - case IN_ARRAY: - ValuesStack.back()->AppendValue(value); - break; - case IN_MAP: - case FINISH: - return false; - default: - ythrow yexception() << "TParserCallbacks::SetValue invalid enum"; - } - return true; - } - - bool OpenComplexValue(EJsonValueType type); - bool CloseComplexValue(); - }; - - //// relaxed json, used in src/library/scheme - bool ReadJsonFastTree(std::string_view in, TJsonValue* out, bool throwOnError = false, bool notClosedBracketIsError = false); - TJsonValue ReadJsonFastTree(std::string_view in, bool notClosedBracketIsError = false); -} diff --git a/include/ydb-cpp-sdk/library/json/json_value.h b/include/ydb-cpp-sdk/library/json/json_value.h deleted file mode 100644 index 35c376048de..00000000000 --- a/include/ydb-cpp-sdk/library/json/json_value.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include diff --git a/include/ydb-cpp-sdk/library/json/writer/json.h b/include/ydb-cpp-sdk/library/json/writer/json.h deleted file mode 100644 index 04dd252668f..00000000000 --- a/include/ydb-cpp-sdk/library/json/writer/json.h +++ /dev/null @@ -1,286 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace NJson { - class TJsonValue; -} - -namespace NJsonWriter { - enum EJsonEntity : ui8 { - JE_OUTER_SPACE = 1, - JE_LIST, - JE_OBJECT, - JE_PAIR, - }; - - enum EHtmlEscapeMode { - HEM_ESCAPE_HTML = 1, // Use HTML escaping: < > & \/ - HEM_DONT_ESCAPE_HTML, // Use JSON escaping: \u003C \u003E \u0026 \/ - HEM_RELAXED, // Use JSON escaping: \u003C \u003E \u0026 / - HEM_UNSAFE, // Turn escaping off: < > & / - }; - - class TError: public yexception {}; - - class TValueContext; - class TPairContext; - class TAfterColonContext; - - struct TBufState { - bool NeedComma; - bool NeedNewline; - std::vector Stack; - }; - - class TBuf : TNonCopyable { - public: - TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr); - - TValueContext WriteString(const std::string_view& s, EHtmlEscapeMode hem); - TValueContext WriteString(const std::string_view& s); - TValueContext WriteInt(int i); - TValueContext WriteLongLong(long long i); - TValueContext WriteULongLong(unsigned long long i); - TValueContext WriteFloat(float f, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 6); - TValueContext WriteDouble(double f, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10); - TValueContext WriteBool(bool b); - TValueContext WriteNull(); - TValueContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10); - - TValueContext BeginList(); - TBuf& EndList(); - - TPairContext BeginObject(); - TAfterColonContext WriteKey(const std::string_view& key, EHtmlEscapeMode hem); - TAfterColonContext WriteKey(const std::string_view& key); - TAfterColonContext UnsafeWriteKey(const std::string_view& key); - bool KeyExpected() const { - return Stack.back() == JE_OBJECT; - } - - //! deprecated, do not use in new code - TAfterColonContext CompatWriteKeyWithoutQuotes(const std::string_view& key); - - TBuf& EndObject(); - - /*** Indent the resulting JSON with spaces. - * By default (spaces==0) no formatting is done. */ - TBuf& SetIndentSpaces(int spaces) { - IndentSpaces = spaces; - return *this; - } - - /*** NaN and Inf are not valid json values, - * so if WriteNanAsString is set, writer would write string - * intead of throwing exception (default case) */ - TBuf& SetWriteNanAsString(bool writeNanAsString = true) { - WriteNanAsString = writeNanAsString; - return *this; - } - - /*** Return the string formed in the internal std::stringStream. - * You may only call it if the `stream' parameter was NULL - * at construction time. */ - const std::string& Str() const; - - /*** Dump and forget the string constructed so far. - * You may only call it if the `stream' parameter was NULL - * at construction time. */ - void FlushTo(IOutputStream* stream); - - /*** Write a literal string that represents a JSON value - * (string, number, object, array, bool, or null). - * - * Example: - * j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]"); - * - * As in all of the Unsafe* functions, no escaping is done. */ - void UnsafeWriteValue(const std::string_view& s); - void UnsafeWriteValue(const char* s, size_t len); - - /*** When in the context of an object, write a literal string - * that represents a key:value pair (or several pairs). - * - * Example: - * j.BeginObject(); - * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\""); - * j.EndObject(); - * - * As in all of the Unsafe* functions, no escaping is done. */ - TPairContext UnsafeWritePair(const std::string_view& s); - - /*** Copy the supplied string directly into the output stream. */ - void UnsafeWriteRawBytes(const std::string_view& s); - void UnsafeWriteRawBytes(const char* c, size_t len); - - TBufState State() const; - void Reset(const TBufState& from); - void Reset(TBufState&& from); - - private: - void BeginValue(); - void EndValue(); - void BeginKey(); - void RawWriteChar(char c); - bool EscapedWriteChar(const char* b, const char* c, EHtmlEscapeMode hem); - void WriteBareString(const std::string_view s, EHtmlEscapeMode hem); - void WriteComma(); - void PrintIndentation(bool closing); - void PrintWhitespaces(size_t count, bool prependWithNewLine); - void WriteHexEscape(unsigned char c); - - void StackPush(EJsonEntity e); - void StackPop(); - void CheckAndPop(EJsonEntity e); - EJsonEntity StackTop() const; - - template - TValueContext WriteFloatImpl(TFloat f, EFloatToStringMode mode, int ndigits); - - private: - IOutputStream* Stream; - THolder StringStream; - typedef std::vector TKeys; - TKeys Keys; - - std::vector Stack; - bool NeedComma; - bool NeedNewline; - const EHtmlEscapeMode EscapeMode; - int IndentSpaces; - bool WriteNanAsString; - }; - - // Please don't try to instantiate the classes declared below this point. - - template - class TValueWriter { - public: - TOutContext WriteNull(); - TOutContext WriteString(const std::string_view&); - TOutContext WriteString(const std::string_view& s, EHtmlEscapeMode hem); - TOutContext WriteInt(int); - TOutContext WriteLongLong(long long); - TOutContext WriteULongLong(unsigned long long); - TOutContext WriteBool(bool); - TOutContext WriteFloat(float); - TOutContext WriteFloat(float, EFloatToStringMode, int ndigits); - TOutContext WriteDouble(double); - TOutContext WriteDouble(double, EFloatToStringMode, int ndigits); - TOutContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false); - TOutContext UnsafeWriteValue(const std::string_view&); - - TValueContext BeginList(); - TPairContext BeginObject(); - - protected: - TValueWriter(TBuf& buf) - : Buf(buf) - { - } - friend class TBuf; - - protected: - TBuf& Buf; - }; - - class TValueContext: public TValueWriter { - public: - TBuf& EndList() { - return Buf.EndList(); - } - std::string Str() const { - return Buf.Str(); - } - - private: - TValueContext(TBuf& buf) - : TValueWriter(buf) - { - } - friend class TBuf; - friend class TValueWriter; - }; - - class TAfterColonContext: public TValueWriter { - private: - TAfterColonContext(TBuf& iBuf) - : TValueWriter(iBuf) - { - } - friend class TBuf; - friend class TPairContext; - }; - - class TPairContext { - public: - TAfterColonContext WriteKey(const std::string_view& s, EHtmlEscapeMode hem) { - return Buf.WriteKey(s, hem); - } - TAfterColonContext WriteKey(const std::string_view& s) { - return Buf.WriteKey(s); - } - TAfterColonContext UnsafeWriteKey(const std::string_view& s) { - return Buf.UnsafeWriteKey(s); - } - TAfterColonContext CompatWriteKeyWithoutQuotes(const std::string_view& s) { - return Buf.CompatWriteKeyWithoutQuotes(s); - } - TPairContext UnsafeWritePair(const std::string_view& s) { - return Buf.UnsafeWritePair(s); - } - TBuf& EndObject() { - return Buf.EndObject(); - } - - private: - TPairContext(TBuf& buf) - : Buf(buf) - { - } - - friend class TBuf; - friend class TValueWriter; - - private: - TBuf& Buf; - }; - -#define JSON_VALUE_WRITER_WRAP(function, params, args) \ - template \ - TOutContext TValueWriter::function params { \ - Buf.function args; \ - return TOutContext(Buf); \ - } - - JSON_VALUE_WRITER_WRAP(WriteNull, (), ()) - JSON_VALUE_WRITER_WRAP(WriteString, (const std::string_view& arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteString, (const std::string_view& s, EHtmlEscapeMode hem), (s, hem)) - JSON_VALUE_WRITER_WRAP(WriteInt, (int arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteLongLong, (long long arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteULongLong, (unsigned long long arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteBool, (bool arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteFloat, (float arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteFloat, (float arg, EFloatToStringMode mode, int ndigits), (arg, mode, ndigits)) - JSON_VALUE_WRITER_WRAP(WriteDouble, (double arg), (arg)) - JSON_VALUE_WRITER_WRAP(WriteDouble, (double arg, EFloatToStringMode mode, int ndigits), (arg, mode, ndigits)) - JSON_VALUE_WRITER_WRAP(WriteJsonValue, (const NJson::TJsonValue* value, bool sortKeys), (value, sortKeys)) - JSON_VALUE_WRITER_WRAP(UnsafeWriteValue, (const std::string_view& arg), (arg)) -#undef JSON_VALUE_WRITER_WRAP - - template - TValueContext TValueWriter::BeginList() { - return Buf.BeginList(); - } - - template - TPairContext TValueWriter::BeginObject() { - return Buf.BeginObject(); - } - - std::string WrapJsonToCallback(const TBuf& buf, std::string_view callback); -} diff --git a/include/ydb-cpp-sdk/library/json/writer/json_value.h b/include/ydb-cpp-sdk/library/json/writer/json_value.h deleted file mode 100644 index e6a99f1a8ab..00000000000 --- a/include/ydb-cpp-sdk/library/json/writer/json_value.h +++ /dev/null @@ -1,287 +0,0 @@ -#pragma once - -#include - -#include -#include - -#include - -namespace NJson { - enum EJsonValueType { - JSON_UNDEFINED /* "Undefined" */, - JSON_NULL /* "Null" */, - JSON_BOOLEAN /* "Boolean" */, - JSON_INTEGER /* "Integer" */, - JSON_DOUBLE /* "Double" */, - JSON_STRING /* "String" */, - JSON_MAP /* "Map" */, - JSON_ARRAY /* "Array" */, - JSON_UINTEGER /* "UInteger" */ - }; - - class TJsonValue; - - class IScanCallback { - public: - virtual ~IScanCallback() = default; - - virtual bool Do(const std::string& path, TJsonValue* parent, TJsonValue& value) = 0; - }; - - class TJsonValue { - void Clear() noexcept; - - public: - typedef std::unordered_map TMapType; - typedef std::deque TArray; - - TJsonValue() noexcept = default; - TJsonValue(EJsonValueType type); - TJsonValue(bool value) noexcept; - TJsonValue(int value) noexcept; - TJsonValue(unsigned int value) noexcept; - TJsonValue(long value) noexcept; - TJsonValue(unsigned long value) noexcept; - TJsonValue(long long value) noexcept; - TJsonValue(unsigned long long value) noexcept; - TJsonValue(double value) noexcept; - TJsonValue(const char* value); - template - TJsonValue(const T*) = delete; - TJsonValue(std::string_view value); - - TJsonValue(const std::string& s) - : TJsonValue(std::string_view(s)) - { - } - - TJsonValue(const TJsonValue& vval); - TJsonValue(TJsonValue&& vval) noexcept; - - TJsonValue& operator=(const TJsonValue& val); - TJsonValue& operator=(TJsonValue&& val) noexcept; - - ~TJsonValue() { - Clear(); - } - - EJsonValueType GetType() const noexcept; - TJsonValue& SetType(EJsonValueType type); - - TJsonValue& SetValue(const TJsonValue& value); - TJsonValue& SetValue(TJsonValue&& value); - - // for Map - TJsonValue& InsertValue(const std::string& key, const TJsonValue& value); - TJsonValue& InsertValue(std::string_view key, const TJsonValue& value); - TJsonValue& InsertValue(const char* key, const TJsonValue& value); - TJsonValue& InsertValue(const std::string& key, TJsonValue&& value); - TJsonValue& InsertValue(std::string_view key, TJsonValue&& value); - TJsonValue& InsertValue(const char* key, TJsonValue&& value); - - // for Array - TJsonValue& AppendValue(const TJsonValue& value); - TJsonValue& AppendValue(TJsonValue&& value); - TJsonValue& Back(); - const TJsonValue& Back() const; - - bool GetValueByPath(std::string_view path, TJsonValue& result, char delimiter = '.') const; - bool SetValueByPath(std::string_view path, const TJsonValue& value, char delimiter = '.'); - bool SetValueByPath(std::string_view path, TJsonValue&& value, char delimiter = '.'); - - // returns NULL on failure - const TJsonValue* GetValueByPath(std::string_view path, char delimiter = '.') const noexcept; - TJsonValue* GetValueByPath(std::string_view path, char delimiter = '.') noexcept; - - void EraseValue(std::string_view key); - void EraseValue(size_t index); - - TJsonValue& operator[](size_t idx); - TJsonValue& operator[](const std::string_view& key); - const TJsonValue& operator[](size_t idx) const noexcept; - const TJsonValue& operator[](const std::string_view& key) const noexcept; - - bool GetBoolean() const; - long long GetInteger() const; - unsigned long long GetUInteger() const; - double GetDouble() const; - const std::string& GetString() const; - const TMapType& GetMap() const; - const TArray& GetArray() const; - - //throwing TJsonException possible - bool GetBooleanSafe() const; - long long GetIntegerSafe() const; - unsigned long long GetUIntegerSafe() const; - double GetDoubleSafe() const; - const std::string& GetStringSafe() const; - const TMapType& GetMapSafe() const; - TMapType& GetMapSafe(); - const TArray& GetArraySafe() const; - TArray& GetArraySafe(); - - bool GetBooleanSafe(bool defaultValue) const; - long long GetIntegerSafe(long long defaultValue) const; - unsigned long long GetUIntegerSafe(unsigned long long defaultValue) const; - double GetDoubleSafe(double defaultValue) const; - std::string GetStringSafe(const std::string& defaultValue) const; - - bool GetBooleanRobust() const noexcept; - long long GetIntegerRobust() const noexcept; - unsigned long long GetUIntegerRobust() const noexcept; - double GetDoubleRobust() const noexcept; - std::string GetStringRobust() const; - - // Exception-free accessors - bool GetBoolean(bool* value) const noexcept; - bool GetInteger(long long* value) const noexcept; - bool GetUInteger(unsigned long long* value) const noexcept; - bool GetDouble(double* value) const noexcept; - bool GetMapPointer(const TMapType** value) const noexcept; - bool GetArrayPointer(const TArray** value) const noexcept; - - bool GetString(std::string* value) const; - bool GetMap(TMapType* value) const; - bool GetArray(TArray* value) const; - bool GetValue(size_t index, TJsonValue* value) const; - bool GetValue(std::string_view key, TJsonValue* value) const; - bool GetValuePointer(size_t index, const TJsonValue** value) const noexcept; - bool GetValuePointer(std::string_view key, const TJsonValue** value) const noexcept; - bool GetValuePointer(std::string_view key, TJsonValue** value) noexcept; - - // Checking for defined non-null value - bool IsDefined() const noexcept { - return Type != JSON_UNDEFINED && Type != JSON_NULL; - } - - bool IsNull() const noexcept; - bool IsBoolean() const noexcept; - bool IsDouble() const noexcept; - bool IsString() const noexcept; - bool IsMap() const noexcept; - bool IsArray() const noexcept; - - /// @return true if JSON_INTEGER or (JSON_UINTEGER and Value <= Max) - bool IsInteger() const noexcept; - - /// @return true if JSON_UINTEGER or (JSON_INTEGER and Value >= 0) - bool IsUInteger() const noexcept; - - bool Has(const std::string_view& key) const noexcept; - bool Has(size_t key) const noexcept; - - void Scan(IScanCallback& callback); - - /// Non-robust comparison. - bool operator==(const TJsonValue& rhs) const; - - void Swap(TJsonValue& rhs) noexcept; - - // save using src/util/ysaveload.h serialization (not to JSON stream) - void Save(IOutputStream* s) const; - - // load using src/util/ysaveload.h serialization (not as JSON stream) - void Load(IInputStream* s); - - static const TJsonValue UNDEFINED; - - private: - EJsonValueType Type = JSON_UNDEFINED; - union TValueUnion { - bool Boolean; - long long Integer; - unsigned long long UInteger; - double Double; - std::string* String; - TMapType* Map; - TArray* Array; - - TValueUnion() noexcept { - Zero(*this); - } - ~TValueUnion() noexcept { - } - }; - TValueUnion Value; - void DoScan(const std::string& path, TJsonValue* parent, IScanCallback& callback); - void SwapWithUndefined(TJsonValue& output) noexcept; - - /** - @throw yexception if Back shouldn't be called on the object. - */ - void BackChecks() const; - }; - - inline bool GetBoolean(const TJsonValue& jv, size_t index, bool* value) noexcept { - return jv[index].GetBoolean(value); - } - - inline bool GetInteger(const TJsonValue& jv, size_t index, long long* value) noexcept { - return jv[index].GetInteger(value); - } - - inline bool GetUInteger(const TJsonValue& jv, size_t index, unsigned long long* value) noexcept { - return jv[index].GetUInteger(value); - } - - inline bool GetDouble(const TJsonValue& jv, size_t index, double* value) noexcept { - return jv[index].GetDouble(value); - } - - inline bool GetString(const TJsonValue& jv, size_t index, std::string* value) { - return jv[index].GetString(value); - } - - bool GetMapPointer(const TJsonValue& jv, size_t index, const TJsonValue::TMapType** value); - bool GetArrayPointer(const TJsonValue& jv, size_t index, const TJsonValue::TArray** value); - - inline bool GetBoolean(const TJsonValue& jv, std::string_view key, bool* value) noexcept { - return jv[key].GetBoolean(value); - } - - inline bool GetInteger(const TJsonValue& jv, std::string_view key, long long* value) noexcept { - return jv[key].GetInteger(value); - } - - inline bool GetUInteger(const TJsonValue& jv, std::string_view key, unsigned long long* value) noexcept { - return jv[key].GetUInteger(value); - } - - inline bool GetDouble(const TJsonValue& jv, std::string_view key, double* value) noexcept { - return jv[key].GetDouble(value); - } - - inline bool GetString(const TJsonValue& jv, std::string_view key, std::string* value) { - return jv[key].GetString(value); - } - - bool GetMapPointer(const TJsonValue& jv, const std::string_view key, const TJsonValue::TMapType** value); - bool GetArrayPointer(const TJsonValue& jv, const std::string_view key, const TJsonValue::TArray** value); - - class TJsonMap: public TJsonValue { - public: - TJsonMap() - : TJsonValue(NJson::JSON_MAP) - {} - - TJsonMap(const std::initializer_list>& list) - : TJsonValue(NJson::JSON_MAP) - { - GetMapSafe() = std::unordered_map(list); - } - }; - - class TJsonArray: public TJsonValue { - public: - TJsonArray() - : TJsonValue(NJson::JSON_ARRAY) - {} - - TJsonArray(const std::initializer_list& list) - : TJsonValue(NJson::JSON_ARRAY) - { - GetArraySafe() = TJsonValue::TArray(list); - } - }; -} diff --git a/include/ydb-cpp-sdk/json_value/ydb_json_value.h b/include/ydb-cpp-sdk/library/json_value/ydb_json_value.h similarity index 96% rename from include/ydb-cpp-sdk/json_value/ydb_json_value.h rename to include/ydb-cpp-sdk/library/json_value/ydb_json_value.h index 4ba5da17c4d..ef80a591322 100644 --- a/include/ydb-cpp-sdk/json_value/ydb_json_value.h +++ b/include/ydb-cpp-sdk/library/json_value/ydb_json_value.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/library/jwt/jwt.h b/include/ydb-cpp-sdk/library/jwt/jwt.h index 6d467de71ac..4d3d90f3153 100644 --- a/include/ydb-cpp-sdk/library/jwt/jwt.h +++ b/include/ydb-cpp-sdk/library/jwt/jwt.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/library/logger/record.h b/include/ydb-cpp-sdk/library/logger/record.h deleted file mode 100644 index 19c23c9c9d1..00000000000 --- a/include/ydb-cpp-sdk/library/logger/record.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "priority.h" - -#include -#include - -#include -#include - -struct TLogRecord { - using TMetaFlags = std::vector>; - - const char* Data; - size_t Len; - ELogPriority Priority; - TMetaFlags MetaFlags; - - inline TLogRecord(ELogPriority priority, const char* data, size_t len, TMetaFlags metaFlags = {}) noexcept - : Data(data) - , Len(len) - , Priority(priority) - , MetaFlags(std::move(metaFlags)) - { - } -}; diff --git a/include/ydb-cpp-sdk/library/logger/thread.h b/include/ydb-cpp-sdk/library/logger/thread.h deleted file mode 100644 index ba251e49e29..00000000000 --- a/include/ydb-cpp-sdk/library/logger/thread.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "backend.h" - -#include - -#include - -class TThreadedLogBackend: public TLogBackend { -public: - TThreadedLogBackend(TLogBackend* slave); - TThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function queueOverflowCallback = {}); - ~TThreadedLogBackend() override; - - void WriteData(const TLogRecord& rec) override; - void ReopenLog() override; - void ReopenLogNoFlush() override; - size_t QueueSize() const override; - - // Write an emergency message when the memory allocator is corrupted. - // The TThreadedLogBackend object can't be used after this method is called. - void WriteEmergencyData(const TLogRecord& rec); - -private: - class TImpl; - THolder Impl_; -}; - -class TOwningThreadedLogBackend: private THolder, public TThreadedLogBackend { -public: - TOwningThreadedLogBackend(TLogBackend* slave); - TOwningThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function queueOverflowCallback = {}); - ~TOwningThreadedLogBackend() override; -}; diff --git a/include/ydb-cpp-sdk/library/monlib/counters/counters.h b/include/ydb-cpp-sdk/library/monlib/counters/counters.h deleted file mode 100644 index 9cff24c30fa..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/counters/counters.h +++ /dev/null @@ -1,346 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace NMonitoring { -#define BEGIN_OUTPUT_COUNTERS \ - void OutputImpl(IOutputStream& out) { \ - char prettyBuf[32]; -#define END_OUTPUT_COUNTERS \ - out.Flush(); \ - } - -#define OUTPUT_NAMED_COUNTER(var, name) out << name << ": \t" << var << NMonitoring::PrettyNum(var, prettyBuf, 32) << '\n' -#define OUTPUT_COUNTER(var) OUTPUT_NAMED_COUNTER(var, #var); - - char* PrettyNumShort(i64 val, char* buf, size_t size); - char* PrettyNum(i64 val, char* buf, size_t size); - - // This class is deprecated. Please consider to use - // src/library/monlib/metrics instead. See more info at - // https://wiki.yandex-team.ru/solomon/libs/monlib_cpp/ - class TDeprecatedCounter { - public: - using TValue = TAtomic; - using TValueBase = TAtomicBase; - - TDeprecatedCounter() - : Value() - , Derivative(false) - { - } - - TDeprecatedCounter(TValueBase value, bool derivative = false) - : Value(value) - , Derivative(derivative) - { - } - - bool ForDerivative() const { - return Derivative; - } - - operator TValueBase() const { - return AtomicGet(Value); - } - TValueBase Val() const { - return AtomicGet(Value); - } - - void Set(TValueBase val) { - AtomicSet(Value, val); - } - - TValueBase Inc() { - return AtomicIncrement(Value); - } - TValueBase Dec() { - return AtomicDecrement(Value); - } - - TValueBase Add(const TValueBase val) { - return AtomicAdd(Value, val); - } - TValueBase Sub(const TValueBase val) { - return AtomicAdd(Value, -val); - } - - // operator overloads convinient - void operator++() { - Inc(); - } - void operator++(int) { - Inc(); - } - - void operator--() { - Dec(); - } - void operator--(int) { - Dec(); - } - - void operator+=(TValueBase rhs) { - Add(rhs); - } - void operator-=(TValueBase rhs) { - Sub(rhs); - } - - TValueBase operator=(TValueBase rhs) { - AtomicSwap(&Value, rhs); - return rhs; - } - - bool operator!() const { - return AtomicGet(Value) == 0; - } - - TAtomic& GetAtomic() { - return Value; - } - - private: - TAtomic Value; - bool Derivative; - }; - - template - struct TDeprecatedCountersBase { - virtual ~TDeprecatedCountersBase() { - } - - virtual void OutputImpl(IOutputStream&) = 0; - - static T& Instance() { - return *Singleton(); - } - - static void Output(IOutputStream& out) { - Instance().OutputImpl(out); - } - }; - - // This class is deprecated. Please consider to use - // src/library/monlib/metrics instead. See more info at - // https://wiki.yandex-team.ru/solomon/libs/monlib_cpp/ - // - // Groups of G counters, defined by T type. - // Less(a,b) returns true, if a < b. - // It's threadsafe. - template > - class TDeprecatedCounterGroups { - public: - typedef std::map TGroups; - typedef std::vector TGroupsNames; - - typedef THolder TGroupsNamesPtr; - - private: - class TCollection { - struct TElement { - T* Name; - G* Counters; - - public: - static bool Compare(const TElement& a, const TElement& b) { - return Less(*(a.Name), *(b.Name)); - } - }; // TElement - private: - TArrayHolder Elements; - size_t Size; - - public: - TCollection() - : Size(0) - { - } - - TCollection(const TCollection& collection) - : Elements(new TElement[collection.Size]) - , Size(collection.Size) - { - for (int i = 0; i < Size; ++i) { - Elements[i] = collection.Elements[i]; - } - } - - TCollection(const TCollection& collection, T* name, G* counters) - : Elements(new TElement[collection.Size + 1]) - , Size(collection.Size + 1) - { - for (size_t i = 0; i < Size - 1; ++i) { - Elements[i] = collection.Elements[i]; - } - Elements[Size - 1].Name = name; - Elements[Size - 1].Counters = counters; - for (size_t i = 1; i < Size; ++i) { - size_t j = i; - while (j > 0 && - TElement::Compare(Elements[j], Elements[j - 1])) { - std::swap(Elements[j], Elements[j - 1]); - --j; - } - } - } - - G* Find(const T& name) const { - G* result = nullptr; - if (Size == 0) { - return nullptr; - } - size_t l = 0; - size_t r = Size - 1; - while (l < r) { - size_t m = (l + r) / 2; - if (Less(*(Elements[m].Name), name)) { - l = m + 1; - } else { - r = m; - } - } - if (!Less(*(Elements[l].Name), name) && !Less(name, *(Elements[l].Name))) { - result = Elements[l].Counters; - } - return result; - } - - void Free() { - for (size_t i = 0; i < Size; ++i) { - T* name = Elements[i].Name; - G* counters = Elements[i].Counters; - Elements[i].Name = nullptr; - Elements[i].Counters = nullptr; - delete name; - delete counters; - } - Size = 0; - } - - TGroupsNamesPtr GetNames() const { - TGroupsNamesPtr result(new TGroupsNames()); - for (size_t i = 0; i < Size; ++i) { - result->push_back(*(Elements[i].Name)); - } - return result; - } - }; // TCollection - struct TOldGroup { - TCollection* Collection; - ui64 Time; - }; - - private: - TCollection* Groups; - std::list OldGroups; - TSpinLock AddMutex; - - ui64 Timeout; - - static TL Less; - - private: - G* Add(const T& name) { - std::lock_guard guard(AddMutex); - G* result = Groups->Find(name); - if (result == nullptr) { - T* newName = new T(name); - G* newCounters = new G(); - TCollection* newGroups = - new TCollection(*Groups, newName, newCounters); - ui64 now = ::Now().MicroSeconds(); - TOldGroup group; - group.Collection = Groups; - group.Time = now; - OldGroups.push_back(group); - for (ui32 i = 0; i < 5; ++i) { - if (OldGroups.front().Time + Timeout < now) { - delete OldGroups.front().Collection; - OldGroups.front().Collection = nullptr; - OldGroups.pop_front(); - } else { - break; - } - } - Groups = newGroups; - result = Groups->Find(name); - } - return result; - } - - public: - TDeprecatedCounterGroups(ui64 timeout = 5 * 1000000L) { - Groups = new TCollection(); - Timeout = timeout; - } - - virtual ~TDeprecatedCounterGroups() { - std::lock_guard guard(AddMutex); - Groups->Free(); - delete Groups; - Groups = nullptr; - typename std::list::iterator i; - for (i = OldGroups.begin(); i != OldGroups.end(); ++i) { - delete i->Collection; - i->Collection = nullptr; - } - OldGroups.clear(); - } - - bool Has(const T& name) const { - TCollection* groups = Groups; - return groups->Find(name) != nullptr; - } - - G* Find(const T& name) const { - TCollection* groups = Groups; - return groups->Find(name); - } - - // Get group with the name, if it exists. - // If there is no group with the name, add new group. - G& Get(const T& name) { - G* result = Find(name); - if (result == nullptr) { - result = Add(name); - Y_ASSERT(result != nullptr); - } - return *result; - } - - // Get copy of groups names array. - TGroupsNamesPtr GetGroupsNames() const { - TCollection* groups = Groups; - TGroupsNamesPtr result = groups->GetNames(); - return result; - } - }; // TDeprecatedCounterGroups - - template - TL TDeprecatedCounterGroups::Less; -} - -static inline IOutputStream& operator<<(IOutputStream& o, const NMonitoring::TDeprecatedCounter& rhs) { - return o << rhs.Val(); -} - -template -static inline IOutputStream& operator<<(IOutputStream& o, const std::array& rhs) { - for (typename std::array::const_iterator it = rhs.begin(); it != rhs.end(); ++it) { - if (!!*it) - o << *it << Endl; - } - return o; -} diff --git a/include/ydb-cpp-sdk/library/monlib/dynamic_counters/counters.h b/include/ydb-cpp-sdk/library/monlib/dynamic_counters/counters.h deleted file mode 100644 index 787cea24010..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/dynamic_counters/counters.h +++ /dev/null @@ -1,374 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include - -namespace NMonitoring { - struct TCounterForPtr; - struct TDynamicCounters; - struct ICountableConsumer; - - - struct TCountableBase: public TAtomicRefCount { - // Private means that the object must not be serialized unless the consumer - // has explicitly specified this by setting its Visibility to Private. - // - // Works only for the methods that accept ICountableConsumer - enum class EVisibility: ui8 { - Unspecified, - Public, - Private, - }; - - virtual ~TCountableBase() { - } - - virtual void Accept( - const std::string& labelName, const std::string& labelValue, - ICountableConsumer& consumer) const = 0; - - virtual EVisibility Visibility() const { - return Visibility_; - } - - protected: - EVisibility Visibility_{EVisibility::Unspecified}; - }; - - inline bool IsVisible(TCountableBase::EVisibility myLevel, TCountableBase::EVisibility consumerLevel) { - if (myLevel == TCountableBase::EVisibility::Private - && consumerLevel != TCountableBase::EVisibility::Private) { - - return false; - } - - return true; - } - - struct ICountableConsumer { - virtual ~ICountableConsumer() { - } - - virtual void OnCounter( - const std::string& labelName, const std::string& labelValue, - const TCounterForPtr* counter) = 0; - - virtual void OnHistogram( - const std::string& labelName, const std::string& labelValue, - IHistogramSnapshotPtr snapshot, bool derivative) = 0; - - virtual void OnGroupBegin( - const std::string& labelName, const std::string& labelValue, - const TDynamicCounters* group) = 0; - - virtual void OnGroupEnd( - const std::string& labelName, const std::string& labelValue, - const TDynamicCounters* group) = 0; - - virtual TCountableBase::EVisibility Visibility() const { - return TCountableBase::EVisibility::Unspecified; - } - }; - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) // multiple assignment operators specified -#endif // _MSC_VER - - struct TCounterForPtr: public TDeprecatedCounter, public TCountableBase { - TCounterForPtr(bool derivative = false, EVisibility vis = EVisibility::Public) - : TDeprecatedCounter(0ULL, derivative) - { - Visibility_ = vis; - } - - TCounterForPtr(const TCounterForPtr&) = delete; - TCounterForPtr& operator=(const TCounterForPtr& other) = delete; - - void Accept( - const std::string& labelName, const std::string& labelValue, - ICountableConsumer& consumer) const override { - if (IsVisible(Visibility(), consumer.Visibility())) { - consumer.OnCounter(labelName, labelValue, this); - } - } - - TCountableBase::EVisibility Visibility() const override { - return Visibility_; - } - - using TDeprecatedCounter::operator++; - using TDeprecatedCounter::operator--; - using TDeprecatedCounter::operator+=; - using TDeprecatedCounter::operator-=; - using TDeprecatedCounter::operator=; - using TDeprecatedCounter::operator!; - }; - - struct TExpiringCounter: public TCounterForPtr { - explicit TExpiringCounter(bool derivative = false, EVisibility vis = EVisibility::Public) - : TCounterForPtr{derivative} - { - Visibility_ = vis; - } - - void Reset() { - TDeprecatedCounter::operator=(0); - } - }; - - struct THistogramCounter: public TCountableBase { - explicit THistogramCounter( - IHistogramCollectorPtr collector, bool derivative = true, EVisibility vis = EVisibility::Public) - : Collector_(std::move(collector)) - , Derivative_(derivative) - { - Visibility_ = vis; - } - - void Collect(i64 value) { - Collector_->Collect(value); - } - - void Collect(i64 value, ui64 count) { - Collector_->Collect(value, count); - } - - void Collect(double value, ui64 count) { - Collector_->Collect(value, count); - } - - void Collect(const IHistogramSnapshot& snapshot) { - Collector_->Collect(snapshot); - } - - void Accept( - const std::string& labelName, const std::string& labelValue, - ICountableConsumer& consumer) const override - { - if (IsVisible(Visibility(), consumer.Visibility())) { - consumer.OnHistogram(labelName, labelValue, Collector_->Snapshot(), Derivative_); - } - } - - void Reset() { - Collector_->Reset(); - } - - IHistogramSnapshotPtr Snapshot() const { - return Collector_->Snapshot(); - } - - private: - IHistogramCollectorPtr Collector_; - bool Derivative_; - }; - - struct TExpiringHistogramCounter: public THistogramCounter { - using THistogramCounter::THistogramCounter; - }; - - using THistogramPtr = TIntrusivePtr; - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - struct TDynamicCounters; - - typedef TIntrusivePtr TDynamicCounterPtr; - struct TDynamicCounters: public TCountableBase { - public: - using TCounterPtr = TIntrusivePtr; - using TOnLookupPtr = void (*)(const char *methodName, const std::string &name, const std::string &value); - - private: - TRWMutex Lock; - TCounterPtr LookupCounter; // Counts lookups by name - TOnLookupPtr OnLookup = nullptr; // Called on each lookup if not nullptr, intended for lightweight tracing. - - typedef TIntrusivePtr TCountablePtr; - - struct TChildId { - std::string LabelName; - std::string LabelValue; - TChildId() { - } - TChildId(const std::string& labelName, const std::string& labelValue) - : LabelName(labelName) - , LabelValue(labelValue) - { - } - auto AsTuple() const { - return std::make_tuple(std::cref(LabelName), std::cref(LabelValue)); - } - friend bool operator <(const TChildId& x, const TChildId& y) { - return x.AsTuple() < y.AsTuple(); - } - friend bool operator ==(const TChildId& x, const TChildId& y) { - return x.AsTuple() == y.AsTuple(); - } - friend bool operator !=(const TChildId& x, const TChildId& y) { - return x.AsTuple() != y.AsTuple(); - } - }; - - using TCounters = std::map; - using TLabels = std::vector; - - /// XXX: hack for deferred removal of expired counters. Remove once Output* functions are not used for serialization - mutable TCounters Counters; - mutable TAtomic ExpiringCount = 0; - - public: - TDynamicCounters(TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - TDynamicCounters(const TDynamicCounters *origin) - : LookupCounter(origin->LookupCounter) - , OnLookup(origin->OnLookup) - {} - - ~TDynamicCounters() override; - - // This counter allows to track lookups by name within the whole subtree - void SetLookupCounter(TCounterPtr lookupCounter) { - TWriteGuard g(Lock); - LookupCounter = lookupCounter; - } - - void SetOnLookup(TOnLookupPtr onLookup) { - TWriteGuard g(Lock); - OnLookup = onLookup; - } - - TWriteGuard LockForUpdate(const char *method, const std::string& name, const std::string& value) { - auto res = TWriteGuard(Lock); - if (LookupCounter) { - ++*LookupCounter; - } - if (OnLookup) { - OnLookup(method, name, value); - } - return res; - } - - TStackVec ReadSnapshot() const { - RemoveExpired(); - TReadGuard g(Lock); - TStackVec items(Counters.begin(), Counters.end()); - return items; - } - - TCounterPtr GetCounter( - const std::string& value, - bool derivative = false, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - TCounterPtr GetNamedCounter( - const std::string& name, - const std::string& value, - bool derivative = false, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - THistogramPtr GetHistogram( - const std::string& value, - IHistogramCollectorPtr collector, - bool derivative = true, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - THistogramPtr GetNamedHistogram( - const std::string& name, - const std::string& value, - IHistogramCollectorPtr collector, - bool derivative = true, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - // These counters will be automatically removed from the registry - // when last reference to the counter expires. - TCounterPtr GetExpiringCounter( - const std::string& value, - bool derivative = false, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - TCounterPtr GetExpiringNamedCounter( - const std::string& name, - const std::string& value, - bool derivative = false, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - THistogramPtr GetExpiringHistogram( - const std::string& value, - IHistogramCollectorPtr collector, - bool derivative = true, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - THistogramPtr GetExpiringNamedHistogram( - const std::string& name, - const std::string& value, - IHistogramCollectorPtr collector, - bool derivative = true, - TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public); - - TCounterPtr FindCounter(const std::string& value) const; - TCounterPtr FindNamedCounter(const std::string& name, const std::string& value) const; - - THistogramPtr FindHistogram(const std::string& value) const; - THistogramPtr FindNamedHistogram(const std::string& name,const std::string& value) const; - - void RemoveCounter(const std::string &value); - bool RemoveNamedCounter(const std::string& name, const std::string &value); - void RemoveSubgroupChain(const std::vector>& chain); - - TIntrusivePtr GetSubgroup(const std::string& name, const std::string& value); - TIntrusivePtr FindSubgroup(const std::string& name, const std::string& value) const; - bool RemoveSubgroup(const std::string& name, const std::string& value); - void ReplaceSubgroup(const std::string& name, const std::string& value, TIntrusivePtr subgroup); - - // Move all counters from specified subgroup and remove the subgroup. - void MergeWithSubgroup(const std::string& name, const std::string& value); - // Recursively reset all/deriv counters to 0. - void ResetCounters(bool derivOnly = false); - - void RegisterSubgroup(const std::string& name, - const std::string& value, - TIntrusivePtr subgroup); - - void OutputHtml(IOutputStream& os) const; - void EnumerateSubgroups(const std::function& output) const; - - // mostly for debugging purposes -- use accept with encoder instead - void OutputPlainText(IOutputStream& os, const std::string& indent = "") const; - - void Accept( - const std::string& labelName, const std::string& labelValue, - ICountableConsumer& consumer) const override; - - private: - TCounters Resign() { - TCounters counters; - TWriteGuard g(Lock); - Counters.swap(counters); - return counters; - } - - void RegisterCountable(const std::string& name, const std::string& value, TCountablePtr countable); - void RemoveExpired() const; - - template - TCountablePtr GetNamedCounterImpl(const std::string& name, const std::string& value, TArgs&&... args); - - template - TCountablePtr FindNamedCounterImpl(const std::string& name, const std::string& value) const; - }; - -} diff --git a/include/ydb-cpp-sdk/library/monlib/encode/encoder.h b/include/ydb-cpp-sdk/library/monlib/encode/encoder.h deleted file mode 100644 index 0b34daea376..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/encode/encoder.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -#include - -namespace NMonitoring { - class IMetricEncoder: public IMetricConsumer { - public: - virtual ~IMetricEncoder(); - - virtual void Close() = 0; - }; - - using IMetricEncoderPtr = THolder; - -} diff --git a/include/ydb-cpp-sdk/library/monlib/encode/format.h b/include/ydb-cpp-sdk/library/monlib/encode/format.h deleted file mode 100644 index e8c9d178b2b..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/encode/format.h +++ /dev/null @@ -1,172 +0,0 @@ -#pragma once - -#include - -namespace NMonitoring { - namespace NFormatContenType { - constexpr std::string_view TEXT = "application/x-solomon-txt"; - constexpr std::string_view JSON = "application/json"; - constexpr std::string_view PROTOBUF = "application/x-solomon-pb"; - constexpr std::string_view SPACK = "application/x-solomon-spack"; - constexpr std::string_view PROMETHEUS = "text/plain"; - constexpr std::string_view UNISTAT = "text/json"; - } - - namespace NFormatContentEncoding { - constexpr std::string_view IDENTITY = "identity"; - constexpr std::string_view ZLIB = "zlib"; - constexpr std::string_view LZ4 = "lz4"; - constexpr std::string_view ZSTD = "zstd"; - } - - /** - * Defines format types for metric encoders. - */ - enum class EFormat { - /** - * Special case when it was not possible to determine format. - */ - UNKNOWN, - - /** - * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/spackv1 - */ - SPACK, - - /** - * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/json - */ - JSON, - - /** - * Read more https://wiki.yandex-team.ru/golovan/userdocs/stat-handle - */ - UNISTAT, - - /** - * Simple protobuf format, only for testing purposes. - */ - PROTOBUF, - - /** - * Simple text representation, only for debug purposes. - */ - TEXT, - - /** - * Prometheus text-based format - */ - PROMETHEUS, - }; - - /** - * Defines compression algorithms for metric encoders. - */ - enum class ECompression { - /** - * Special case when it was not possible to determine compression. - */ - UNKNOWN, - - /** - * Means no compression. - */ - IDENTITY, - - /** - * Using the zlib structure (defined in RFC 1950), with the - * deflate compression algorithm and Adler32 checkums. - */ - ZLIB, - - /** - * Using LZ4 compression algorithm (read http://lz4.org for more info) - * with XxHash32 checksums. - */ - LZ4, - - /** - * Using Zstandard compression algorithm (read http://zstd.net for more - * info) with XxHash32 checksums. - */ - ZSTD, - }; - - enum class EMetricsMergingMode { - /** - * Do not merge metric batches. If several points of the same metric were - * added multiple times accross different writes, paste them as - * separate metrics. - * - * Example: - * COUNTER [(ts1, val1)] | COUNTER [(ts1, val1)] - * COUNTER [(ts2, val2)] | --> COUNTER [(ts2, val2)] - * COUNTER [(ts3, val3)] | COUNTER [(ts3, val3)] - */ - DEFAULT, - - /** - * If several points of the same metric were added multiple times across - * different writes, merge all values to one timeseries. - * - * Example: - * COUNTER [(ts1, val1)] | - * COUNTER [(ts2, val2)] | --> COUNTER [(ts1, val1), (ts2, val2), (ts3, val3)] - * COUNTER [(ts3, val3)] | - */ - MERGE_METRICS, - }; - - /** - * Matches serialization format by the given "Accept" header value. - * - * @param value value of the "Accept" header. - * @return most preffered serialization format type - */ - EFormat FormatFromAcceptHeader(std::string_view value); - - /** - * Matches serialization format by the given "Content-Type" header value - * - * @param value value of the "Content-Type" header - * @return message format - */ - EFormat FormatFromContentType(std::string_view value); - - /** - * Returns value for "Content-Type" header determined by the given - * format type. - * - * @param format serialization format type - * @return mime-type indentificator - * or empty string if format is UNKNOWN - */ - std::string_view ContentTypeByFormat(EFormat format); - - /** - * Matches compression algorithm by the given "Accept-Encoding" header value. - * - * @param value value of the "Accept-Encoding" header. - * @return most preffered compression algorithm - */ - ECompression CompressionFromAcceptEncodingHeader(std::string_view value); - - /** - * Matches compression algorithm by the given "Content-Encoding" header value. - * - * @param value value of the "Accept-Encoding" header. - * @return most preffered compression algorithm - */ - ECompression CompressionFromContentEncodingHeader(std::string_view value); - - /** - * Returns value for "Content-Encoding" header determined by the given - * compression algorithm. - * - * @param compression encoding compression alg - * @return media-type compresion algorithm - * or empty string if compression is UNKNOWN - */ - std::string_view ContentEncodingByCompression(ECompression compression); - -} diff --git a/include/ydb-cpp-sdk/library/monlib/encode/json/json.h b/include/ydb-cpp-sdk/library/monlib/encode/json/json.h deleted file mode 100644 index ffc80c2941b..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/encode/json/json.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -class IOutputStream; - -namespace NMonitoring { - - class TJsonDecodeError: public yexception { - }; - - IMetricEncoderPtr EncoderJson(IOutputStream* out, int indentation = 0); - - /// Buffered encoder will merge series with same labels into one. - IMetricEncoderPtr BufferedEncoderJson(IOutputStream* out, int indentation = 0); - - IMetricEncoderPtr EncoderCloudJson(IOutputStream* out, - int indentation = 0, - std::string_view metricNameLabel = "name"); - - IMetricEncoderPtr BufferedEncoderCloudJson(IOutputStream* out, - int indentation = 0, - std::string_view metricNameLabel = "name"); - - void DecodeJson(std::string_view data, IMetricConsumer* c, std::string_view metricNameLabel = "name"); - -} diff --git a/include/ydb-cpp-sdk/library/monlib/metrics/metric_type.h b/include/ydb-cpp-sdk/library/monlib/metrics/metric_type.h deleted file mode 100644 index 409178fa49b..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/metrics/metric_type.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include - -namespace NMonitoring { - - constexpr ui32 MaxMetricTypeNameLength = 9; - - enum class EMetricType { - UNKNOWN = 0, - GAUGE = 1, - COUNTER = 2, - RATE = 3, - IGAUGE = 4, - HIST = 5, - HIST_RATE = 6, - DSUMMARY = 7, - // ISUMMARY = 8, reserved - LOGHIST = 9, - }; - - std::string_view MetricTypeToStr(EMetricType type); - EMetricType MetricTypeFromStr(std::string_view str); - -} diff --git a/include/ydb-cpp-sdk/library/monlib/service/mon_service_http_request.h b/include/ydb-cpp-sdk/library/monlib/service/mon_service_http_request.h deleted file mode 100644 index 00bb6408427..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/service/mon_service_http_request.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include "service.h" - -#include - -namespace NMonitoring { - class TMonService2; - class IMonPage; - - // XXX: IHttpRequest is already taken - struct IMonHttpRequest { - virtual ~IMonHttpRequest(); - - virtual IOutputStream& Output() = 0; - - virtual HTTP_METHOD GetMethod() const = 0; - virtual std::string_view GetPath() const = 0; - virtual std::string_view GetPathInfo() const = 0; - virtual std::string_view GetUri() const = 0; - virtual const TCgiParameters& GetParams() const = 0; - virtual const TCgiParameters& GetPostParams() const = 0; - virtual std::string_view GetPostContent() const = 0; - virtual const THttpHeaders& GetHeaders() const = 0; - virtual std::string_view GetHeader(std::string_view name) const = 0; - virtual std::string_view GetCookie(std::string_view name) const = 0; - virtual std::string GetRemoteAddr() const = 0; - - virtual std::string GetServiceTitle() const = 0; - - virtual IMonPage* GetPage() const = 0; - - virtual IMonHttpRequest* MakeChild(IMonPage* page, const std::string& pathInfo) const = 0; - }; - - struct TMonService2HttpRequest: IMonHttpRequest { - IOutputStream* const Out; - const IHttpRequest* const HttpRequest; - TMonService2* const MonService; - IMonPage* const MonPage; - const std::string PathInfo; - TMonService2HttpRequest* const Parent; - - TMonService2HttpRequest( - IOutputStream* out, const IHttpRequest* httpRequest, - TMonService2* monService, IMonPage* monPage, - const std::string& pathInfo, - TMonService2HttpRequest* parent) - : Out(out) - , HttpRequest(httpRequest) - , MonService(monService) - , MonPage(monPage) - , PathInfo(pathInfo) - , Parent(parent) - { - } - - ~TMonService2HttpRequest() override; - - IOutputStream& Output() override; - HTTP_METHOD GetMethod() const override; - std::string_view GetPath() const override; - std::string_view GetPathInfo() const override; - std::string_view GetUri() const override; - const TCgiParameters& GetParams() const override; - const TCgiParameters& GetPostParams() const override; - std::string_view GetPostContent() const override { - return HttpRequest->GetPostContent(); - } - - std::string_view GetHeader(std::string_view name) const override; - std::string_view GetCookie(std::string_view name) const override; - const THttpHeaders& GetHeaders() const override; - std::string GetRemoteAddr() const override; - - IMonPage* GetPage() const override { - return MonPage; - } - - TMonService2HttpRequest* MakeChild(IMonPage* page, const std::string& pathInfo) const override { - return new TMonService2HttpRequest{ - Out, HttpRequest, MonService, page, - pathInfo, const_cast(this) - }; - } - - std::string GetServiceTitle() const override; - }; - -} diff --git a/include/ydb-cpp-sdk/library/monlib/service/monservice.h b/include/ydb-cpp-sdk/library/monlib/service/monservice.h deleted file mode 100644 index 96ccdaf81d0..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/service/monservice.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include "service.h" -#include "auth.h" -#include "mon_service_http_request.h" - -#include "pages/index_mon_page.h" -#include "pages/mon_page.h" - -#include - -#include - -namespace NMonitoring { - class TMonService2: public TMtHttpServer { - protected: - const std::string Title; - char StartTime[26]; - TIntrusivePtr IndexMonPage; - THolder AuthProvider_; - - public: - static THttpServerOptions HttpServerOptions(ui16 port, const std::string& host, ui32 threads) { - THttpServerOptions opts(port); - if (!host.empty()) { - opts.SetHost(host); - } - opts.SetClientTimeout(TDuration::Minutes(1)); - opts.EnableCompression(true); - opts.SetThreads(threads); - opts.SetMaxConnections(std::max(100, threads)); - opts.EnableRejectExcessConnections(true); - return opts; - } - - static THttpServerOptions HttpServerOptions(ui16 port, ui32 threads) { - return HttpServerOptions(port, std::string(), threads); - } - - public: - explicit TMonService2(ui16 port, const std::string& title = GetProgramName(), THolder auth = nullptr); - explicit TMonService2(ui16 port, ui32 threads, const std::string& title = GetProgramName(), THolder auth = nullptr); - explicit TMonService2(ui16 port, const std::string& host, ui32 threads, const std::string& title = GetProgramName(), THolder auth = nullptr); - explicit TMonService2(const THttpServerOptions& options, const std::string& title = GetProgramName(), THolder auth = nullptr); - explicit TMonService2(const THttpServerOptions& options, std::shared_ptr pool, const std::string& title = GetProgramName(), THolder auth = nullptr); - - ~TMonService2() override { - } - - const char* GetStartTime() const { - return StartTime; - } - - const std::string& GetTitle() const { - return Title; - } - - virtual void ServeRequest(IOutputStream& out, const NMonitoring::IHttpRequest& request); - virtual void OutputIndex(IOutputStream& out); - virtual void OutputIndexPage(IOutputStream& out); - virtual void OutputIndexBody(IOutputStream& out); - - void Register(IMonPage* page); - void Register(TMonPagePtr page); - - TIndexMonPage* RegisterIndexPage(const std::string& path, const std::string& title); - - IMonPage* FindPage(const std::string& relativePath); - TIndexMonPage* FindIndexPage(const std::string& relativePath); - void SortPages(); - - TIndexMonPage* GetRoot() { - return IndexMonPage.Get(); - } - }; - -} diff --git a/include/ydb-cpp-sdk/library/monlib/service/pages/index_mon_page.h b/include/ydb-cpp-sdk/library/monlib/service/pages/index_mon_page.h deleted file mode 100644 index a62d386c0d0..00000000000 --- a/include/ydb-cpp-sdk/library/monlib/service/pages/index_mon_page.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "mon_page.h" - -#include -#include - -namespace NMonitoring { - struct TIndexMonPage: public IMonPage { - std::mutex Mtx; - using TPages = std::list; - TPages Pages; // a list of pages to maintain specific order - using TPagesByPath = std::unordered_map; - TPagesByPath PagesByPath; - - TIndexMonPage(const std::string& path, const std::string& title) - : IMonPage(path, title) - { - } - - ~TIndexMonPage() override { - } - - bool IsIndex() const override { - return true; - } - - void Output(IMonHttpRequest& request) override; - void OutputIndexPage(IMonHttpRequest& request); - virtual void OutputIndex(IOutputStream& out, bool pathEndsWithSlash); - virtual void OutputCommonJsCss(IOutputStream& out); - void OutputHead(IOutputStream& out); - void OutputBody(IMonHttpRequest& out); - - void Register(TMonPagePtr page); - TIndexMonPage* RegisterIndexPage(const std::string& path, const std::string& title); - - IMonPage* FindPage(const std::string& relativePath); - TIndexMonPage* FindIndexPage(const std::string& relativePath); - IMonPage* FindPageByAbsolutePath(const std::string& absolutePath); - - void SortPages(); - void ClearPages(); - }; - -} diff --git a/include/ydb-cpp-sdk/library/operation_id/operation_id.h b/include/ydb-cpp-sdk/library/operation_id/operation_id.h index 714fa099d9c..58bf9bbcb94 100644 --- a/include/ydb-cpp-sdk/library/operation_id/operation_id.h +++ b/include/ydb-cpp-sdk/library/operation_id/operation_id.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/ydb-cpp-sdk/library/resource/resource.h b/include/ydb-cpp-sdk/library/resource/resource.h deleted file mode 100644 index e49064caf0f..00000000000 --- a/include/ydb-cpp-sdk/library/resource/resource.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace NResource { - struct TResource { - std::string_view Key; - std::string Data; - }; - - typedef std::vector TResources; - - bool Has(const std::string_view key); - std::string Find(const std::string_view key); - bool FindExact(const std::string_view key, std::string* out); - /// @note Perform full scan for now. - void FindMatch(const std::string_view subkey, TResources* out); - size_t Count() noexcept; - std::string_view KeyByIndex(size_t idx); - std::vector ListAllKeys(); -} diff --git a/include/ydb-cpp-sdk/library/retry/retry_policy.h b/include/ydb-cpp-sdk/library/retry/retry_policy.h index 005e59480ba..bc553cbd9c9 100644 --- a/include/ydb-cpp-sdk/library/retry/retry_policy.h +++ b/include/ydb-cpp-sdk/library/retry/retry_policy.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/ydb-cpp-sdk/library/string_utils/misc/misc.h b/include/ydb-cpp-sdk/library/string_utils/misc/misc.h index f94f35382eb..20beb71f72c 100644 --- a/include/ydb-cpp-sdk/library/string_utils/misc/misc.h +++ b/include/ydb-cpp-sdk/library/string_utils/misc/misc.h @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include #include @@ -48,4 +48,14 @@ void GetNext(std::string_view& s, D delim, std::optional

& param) { } } +template +void GetNext(std::string_view& s, D delim, std::optional& param) { + std::string_view next; + if (NUtils::NextTok(s, next, delim)) { + param = next; + } else { + param.reset(); + } +} + } \ No newline at end of file diff --git a/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue.h b/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue.h index c87d91cd3e1..abea688129c 100644 --- a/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue.h +++ b/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue.h @@ -2,10 +2,12 @@ #include "yql_issue_id.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include @@ -159,9 +161,9 @@ class TIssue: public TThrRefBase { return CombineHashes( CombineHashes( (size_t)CombineHashes(IntHash(Position.Row), IntHash(Position.Column)), - THash{}(Position.File) + std::hash{}(Position.File) ), - (size_t)CombineHashes((size_t)IntHash(static_cast(IssueCode)), THash{}(Message))); + (size_t)CombineHashes((size_t)IntHash(static_cast(IssueCode)), std::hash{}(Message))); } TIssue& SetCode(TIssueCode id, ESeverity severity) { @@ -198,12 +200,12 @@ class TIssue: public TThrRefBase { return Children_; } - void PrintTo(std::ostream& out, bool oneLine = false) const; + void PrintTo(IOutputStream& out, bool oneLine = false) const; std::string ToString(bool oneLine = false) const { - std::stringstream out; + TStringStream out; PrintTo(out, oneLine); - return out.str(); + return out.Str(); } // Unsafe method. Doesn't call SanitizeNonAscii(Message) @@ -306,16 +308,16 @@ class TIssues { return Issues_.size(); } - void PrintTo(std::ostream& out, bool oneLine = false) const; + void PrintTo(IOutputStream& out, bool oneLine = false) const; void PrintWithProgramTo( - std::ostream& out, + IOutputStream& out, const std::string& programFilename, const std::string& programText) const; inline std::string ToString(bool oneLine = false) const { - std::stringstream out; + TStringStream out; PrintTo(out, oneLine); - return out.str(); + return out.Str(); } std::string ToOneLineString() const { @@ -350,10 +352,17 @@ std::optional TryParseTerminationMessage(std::string_view& message); } // namespace NYql -std::ostream& operator<<(std::ostream& out, const NYql::TPosition& pos); -std::ostream& operator<<(std::ostream& out, const NYql::TRange& range); -std::ostream& operator<<(std::ostream& out, const NYql::TIssue& error); -std::ostream& operator<<(std::ostream& out, const NYql::TIssues& error); +template <> +void Out(IOutputStream& out, const NYql::TPosition& pos); + +template <> +void Out(IOutputStream& out, const NYql::TRange& pos); + +template <> +void Out(IOutputStream& out, const NYql::TIssue& error); + +template <> +void Out(IOutputStream& out, const NYql::TIssues& error); template <> struct THash { diff --git a/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue_id.h b/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue_id.h index 8adf05c940d..930f0b27b0d 100644 --- a/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue_id.h +++ b/include/ydb-cpp-sdk/library/yql/public/issue/yql_issue_id.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace NYql { diff --git a/include/ydb-cpp-sdk/library/yson/consumer.h b/include/ydb-cpp-sdk/library/yson/consumer.h deleted file mode 100644 index a11ccac480f..00000000000 --- a/include/ydb-cpp-sdk/library/yson/consumer.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -#include - -namespace NYson { - struct TYsonConsumerBase - : public virtual NYT::NYson::IYsonConsumer { - void OnRaw(std::string_view ysonNode, NYT::NYson::EYsonType type) override; - }; -} // namespace NYson diff --git a/include/ydb-cpp-sdk/library/yson/node/node.h b/include/ydb-cpp-sdk/library/yson/node/node.h deleted file mode 100644 index 4fdc354f23c..00000000000 --- a/include/ydb-cpp-sdk/library/yson/node/node.h +++ /dev/null @@ -1,523 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include -#include -#include - -class IInputStream; -class IOutputStream; - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -class TNode -{ -public: - class TLookupError - : public TWithBackTrace - { }; - - class TTypeError - : public TWithBackTrace - { }; - - enum EType { - Undefined = 0 /*"undefined"*/, - - // NOTE: string representation of all node types - // are compatible with server node type (except `Undefined' which is missing on server). - String = 1 /*"string_node"*/, - Int64 = 2 /*"int64_node"*/, - Uint64 = 3 /*"uint64_node"*/, - Double = 4 /*"double_node"*/, - Bool = 5 /*"boolean_node"*/, - List = 6 /*"list_node"*/, - Map = 7 /*"map_node"*/, - Null = 8 /*"null"*/, - }; - - using TListType = std::vector; - using TMapType = std::unordered_map; - -private: - struct TNull { - bool operator==(const TNull&) const; - }; - - struct TUndefined { - bool operator==(const TUndefined&) const; - }; - - using TValue = std::variant< - bool, - i64, - ui64, - double, - std::string, - TListType, - TMapType, - TNull, - TUndefined - >; - -public: - - TNode(); - TNode(const char* s); - explicit TNode(std::string_view s); - explicit TNode(const std::string& s); - TNode(std::string s); - TNode(int i); - - //this case made speccially for prevent mess cast of EType into TNode through TNode(int) constructor - //usual case of error SomeNode == TNode::Undefined <-- SomeNode indeed will be compared with TNode(0) without this method - //correct way is SomeNode.GetType() == TNode::Undefined - template - Y_FORCE_INLINE TNode(EType) - { - static_assert(!std::is_same::value, "looks like a mistake, may be you forget .GetType()"); - } - - //this case made speccially for prevent mess cast of T* into TNode through implicit bool ctr - template - Y_FORCE_INLINE TNode(const T*) : TNode() { - static_assert(!std::is_same::value, "looks like a mistake, and pointer have converted to bool"); - } - - TNode(unsigned int ui); - TNode(long i); - TNode(unsigned long ui); - TNode(long long i); - TNode(unsigned long long ui); - TNode(double d); - TNode(bool b); - TNode(TMapType map); - - TNode(const TNode& rhs); - TNode& operator=(const TNode& rhs); - - TNode(TNode&& rhs) noexcept; - TNode& operator=(TNode&& rhs) noexcept; - - ~TNode(); - - void Clear(); - - bool IsString() const; - bool IsInt64() const; - bool IsUint64() const; - bool IsDouble() const; - bool IsBool() const; - bool IsList() const; - bool IsMap() const; - - // `IsEntity' is deprecated use `IsNull' instead. - bool IsEntity() const; - bool IsNull() const; - bool IsUndefined() const; - // Returns true if TNode is neither Null, nor Undefined - bool HasValue() const; - - template - bool IsOfType() const noexcept; - - // Int64, Uint64, Double, or Bool - bool IsArithmetic() const; - - bool Empty() const; - size_t Size() const; - - EType GetType() const; - - const std::string& AsString() const; - i64 AsInt64() const; - ui64 AsUint64() const; - double AsDouble() const; - bool AsBool() const; - const TListType& AsList() const; - const TMapType& AsMap() const; - TListType& AsList(); - TMapType& AsMap(); - - const std::string& UncheckedAsString() const noexcept; - i64 UncheckedAsInt64() const noexcept; - ui64 UncheckedAsUint64() const noexcept; - double UncheckedAsDouble() const noexcept; - bool UncheckedAsBool() const noexcept; - const TListType& UncheckedAsList() const noexcept; - const TMapType& UncheckedAsMap() const noexcept; - TListType& UncheckedAsList() noexcept; - TMapType& UncheckedAsMap() noexcept; - - // integer types cast - // makes overflow checks - template - T IntCast() const; - - // integers <-> double <-> string - // makes overflow checks - template - T ConvertTo() const; - - template - T& As(); - - template - const T& As() const; - - static TNode CreateList(); - static TNode CreateList(TListType list); - static TNode CreateMap(); - static TNode CreateMap(TMapType map); - static TNode CreateEntity(); - - const TNode& operator[](size_t index) const; - TNode& operator[](size_t index); - const TNode& At(size_t index) const; - TNode& At(size_t index); - - TNode& Add() &; - TNode Add() &&; - TNode& Add(const TNode& node) &; - TNode Add(const TNode& node) &&; - TNode& Add(TNode&& node) &; - TNode Add(TNode&& node) &&; - - bool HasKey(const std::string_view key) const; - - TNode& operator()(const std::string& key, const TNode& value) &; - TNode operator()(const std::string& key, const TNode& value) &&; - TNode& operator()(const std::string& key, TNode&& value) &; - TNode operator()(const std::string& key, TNode&& value) &&; - - const TNode& operator[](const std::string_view key) const; - TNode& operator[](const std::string_view key); - const TNode& At(const std::string_view key) const; - TNode& At(const std::string_view key); - - // map getters - // works the same way like simple getters - const std::string& ChildAsString(const std::string_view key) const; - i64 ChildAsInt64(const std::string_view key) const; - ui64 ChildAsUint64(const std::string_view key) const; - double ChildAsDouble(const std::string_view key) const; - bool ChildAsBool(const std::string_view key) const; - const TListType& ChildAsList(const std::string_view key) const; - const TMapType& ChildAsMap(const std::string_view key) const; - TListType& ChildAsList(const std::string_view key); - TMapType& ChildAsMap(const std::string_view key); - - template - T ChildIntCast(const std::string_view key) const; - - template - T ChildConvertTo(const std::string_view key) const; - - template - const T& ChildAs(const std::string_view key) const; - - template - T& ChildAs(const std::string_view key); - - // list getters - // works the same way like simple getters - const std::string& ChildAsString(size_t index) const; - i64 ChildAsInt64(size_t index) const; - ui64 ChildAsUint64(size_t index) const; - double ChildAsDouble(size_t index) const; - bool ChildAsBool(size_t index) const; - const TListType& ChildAsList(size_t index) const; - const TMapType& ChildAsMap(size_t index) const; - TListType& ChildAsList(size_t index); - TMapType& ChildAsMap(size_t index); - - template - T ChildIntCast(size_t index) const; - - template - T ChildConvertTo(size_t index) const; - - template - const T& ChildAs(size_t index) const; - - template - T& ChildAs(size_t index); - - - // attributes - bool HasAttributes() const; - void ClearAttributes(); - const TNode& GetAttributes() const; - TNode& Attributes(); - - void MoveWithoutAttributes(TNode&& rhs); - - // Serialize TNode using binary yson format. - // Methods for ysaveload. - void Save(IOutputStream* output) const; - void Load(IInputStream* input); - -private: - void Move(TNode&& rhs); - - void CheckType(EType type) const; - - void AssureMap(); - void AssureList(); - - void CreateAttributes(); - -private: - TValue Value_; - THolder Attributes_; - - friend bool operator==(const TNode& lhs, const TNode& rhs); - friend bool operator!=(const TNode& lhs, const TNode& rhs); -}; - -bool operator==(const TNode& lhs, const TNode& rhs); -bool operator!=(const TNode& lhs, const TNode& rhs); - -bool GetBool(const TNode& node); - -/// Debug printer for gtest -void PrintTo(const TNode& node, std::ostream* out); - -inline bool TNode::IsArithmetic() const { - return IsInt64() || IsUint64() || IsDouble() || IsBool(); -} - -template -inline T TNode::IntCast() const { - if constexpr (std::is_integral::value) { - try { - switch (GetType()) { - case TNode::Uint64: - return SafeIntegerCast(AsUint64()); - case TNode::Int64: - return SafeIntegerCast(AsInt64()); - default: - ythrow TTypeError() << "IntCast() called for type " << GetType(); - } - } catch(TBadCastException& exc) { - ythrow TTypeError() << "TBadCastException during IntCast(): " << exc.what(); - } - } else { - static_assert(sizeof(T) != sizeof(T), "implemented only for std::is_integral types"); - } -} - -template -inline T TNode::ConvertTo() const { - if constexpr (std::is_integral::value) { - switch (GetType()) { - case NYT::TNode::String: - return ::FromString(AsString()); - case NYT::TNode::Int64: - case NYT::TNode::Uint64: - return IntCast(); - case NYT::TNode::Double: - if (AsDouble() < Min() || AsDouble() > MaxFloor() || !std::isfinite(AsDouble())) { - ythrow TTypeError() << AsDouble() << " can't be converted to " << TypeName(); - } - return AsDouble(); - case NYT::TNode::Bool: - return AsBool(); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo<" << TypeName() << ">() called for type " << GetType(); - }; - } else { - static_assert(sizeof(T) != sizeof(T), "should have template specialization"); - } -} - -template<> -inline std::string TNode::ConvertTo() const { - switch (GetType()) { - case NYT::TNode::String: - return AsString(); - case NYT::TNode::Int64: - return ::ToString(AsInt64()); - case NYT::TNode::Uint64: - return ::ToString(AsUint64()); - case NYT::TNode::Double: - return ::ToString(AsDouble()); - case NYT::TNode::Bool: - return ::ToString(AsBool()); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo() called for type " << GetType(); - } - Y_UNREACHABLE(); -} - -template<> -inline double TNode::ConvertTo() const { - switch (GetType()) { - case NYT::TNode::String: - return ::FromString(AsString()); - case NYT::TNode::Int64: - return AsInt64(); - case NYT::TNode::Uint64: - return AsUint64(); - case NYT::TNode::Double: - return AsDouble(); - case NYT::TNode::Bool: - return AsBool(); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo() called for type " << GetType(); - } -} - -template<> -inline bool TNode::ConvertTo() const { - switch (GetType()) { - case NYT::TNode::String: - return ::FromString(AsString()); - case NYT::TNode::Int64: - return AsInt64(); - case NYT::TNode::Uint64: - return AsUint64(); - case NYT::TNode::Double: - return AsDouble(); - case NYT::TNode::Bool: - return AsBool(); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo() called for type " << GetType(); - } -} - -template -inline T TNode::ChildIntCast(const std::string_view key) const { - const auto& node = At(key); - try { - return node.IntCast(); - } catch (TTypeError& e) { - e << ", during getting key=" << key; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting key=" << key; - } -} - -template -inline T TNode::ChildIntCast(size_t index) const { - const auto& node = At(index); - try { - return node.IntCast(); - } catch (TTypeError& e) { - e << ", during getting index=" << index; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting index=" << index; - } -} - -template -inline T TNode::ChildConvertTo(const std::string_view key) const { - const auto& node = At(key); - try { - return node.ConvertTo(); - } catch (TTypeError& e) { - e << ", during getting key=" << key; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting key=" << key; - } -} - -template -inline T TNode::ChildConvertTo(size_t index) const { - const auto& node = At(index); - try { - return node.ConvertTo(); - } catch (TTypeError& e) { - e << ", during getting index=" << index; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting index=" << index; - } -} - -template -inline const T& TNode::ChildAs(const std::string_view key) const { - const auto& node = At(key); - try { - return node.As(); - } catch (TTypeError& e) { - e << ", during getting key=" << key; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting key=" << key; - } -} - -template -inline const T& TNode::ChildAs(size_t index) const { - const auto& node = At(index); - try { - return node.As(); - } catch (TTypeError& e) { - e << ", during getting index=" << index; - throw e; - } catch (...) { - ythrow TTypeError() << CurrentExceptionMessage() << ", during getting index=" << index; - } -} - -template -inline T& TNode::ChildAs(const std::string_view key) { - return const_cast(static_cast(this)->ChildAs(key)); -} - -template -inline T& TNode::ChildAs(size_t index) { - return const_cast(static_cast(this)->ChildAs(index)); -} - -template -inline bool TNode::IsOfType() const noexcept { - return std::holds_alternative(Value_); -} - -template -inline T& TNode::As() { - return std::get(Value_); -} - -template -inline const T& TNode::As() const { - return std::get(Value_); -} - -//////////////////////////////////////////////////////////////////////////////// - -namespace NNodeCmp { - bool operator<(const TNode& lhs, const TNode& rhs); - bool operator<=(const TNode& lhs, const TNode& rhs); - bool operator>(const TNode& lhs, const TNode& rhs); - bool operator>=(const TNode& lhs, const TNode& rhs); - bool IsComparableType(const TNode::EType type); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/include/ydb-cpp-sdk/library/yson/node/node_io.h b/include/ydb-cpp-sdk/library/yson/node/node_io.h deleted file mode 100644 index b7cfefc8d0d..00000000000 --- a/include/ydb-cpp-sdk/library/yson/node/node_io.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "node.h" -#include - -namespace NJson { - class TJsonValue; -} // namespace NJson - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -// Parse TNode from string in YSON format -TNode NodeFromYsonString(const std::string_view input, ::NYson::EYsonType type = ::NYson::EYsonType::Node); - -// Serialize TNode to string in one of YSON formats with random order of maps' keys (don't use in tests) -std::string NodeToYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) -std::string NodeToCanonicalYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Parse TNode from stream in YSON format -TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type = ::NYson::EYsonType::Node); - -// Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests) -void NodeToYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) -void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Parse TNode from string in JSON format -TNode NodeFromJsonString(const std::string_view input); -bool TryNodeFromJsonString(const std::string_view input, TNode& dst); - -// Parse TNode from string in JSON format using an iterative JSON parser. -// Iterative JSON parsers still use the stack, but allocate it on the heap (instead of using the system call stack). -// Needed to mitigate stack overflow with short stacks on deeply nested JSON strings -// (e.g. 256kb of stack when parsing "[[[[[[...]]]]]]" crashes the whole binary). -TNode NodeFromJsonStringIterative(const std::string_view input, ui64 maxDepth = 1024); - -// Convert TJsonValue to TNode -TNode NodeFromJsonValue(const ::NJson::TJsonValue& input); - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/include/ydb-cpp-sdk/library/yson/public.h b/include/ydb-cpp-sdk/library/yson/public.h deleted file mode 100644 index 0b19485f043..00000000000 --- a/include/ydb-cpp-sdk/library/yson/public.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -namespace NYson { - - //////////////////////////////////////////////////////////////////////////////// - - using NYT::NYson::EYsonFormat; - using NYT::NYson::EYsonType; - - class TYsonStringBuf; - - struct TYsonConsumerBase; - - class TYsonWriter; - class TYsonParser; - class TStatelessYsonParser; - class TYsonListParser; - - class TYsonException - : public yexception {}; - - //////////////////////////////////////////////////////////////////////////////// - -} // namespace NYson diff --git a/include/ydb-cpp-sdk/yson_value/ydb_yson_value.h b/include/ydb-cpp-sdk/library/yson_value/ydb_yson_value.h similarity index 85% rename from include/ydb-cpp-sdk/yson_value/ydb_yson_value.h rename to include/ydb-cpp-sdk/library/yson_value/ydb_yson_value.h index 09acacc402d..da92724f4bc 100644 --- a/include/ydb-cpp-sdk/yson_value/ydb_yson_value.h +++ b/include/ydb-cpp-sdk/library/yson_value/ydb_yson_value.h @@ -4,9 +4,7 @@ #include #include -#include - -#include +#include namespace NYdb { diff --git a/include/ydb-cpp-sdk/library/yt/exception/exception.h b/include/ydb-cpp-sdk/library/yt/exception/exception.h deleted file mode 100644 index 5611dfdc78b..00000000000 --- a/include/ydb-cpp-sdk/library/yt/exception/exception.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// -// These are poor man's versions of NYT::TErrorException to be used in -// a limited subset of core libraries that are needed to implement NYT::TError. - -class TSimpleException - : public std::exception -{ -public: - explicit TSimpleException(std::string message); - - const std::string& GetMessage() const; - const char* what() const noexcept override; - -protected: - const std::string Message_; -}; - -class TCompositeException - : public TSimpleException -{ -public: - explicit TCompositeException(std::string message); - TCompositeException( - const std::exception& exception, - std::string message); - - const std::exception_ptr& GetInnerException() const; - const char* what() const noexcept override; - -private: - const std::exception_ptr InnerException_; - const std::string What_; -}; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/include/ydb-cpp-sdk/library/yt/misc/enum-inl.h b/include/ydb-cpp-sdk/library/yt/misc/enum-inl.h deleted file mode 100644 index 92e0f442d7f..00000000000 --- a/include/ydb-cpp-sdk/library/yt/misc/enum-inl.h +++ /dev/null @@ -1,423 +0,0 @@ -#pragma once -#ifndef ENUM_INL_H_ -#error "Direct inclusion of this file is not allowed, include enum.h" -// For the sake of sane code completion. -#include "enum.h" -#endif - -#include -#include - -#include - -#include -#include -#include - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -#define ENUM__CLASS(enumType, underlyingType, seq) \ - enum class enumType : underlyingType \ - { \ - PP_FOR_EACH(ENUM__DOMAIN_ITEM, seq) \ - }; - -#define ENUM__DOMAIN_ITEM(item) \ - PP_IF( \ - PP_IS_SEQUENCE(item), \ - ENUM__DOMAIN_ITEM_SEQ, \ - ENUM__DOMAIN_ITEM_ATOMIC \ - )(item)() - -#define ENUM__DOMAIN_ITEM_ATOMIC(item) \ - item PP_COMMA - -#define ENUM__DOMAIN_ITEM_SEQ(seq) \ - PP_ELEMENT(seq, 0) = PP_ELEMENT(seq, 1) PP_COMMA - -//////////////////////////////////////////////////////////////////////////////// - -namespace NDetail { - -template -constexpr bool CheckValuesMonotonic(const TValues& values) -{ - return std::adjacent_find(values.begin(), values.end(), std::greater_equal<>()) == values.end(); -} - -template -constexpr bool CheckValuesUnique(const TValues& values) -{ - for (size_t i = 0; i < std::size(values); ++i) { - for (size_t j = i + 1; j < std::size(values); ++j) { - if (values[i] == values[j]) { - return false; - } - } - } - return true; -} - -template -constexpr bool CheckDomainNames(const TNames& names) -{ - for (size_t i = 0; i < std::size(names); ++i) { - if (std::size(names[i]) == 0) { - return false; - } - for (size_t j = 1; j < std::size(names[i]); ++j) { - // If name does not start with a capital letter, all the others must be in lowercase. - if (('A' <= names[i][j] && names[i][j] <= 'Z') && ('A' > names[i][0] || names[i][0] > 'Z')) { - return false; - } - } - } - return true; -} - -} // namespace NDetail - -//////////////////////////////////////////////////////////////////////////////// - -#define ENUM__BEGIN_TRAITS(enumType, underlyingType, isBit, isStringSerializable, seq) \ - struct TEnumTraitsImpl_##enumType \ - { \ - using T = enumType; \ - \ - [[maybe_unused]] static constexpr bool IsBitEnum = isBit; \ - [[maybe_unused]] static constexpr bool IsStringSerializableEnum = isStringSerializable; \ - static constexpr int DomainSize = PP_COUNT(seq); \ - \ - static constexpr int GetDomainSize() \ - { \ - return DomainSize; \ - } \ - \ - static constexpr std::array Names{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_NAMES_ITEM, seq) \ - }}; \ - static_assert(::NYT::NDetail::CheckDomainNames(Names), \ - "Enumeration " #enumType " contains names in wrong format"); \ - static constexpr std::array Values{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_VALUES_ITEM, seq) \ - }}; \ - \ - [[maybe_unused]] static constexpr bool IsMonotonic = \ - ::NYT::NDetail::CheckValuesMonotonic(Values); \ - \ - static std::string_view GetTypeName() \ - { \ - static constexpr std::string_view Result = PP_STRINGIZE(enumType); \ - return Result; \ - } \ - \ - static const std::optional FindLiteralByValue(T value) \ - { \ - for (int i = 0; i < GetDomainSize(); ++i) { \ - if (Values[i] == value) { \ - return Names[i]; \ - } \ - } \ - return std::nullopt; \ - } \ - \ - static std::optional FindValueByLiteral(std::string_view literal) \ - { \ - for (int i = 0; i < GetDomainSize(); ++i) { \ - if (Names[i] == literal) { \ - return Values[i]; \ - } \ - } \ - return std::nullopt; \ - } \ - \ - static constexpr const std::array& GetDomainNames() \ - { \ - return Names; \ - } \ - \ - static constexpr const std::array& GetDomainValues() \ - { \ - return Values; \ - } - -#define ENUM__GET_DOMAIN_VALUES_ITEM(item) \ - PP_IF( \ - PP_IS_SEQUENCE(item), \ - ENUM__GET_DOMAIN_VALUES_ITEM_SEQ, \ - ENUM__GET_DOMAIN_VALUES_ITEM_ATOMIC \ - )(item) - -#define ENUM__GET_DOMAIN_VALUES_ITEM_SEQ(seq) \ - ENUM__GET_DOMAIN_VALUES_ITEM_ATOMIC(PP_ELEMENT(seq, 0)) - -#define ENUM__GET_DOMAIN_VALUES_ITEM_ATOMIC(item) \ - T::item, - -#define ENUM__GET_DOMAIN_NAMES_ITEM(item) \ - PP_IF( \ - PP_IS_SEQUENCE(item), \ - ENUM__GET_DOMAIN_NAMES_ITEM_SEQ, \ - ENUM__GET_DOMAIN_NAMES_ITEM_ATOMIC \ - )(item) - -#define ENUM__GET_DOMAIN_NAMES_ITEM_SEQ(seq) \ - PP_IF( \ - ENUM__ITEM_SEQ_HAS_DOMAIN_NAME(seq), \ - ENUM__GET_DOMAIN_NAMES_ITEM_SEQ_CUSTOM, \ - ENUM__GET_DOMAIN_NAMES_ITEM_SEQ_AUTO \ - )(seq) - -#define ENUM__ITEM_SEQ_HAS_DOMAIN_NAME(seq) \ - PP_CONCAT(ENUM__ITEM_SEQ_HAS_DOMAIN_NAME_, PP_COUNT(seq)) - -#define ENUM__ITEM_SEQ_HAS_DOMAIN_NAME_2 PP_FALSE -#define ENUM__ITEM_SEQ_HAS_DOMAIN_NAME_3 PP_TRUE - -#define ENUM__GET_DOMAIN_NAMES_ITEM_SEQ_CUSTOM(seq) \ - std::string_view(PP_ELEMENT(seq, 2)), - -#define ENUM__GET_DOMAIN_NAMES_ITEM_SEQ_AUTO(seq) \ - ENUM__GET_DOMAIN_NAMES_ITEM_ATOMIC(PP_ELEMENT(seq, 0)) - -#define ENUM__GET_DOMAIN_NAMES_ITEM_ATOMIC(item) \ - std::string_view(PP_STRINGIZE(item)), - -#define ENUM__VALIDATE_UNIQUE(enumType) \ - static_assert(IsMonotonic || ::NYT::NDetail::CheckValuesUnique(Values), \ - "Enumeration " #enumType " contains duplicate values"); - -#define ENUM__END_TRAITS(enumType) \ - }; \ - \ - [[maybe_unused]] inline TEnumTraitsImpl_##enumType GetEnumTraitsImpl(enumType) \ - { \ - return {}; \ - } \ - \ - using ::ToString; \ - [[maybe_unused]] inline std::string ToString(enumType value) \ - { \ - return ::NYT::TEnumTraits::ToString(value); \ - } - -//////////////////////////////////////////////////////////////////////////////// - -template -constexpr int TEnumTraitsWithKnownDomain::GetDomainSize() -{ - return TEnumTraitsImpl::GetDomainSize(); -} - -template -constexpr auto TEnumTraitsWithKnownDomain::GetDomainNames() -> const std::array& -{ - return TEnumTraitsImpl::GetDomainNames(); -} - -template -constexpr auto TEnumTraitsWithKnownDomain::GetDomainValues() -> const std::array& -{ - return TEnumTraitsImpl::GetDomainValues(); -} - -template -constexpr T TEnumTraitsWithKnownDomain::GetMinValue() - requires (!TEnumTraitsImpl::IsBitEnum) -{ - const auto& values = GetDomainValues(); - static_assert(!values.empty()); \ - return *std::min_element(std::begin(values), std::end(values)); -} - -template -constexpr T TEnumTraitsWithKnownDomain::GetMaxValue() - requires (!TEnumTraitsImpl::IsBitEnum) -{ - const auto& values = GetDomainValues(); - static_assert(!values.empty()); \ - return *std::max_element(std::begin(values), std::end(values)); -} - -template -std::vector TEnumTraitsWithKnownDomain::Decompose(T value) - requires (TEnumTraitsImpl::IsBitEnum) -{ - std::vector result; - for (auto domainValue : GetDomainValues()) { - if (Any(value & domainValue)) { - result.push_back(domainValue); - } - } - return result; -} - -//////////////////////////////////////////////////////////////////////////////// - -template -std::string_view TEnumTraits::GetTypeName() -{ - return TEnumTraitsImpl::GetTypeName(); -} - -template -std::optional TEnumTraits::FindValueByLiteral(std::string_view literal) -{ - return TEnumTraitsImpl::FindValueByLiteral(literal); -} - -template -std::optional TEnumTraits::FindLiteralByValue(T value) -{ - return TEnumTraitsImpl::FindLiteralByValue(value); -} - -template -std::string TEnumTraits::ToString(T value) -{ - using ::ToString; - if (auto optionalLiteral = TEnumTraits::FindLiteralByValue(value)) { - return ToString(*optionalLiteral); - } - std::string result; - result = TEnumTraits::GetTypeName(); - result += "("; - result += ToString(ToUnderlying(value)); - result += ")"; - return result; -} - -template -T TEnumTraits::FromString(std::string_view literal) -{ - auto optionalValue = FindValueByLiteral(literal); - if (!optionalValue) { - throw ::NYT::TSimpleException(std::format("Error parsing {} value {}", - GetTypeName().data(), - NUtils::Quote(literal))); - } - return *optionalValue; -} - -//////////////////////////////////////////////////////////////////////////////// - -template -constexpr TEnumIndexedVector::TEnumIndexedVector() - : Items_{} -{ } - -template -constexpr TEnumIndexedVector::TEnumIndexedVector(std::initializer_list elements) - : Items_{} -{ - Y_ASSERT(std::distance(elements.begin(), elements.end()) <= N); - size_t index = 0; - for (const auto& element : elements) { - Items_[index++] = element; - } -} - -template -T& TEnumIndexedVector::operator[] (E index) -{ - Y_ASSERT(index >= Min && index <= Max); - return Items_[ToUnderlying(index) - ToUnderlying(Min)]; -} - -template -const T& TEnumIndexedVector::operator[] (E index) const -{ - return const_cast(*this)[index]; -} - -template -T* TEnumIndexedVector::begin() -{ - return Items_.data(); -} - -template -const T* TEnumIndexedVector::begin() const -{ - return Items_.data(); -} - -template -T* TEnumIndexedVector::end() -{ - return begin() + N; -} - -template -const T* TEnumIndexedVector::end() const -{ - return begin() + N; -} - -template -bool TEnumIndexedVector::IsDomainValue(E value) -{ - return value >= Min && value <= Max; -} - -//////////////////////////////////////////////////////////////////////////////// - -#define ENUM__BINARY_BITWISE_OPERATOR(T, assignOp, op) \ - [[maybe_unused]] inline constexpr T operator op (T lhs, T rhs) \ - { \ - return T(ToUnderlying(lhs) op ToUnderlying(rhs)); \ - } \ - \ - [[maybe_unused]] inline T& operator assignOp (T& lhs, T rhs) \ - { \ - lhs = T(ToUnderlying(lhs) op ToUnderlying(rhs)); \ - return lhs; \ - } - -#define ENUM__UNARY_BITWISE_OPERATOR(T, op) \ - [[maybe_unused]] inline constexpr T operator op (T value) \ - { \ - return T(op ToUnderlying(value)); \ - } - -#define ENUM__BIT_SHIFT_OPERATOR(T, assignOp, op) \ - [[maybe_unused]] inline constexpr T operator op (T lhs, size_t rhs) \ - { \ - return T(ToUnderlying(lhs) op rhs); \ - } \ - \ - [[maybe_unused]] inline T& operator assignOp (T& lhs, size_t rhs) \ - { \ - lhs = T(ToUnderlying(lhs) op rhs); \ - return lhs; \ - } - -#define ENUM__BITWISE_OPS(enumType) \ - ENUM__BINARY_BITWISE_OPERATOR(enumType, &=, &) \ - ENUM__BINARY_BITWISE_OPERATOR(enumType, |=, | ) \ - ENUM__BINARY_BITWISE_OPERATOR(enumType, ^=, ^) \ - ENUM__UNARY_BITWISE_OPERATOR(enumType, ~) \ - ENUM__BIT_SHIFT_OPERATOR(enumType, <<=, << ) \ - ENUM__BIT_SHIFT_OPERATOR(enumType, >>=, >> ) - -//////////////////////////////////////////////////////////////////////////////// - -template - requires TEnumTraits::IsBitEnum -constexpr bool Any(E value) noexcept -{ - return ToUnderlying(value) != 0; -} - -template - requires TEnumTraits::IsBitEnum -constexpr bool None(E value) noexcept -{ - return ToUnderlying(value) == 0; -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/include/ydb-cpp-sdk/library/yt/misc/enum.h b/include/ydb-cpp-sdk/library/yt/misc/enum.h deleted file mode 100644 index 3c25d7f93b2..00000000000 --- a/include/ydb-cpp-sdk/library/yt/misc/enum.h +++ /dev/null @@ -1,249 +0,0 @@ -#pragma once - -#include "preprocessor.h" - -#include - -#include -#include -#include -#include - -#include - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// -/* - * Smart enumerations augment C++ enum classes with a bunch of reflection - * capabilities accessible via TEnumTraits class specialization. - * - * Please refer to the unit test for an actual example of usage - * (unittests/enum_ut.cpp). - */ - -// The actual overload must be provided with DEFINE_ENUM* (see below). -template -void GetEnumTraitsImpl(T); - -template -using TEnumTraitsImpl = decltype(GetEnumTraitsImpl(T())); - -template -constexpr bool IsEnumDomainSizeKnown() -{ - if constexpr(requires{ TEnumTraitsImpl::DomainSize; }) { - return true; - } else { - return false; - } -} - -template < - class T, - bool = IsEnumDomainSizeKnown() -> -struct TEnumTraitsWithKnownDomain -{ }; - -template < - class T, - bool = std::is_enum_v && !std::is_same_v, void> -> -struct TEnumTraits -{ - static constexpr bool IsEnum = false; - static constexpr bool IsBitEnum = false; - static constexpr bool IsStringSerializableEnum = false; - static constexpr bool IsMonotonic = false; -}; - -template -struct TEnumTraitsWithKnownDomain -{ - static constexpr int GetDomainSize(); - - static constexpr const std::array& GetDomainNames(); - static constexpr const std::array& GetDomainValues(); - - // For non-bit enums only. - static constexpr T GetMinValue() - requires (!TEnumTraitsImpl::IsBitEnum); - static constexpr T GetMaxValue() - requires (!TEnumTraitsImpl::IsBitEnum); - - // For bit enums only. - static std::vector Decompose(T value) - requires (TEnumTraitsImpl::IsBitEnum); -}; - -template -struct TEnumTraits - : public TEnumTraitsWithKnownDomain -{ - static constexpr bool IsEnum = true; - static constexpr bool IsBitEnum = TEnumTraitsImpl::IsBitEnum; - static constexpr bool IsStringSerializableEnum = TEnumTraitsImpl::IsStringSerializableEnum; - static constexpr bool IsMonotonic = TEnumTraitsImpl::IsMonotonic; - - static std::string_view GetTypeName(); - - static std::optional FindLiteralByValue(T value); - static std::optional FindValueByLiteral(std::string_view literal); - - static std::string ToString(T value); - static T FromString(std::string_view literal); -}; - -//////////////////////////////////////////////////////////////////////////////// - -//! Defines a smart enumeration with a specific underlying type. -/*! - * \param enumType Enumeration enumType. - * \param seq Enumeration domain encoded as a sequence. - * \param underlyingType Underlying type. - */ -#define DEFINE_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, false, false, seq) \ - ENUM__VALIDATE_UNIQUE(enumType) \ - ENUM__END_TRAITS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with a specific underlying type. -//! Duplicate enumeration values are allowed. -#define DEFINE_AMBIGUOUS_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, false, false, seq) \ - ENUM__END_TRAITS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with the default |int| underlying type. -#define DEFINE_ENUM(enumType, seq) \ - DEFINE_ENUM_WITH_UNDERLYING_TYPE(enumType, int, seq) - -//! Defines a smart enumeration with a specific underlying type. -/*! - * \param enumType Enumeration enumType. - * \param seq Enumeration domain encoded as a sequence. - * \param underlyingType Underlying type. - */ -#define DEFINE_BIT_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, true, false, seq) \ - ENUM__VALIDATE_UNIQUE(enumType) \ - ENUM__END_TRAITS(enumType) \ - ENUM__BITWISE_OPS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with a specific underlying type. -//! Duplicate enumeration values are allowed. -/*! - * \param enumType Enumeration enumType. - * \param seq Enumeration domain encoded as a sequence. - * \param underlyingType Underlying type. - */ -#define DEFINE_AMBIGUOUS_BIT_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, true, false, seq) \ - ENUM__END_TRAITS(enumType) \ - ENUM__BITWISE_OPS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with the default |unsigned int| underlying type. -/*! - * \param enumType Enumeration enumType. - * \param seq Enumeration domain encoded as a sequence. - */ -#define DEFINE_BIT_ENUM(enumType, seq) \ - DEFINE_BIT_ENUM_WITH_UNDERLYING_TYPE(enumType, unsigned int, seq) - -//! Defines a smart enumeration with a specific underlying type and IsStringSerializable attribute. -/*! - * \param enumType Enumeration enumType. - * \param seq Enumeration domain encoded as a sequence. - * \param underlyingType Underlying type. - */ -#define DEFINE_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, false, true, seq) \ - ENUM__VALIDATE_UNIQUE(enumType) \ - ENUM__END_TRAITS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with a specific underlying type and IsStringSerializable attribute. -//! Duplicate enumeration values are allowed. -#define DEFINE_AMBIGUOUS_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(enumType, underlyingType, seq) \ - ENUM__CLASS(enumType, underlyingType, seq) \ - ENUM__BEGIN_TRAITS(enumType, underlyingType, false, true, seq) \ - ENUM__END_TRAITS(enumType) \ - static_assert(true) - -//! Defines a smart enumeration with the default |int| underlying type and IsStringSerializable attribute. -#define DEFINE_STRING_SERIALIZABLE_ENUM(enumType, seq) \ - DEFINE_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(enumType, int, seq) - -//////////////////////////////////////////////////////////////////////////////// - -//! A statically sized vector with elements of type |T| indexed by -//! the items of enumeration type |E|. -/*! - * Items are value-initialized on construction. - */ -template < - class E, - class T, - E Min = TEnumTraits::GetMinValue(), - E Max = TEnumTraits::GetMaxValue() -> -class TEnumIndexedVector -{ -public: - using TIndex = E; - using TValue = T; - - constexpr TEnumIndexedVector(); - constexpr TEnumIndexedVector(std::initializer_list elements); - - constexpr TEnumIndexedVector(const TEnumIndexedVector&) = default; - constexpr TEnumIndexedVector(TEnumIndexedVector&&) noexcept = default; - - constexpr TEnumIndexedVector& operator=(const TEnumIndexedVector&) = default; - constexpr TEnumIndexedVector& operator=(TEnumIndexedVector&&) noexcept = default; - - T& operator[] (E index); - const T& operator[] (E index) const; - - // STL interop. - T* begin(); - const T* begin() const; - T* end(); - const T* end() const; - - static bool IsDomainValue(E value); - -private: - using TUnderlying = std::underlying_type_t; - static constexpr int N = static_cast(Max) - static_cast(Min) + 1; - std::array Items_; -}; - -//////////////////////////////////////////////////////////////////////////////// - -//! Returns |true| iff the enumeration value is not bitwise zero. -template - requires TEnumTraits::IsBitEnum -constexpr bool Any(E value) noexcept; - -//! Returns |true| iff the enumeration value is bitwise zero. -template - requires TEnumTraits::IsBitEnum -constexpr bool None(E value) noexcept; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT - -#define ENUM_INL_H_ -#include "enum-inl.h" -#undef ENUM_INL_H_ diff --git a/include/ydb-cpp-sdk/library/yt/misc/preprocessor-gen.h b/include/ydb-cpp-sdk/library/yt/misc/preprocessor-gen.h deleted file mode 100644 index b809941bcdf..00000000000 --- a/include/ydb-cpp-sdk/library/yt/misc/preprocessor-gen.h +++ /dev/null @@ -1,1249 +0,0 @@ -#pragma once - -// WARNING: This file was auto-generated. -// Please, consider incorporating any changes into the generator. - -// Generated on Wed Dec 9 14:20:20 2015. - - -/*! - \internal -*/ - -#ifndef PREPROCESSOR_GEN_H_ -#error "Direct inclusion of this file is not allowed, include preprocessor.h" -// For the sake of sane code completion. -#include "preprocessor.h" -#endif -#undef PREPROCESSOR_GEN_H_ - -//////////////////////////////////////////////////////////////////////////////// -#define PP_COUNT_IMPL(...) PP_CONCAT(PP_COUNT_CONST_, \ - PP_COUNT_IMPL_0 __VA_ARGS__) -#define PP_COUNT_CONST_PP_COUNT_IMPL_0 0 -#define PP_COUNT_CONST_PP_COUNT_IMPL_1 1 -#define PP_COUNT_CONST_PP_COUNT_IMPL_2 2 -#define PP_COUNT_CONST_PP_COUNT_IMPL_3 3 -#define PP_COUNT_CONST_PP_COUNT_IMPL_4 4 -#define PP_COUNT_CONST_PP_COUNT_IMPL_5 5 -#define PP_COUNT_CONST_PP_COUNT_IMPL_6 6 -#define PP_COUNT_CONST_PP_COUNT_IMPL_7 7 -#define PP_COUNT_CONST_PP_COUNT_IMPL_8 8 -#define PP_COUNT_CONST_PP_COUNT_IMPL_9 9 -#define PP_COUNT_CONST_PP_COUNT_IMPL_10 10 -#define PP_COUNT_CONST_PP_COUNT_IMPL_11 11 -#define PP_COUNT_CONST_PP_COUNT_IMPL_12 12 -#define PP_COUNT_CONST_PP_COUNT_IMPL_13 13 -#define PP_COUNT_CONST_PP_COUNT_IMPL_14 14 -#define PP_COUNT_CONST_PP_COUNT_IMPL_15 15 -#define PP_COUNT_CONST_PP_COUNT_IMPL_16 16 -#define PP_COUNT_CONST_PP_COUNT_IMPL_17 17 -#define PP_COUNT_CONST_PP_COUNT_IMPL_18 18 -#define PP_COUNT_CONST_PP_COUNT_IMPL_19 19 -#define PP_COUNT_CONST_PP_COUNT_IMPL_20 20 -#define PP_COUNT_CONST_PP_COUNT_IMPL_21 21 -#define PP_COUNT_CONST_PP_COUNT_IMPL_22 22 -#define PP_COUNT_CONST_PP_COUNT_IMPL_23 23 -#define PP_COUNT_CONST_PP_COUNT_IMPL_24 24 -#define PP_COUNT_CONST_PP_COUNT_IMPL_25 25 -#define PP_COUNT_CONST_PP_COUNT_IMPL_26 26 -#define PP_COUNT_CONST_PP_COUNT_IMPL_27 27 -#define PP_COUNT_CONST_PP_COUNT_IMPL_28 28 -#define PP_COUNT_CONST_PP_COUNT_IMPL_29 29 -#define PP_COUNT_CONST_PP_COUNT_IMPL_30 30 -#define PP_COUNT_CONST_PP_COUNT_IMPL_31 31 -#define PP_COUNT_CONST_PP_COUNT_IMPL_32 32 -#define PP_COUNT_CONST_PP_COUNT_IMPL_33 33 -#define PP_COUNT_CONST_PP_COUNT_IMPL_34 34 -#define PP_COUNT_CONST_PP_COUNT_IMPL_35 35 -#define PP_COUNT_CONST_PP_COUNT_IMPL_36 36 -#define PP_COUNT_CONST_PP_COUNT_IMPL_37 37 -#define PP_COUNT_CONST_PP_COUNT_IMPL_38 38 -#define PP_COUNT_CONST_PP_COUNT_IMPL_39 39 -#define PP_COUNT_CONST_PP_COUNT_IMPL_40 40 -#define PP_COUNT_CONST_PP_COUNT_IMPL_41 41 -#define PP_COUNT_CONST_PP_COUNT_IMPL_42 42 -#define PP_COUNT_CONST_PP_COUNT_IMPL_43 43 -#define PP_COUNT_CONST_PP_COUNT_IMPL_44 44 -#define PP_COUNT_CONST_PP_COUNT_IMPL_45 45 -#define PP_COUNT_CONST_PP_COUNT_IMPL_46 46 -#define PP_COUNT_CONST_PP_COUNT_IMPL_47 47 -#define PP_COUNT_CONST_PP_COUNT_IMPL_48 48 -#define PP_COUNT_CONST_PP_COUNT_IMPL_49 49 -#define PP_COUNT_CONST_PP_COUNT_IMPL_50 50 -#define PP_COUNT_CONST_PP_COUNT_IMPL_51 51 -#define PP_COUNT_CONST_PP_COUNT_IMPL_52 52 -#define PP_COUNT_CONST_PP_COUNT_IMPL_53 53 -#define PP_COUNT_CONST_PP_COUNT_IMPL_54 54 -#define PP_COUNT_CONST_PP_COUNT_IMPL_55 55 -#define PP_COUNT_CONST_PP_COUNT_IMPL_56 56 -#define PP_COUNT_CONST_PP_COUNT_IMPL_57 57 -#define PP_COUNT_CONST_PP_COUNT_IMPL_58 58 -#define PP_COUNT_CONST_PP_COUNT_IMPL_59 59 -#define PP_COUNT_CONST_PP_COUNT_IMPL_60 60 -#define PP_COUNT_CONST_PP_COUNT_IMPL_61 61 -#define PP_COUNT_CONST_PP_COUNT_IMPL_62 62 -#define PP_COUNT_CONST_PP_COUNT_IMPL_63 63 -#define PP_COUNT_CONST_PP_COUNT_IMPL_64 64 -#define PP_COUNT_CONST_PP_COUNT_IMPL_65 65 -#define PP_COUNT_CONST_PP_COUNT_IMPL_66 66 -#define PP_COUNT_CONST_PP_COUNT_IMPL_67 67 -#define PP_COUNT_CONST_PP_COUNT_IMPL_68 68 -#define PP_COUNT_CONST_PP_COUNT_IMPL_69 69 -#define PP_COUNT_CONST_PP_COUNT_IMPL_70 70 -#define PP_COUNT_CONST_PP_COUNT_IMPL_71 71 -#define PP_COUNT_CONST_PP_COUNT_IMPL_72 72 -#define PP_COUNT_CONST_PP_COUNT_IMPL_73 73 -#define PP_COUNT_CONST_PP_COUNT_IMPL_74 74 -#define PP_COUNT_CONST_PP_COUNT_IMPL_75 75 -#define PP_COUNT_CONST_PP_COUNT_IMPL_76 76 -#define PP_COUNT_CONST_PP_COUNT_IMPL_77 77 -#define PP_COUNT_CONST_PP_COUNT_IMPL_78 78 -#define PP_COUNT_CONST_PP_COUNT_IMPL_79 79 -#define PP_COUNT_CONST_PP_COUNT_IMPL_80 80 -#define PP_COUNT_CONST_PP_COUNT_IMPL_81 81 -#define PP_COUNT_CONST_PP_COUNT_IMPL_82 82 -#define PP_COUNT_CONST_PP_COUNT_IMPL_83 83 -#define PP_COUNT_CONST_PP_COUNT_IMPL_84 84 -#define PP_COUNT_CONST_PP_COUNT_IMPL_85 85 -#define PP_COUNT_CONST_PP_COUNT_IMPL_86 86 -#define PP_COUNT_CONST_PP_COUNT_IMPL_87 87 -#define PP_COUNT_CONST_PP_COUNT_IMPL_88 88 -#define PP_COUNT_CONST_PP_COUNT_IMPL_89 89 -#define PP_COUNT_CONST_PP_COUNT_IMPL_90 90 -#define PP_COUNT_CONST_PP_COUNT_IMPL_91 91 -#define PP_COUNT_CONST_PP_COUNT_IMPL_92 92 -#define PP_COUNT_CONST_PP_COUNT_IMPL_93 93 -#define PP_COUNT_CONST_PP_COUNT_IMPL_94 94 -#define PP_COUNT_CONST_PP_COUNT_IMPL_95 95 -#define PP_COUNT_CONST_PP_COUNT_IMPL_96 96 -#define PP_COUNT_CONST_PP_COUNT_IMPL_97 97 -#define PP_COUNT_CONST_PP_COUNT_IMPL_98 98 -#define PP_COUNT_CONST_PP_COUNT_IMPL_99 99 -#define PP_COUNT_CONST_PP_COUNT_IMPL_100 100 -#define PP_COUNT_CONST_PP_COUNT_IMPL_101 101 -#define PP_COUNT_CONST_PP_COUNT_IMPL_102 102 -#define PP_COUNT_CONST_PP_COUNT_IMPL_103 103 -#define PP_COUNT_CONST_PP_COUNT_IMPL_104 104 -#define PP_COUNT_CONST_PP_COUNT_IMPL_105 105 -#define PP_COUNT_CONST_PP_COUNT_IMPL_106 106 -#define PP_COUNT_CONST_PP_COUNT_IMPL_107 107 -#define PP_COUNT_CONST_PP_COUNT_IMPL_108 108 -#define PP_COUNT_CONST_PP_COUNT_IMPL_109 109 -#define PP_COUNT_CONST_PP_COUNT_IMPL_110 110 -#define PP_COUNT_CONST_PP_COUNT_IMPL_111 111 -#define PP_COUNT_CONST_PP_COUNT_IMPL_112 112 -#define PP_COUNT_CONST_PP_COUNT_IMPL_113 113 -#define PP_COUNT_CONST_PP_COUNT_IMPL_114 114 -#define PP_COUNT_CONST_PP_COUNT_IMPL_115 115 -#define PP_COUNT_CONST_PP_COUNT_IMPL_116 116 -#define PP_COUNT_CONST_PP_COUNT_IMPL_117 117 -#define PP_COUNT_CONST_PP_COUNT_IMPL_118 118 -#define PP_COUNT_CONST_PP_COUNT_IMPL_119 119 -#define PP_COUNT_CONST_PP_COUNT_IMPL_120 120 -#define PP_COUNT_CONST_PP_COUNT_IMPL_121 121 -#define PP_COUNT_CONST_PP_COUNT_IMPL_122 122 -#define PP_COUNT_CONST_PP_COUNT_IMPL_123 123 -#define PP_COUNT_CONST_PP_COUNT_IMPL_124 124 -#define PP_COUNT_CONST_PP_COUNT_IMPL_125 125 -#define PP_COUNT_CONST_PP_COUNT_IMPL_126 126 -#define PP_COUNT_CONST_PP_COUNT_IMPL_127 127 -#define PP_COUNT_CONST_PP_COUNT_IMPL_128 128 -#define PP_COUNT_CONST_PP_COUNT_IMPL_129 129 -#define PP_COUNT_CONST_PP_COUNT_IMPL_130 130 -#define PP_COUNT_CONST_PP_COUNT_IMPL_131 131 -#define PP_COUNT_CONST_PP_COUNT_IMPL_132 132 -#define PP_COUNT_CONST_PP_COUNT_IMPL_133 133 -#define PP_COUNT_CONST_PP_COUNT_IMPL_134 134 -#define PP_COUNT_CONST_PP_COUNT_IMPL_135 135 -#define PP_COUNT_CONST_PP_COUNT_IMPL_136 136 -#define PP_COUNT_CONST_PP_COUNT_IMPL_137 137 -#define PP_COUNT_CONST_PP_COUNT_IMPL_138 138 -#define PP_COUNT_CONST_PP_COUNT_IMPL_139 139 -#define PP_COUNT_CONST_PP_COUNT_IMPL_140 140 -#define PP_COUNT_CONST_PP_COUNT_IMPL_141 141 -#define PP_COUNT_CONST_PP_COUNT_IMPL_142 142 -#define PP_COUNT_CONST_PP_COUNT_IMPL_143 143 -#define PP_COUNT_CONST_PP_COUNT_IMPL_144 144 -#define PP_COUNT_CONST_PP_COUNT_IMPL_145 145 -#define PP_COUNT_CONST_PP_COUNT_IMPL_146 146 -#define PP_COUNT_CONST_PP_COUNT_IMPL_147 147 -#define PP_COUNT_CONST_PP_COUNT_IMPL_148 148 -#define PP_COUNT_CONST_PP_COUNT_IMPL_149 149 -#define PP_COUNT_CONST_PP_COUNT_IMPL_150 150 -#define PP_COUNT_CONST_PP_COUNT_IMPL_151 151 -#define PP_COUNT_CONST_PP_COUNT_IMPL_152 152 -#define PP_COUNT_CONST_PP_COUNT_IMPL_153 153 -#define PP_COUNT_CONST_PP_COUNT_IMPL_154 154 -#define PP_COUNT_CONST_PP_COUNT_IMPL_155 155 -#define PP_COUNT_CONST_PP_COUNT_IMPL_156 156 -#define PP_COUNT_CONST_PP_COUNT_IMPL_157 157 -#define PP_COUNT_CONST_PP_COUNT_IMPL_158 158 -#define PP_COUNT_CONST_PP_COUNT_IMPL_159 159 -#define PP_COUNT_CONST_PP_COUNT_IMPL_160 160 -#define PP_COUNT_CONST_PP_COUNT_IMPL_161 161 -#define PP_COUNT_CONST_PP_COUNT_IMPL_162 162 -#define PP_COUNT_CONST_PP_COUNT_IMPL_163 163 -#define PP_COUNT_CONST_PP_COUNT_IMPL_164 164 -#define PP_COUNT_CONST_PP_COUNT_IMPL_165 165 -#define PP_COUNT_CONST_PP_COUNT_IMPL_166 166 -#define PP_COUNT_CONST_PP_COUNT_IMPL_167 167 -#define PP_COUNT_CONST_PP_COUNT_IMPL_168 168 -#define PP_COUNT_CONST_PP_COUNT_IMPL_169 169 -#define PP_COUNT_CONST_PP_COUNT_IMPL_170 170 -#define PP_COUNT_CONST_PP_COUNT_IMPL_171 171 -#define PP_COUNT_CONST_PP_COUNT_IMPL_172 172 -#define PP_COUNT_CONST_PP_COUNT_IMPL_173 173 -#define PP_COUNT_CONST_PP_COUNT_IMPL_174 174 -#define PP_COUNT_CONST_PP_COUNT_IMPL_175 175 -#define PP_COUNT_CONST_PP_COUNT_IMPL_176 176 -#define PP_COUNT_CONST_PP_COUNT_IMPL_177 177 -#define PP_COUNT_CONST_PP_COUNT_IMPL_178 178 -#define PP_COUNT_CONST_PP_COUNT_IMPL_179 179 -#define PP_COUNT_CONST_PP_COUNT_IMPL_180 180 -#define PP_COUNT_CONST_PP_COUNT_IMPL_181 181 -#define PP_COUNT_CONST_PP_COUNT_IMPL_182 182 -#define PP_COUNT_CONST_PP_COUNT_IMPL_183 183 -#define PP_COUNT_CONST_PP_COUNT_IMPL_184 184 -#define PP_COUNT_CONST_PP_COUNT_IMPL_185 185 -#define PP_COUNT_CONST_PP_COUNT_IMPL_186 186 -#define PP_COUNT_CONST_PP_COUNT_IMPL_187 187 -#define PP_COUNT_CONST_PP_COUNT_IMPL_188 188 -#define PP_COUNT_CONST_PP_COUNT_IMPL_189 189 -#define PP_COUNT_CONST_PP_COUNT_IMPL_190 190 -#define PP_COUNT_CONST_PP_COUNT_IMPL_191 191 -#define PP_COUNT_CONST_PP_COUNT_IMPL_192 192 -#define PP_COUNT_CONST_PP_COUNT_IMPL_193 193 -#define PP_COUNT_CONST_PP_COUNT_IMPL_194 194 -#define PP_COUNT_CONST_PP_COUNT_IMPL_195 195 -#define PP_COUNT_CONST_PP_COUNT_IMPL_196 196 -#define PP_COUNT_CONST_PP_COUNT_IMPL_197 197 -#define PP_COUNT_CONST_PP_COUNT_IMPL_198 198 -#define PP_COUNT_CONST_PP_COUNT_IMPL_199 199 -#define PP_COUNT_IMPL_0(_) PP_COUNT_IMPL_1 -#define PP_COUNT_IMPL_1(_) PP_COUNT_IMPL_2 -#define PP_COUNT_IMPL_2(_) PP_COUNT_IMPL_3 -#define PP_COUNT_IMPL_3(_) PP_COUNT_IMPL_4 -#define PP_COUNT_IMPL_4(_) PP_COUNT_IMPL_5 -#define PP_COUNT_IMPL_5(_) PP_COUNT_IMPL_6 -#define PP_COUNT_IMPL_6(_) PP_COUNT_IMPL_7 -#define PP_COUNT_IMPL_7(_) PP_COUNT_IMPL_8 -#define PP_COUNT_IMPL_8(_) PP_COUNT_IMPL_9 -#define PP_COUNT_IMPL_9(_) PP_COUNT_IMPL_10 -#define PP_COUNT_IMPL_10(_) PP_COUNT_IMPL_11 -#define PP_COUNT_IMPL_11(_) PP_COUNT_IMPL_12 -#define PP_COUNT_IMPL_12(_) PP_COUNT_IMPL_13 -#define PP_COUNT_IMPL_13(_) PP_COUNT_IMPL_14 -#define PP_COUNT_IMPL_14(_) PP_COUNT_IMPL_15 -#define PP_COUNT_IMPL_15(_) PP_COUNT_IMPL_16 -#define PP_COUNT_IMPL_16(_) PP_COUNT_IMPL_17 -#define PP_COUNT_IMPL_17(_) PP_COUNT_IMPL_18 -#define PP_COUNT_IMPL_18(_) PP_COUNT_IMPL_19 -#define PP_COUNT_IMPL_19(_) PP_COUNT_IMPL_20 -#define PP_COUNT_IMPL_20(_) PP_COUNT_IMPL_21 -#define PP_COUNT_IMPL_21(_) PP_COUNT_IMPL_22 -#define PP_COUNT_IMPL_22(_) PP_COUNT_IMPL_23 -#define PP_COUNT_IMPL_23(_) PP_COUNT_IMPL_24 -#define PP_COUNT_IMPL_24(_) PP_COUNT_IMPL_25 -#define PP_COUNT_IMPL_25(_) PP_COUNT_IMPL_26 -#define PP_COUNT_IMPL_26(_) PP_COUNT_IMPL_27 -#define PP_COUNT_IMPL_27(_) PP_COUNT_IMPL_28 -#define PP_COUNT_IMPL_28(_) PP_COUNT_IMPL_29 -#define PP_COUNT_IMPL_29(_) PP_COUNT_IMPL_30 -#define PP_COUNT_IMPL_30(_) PP_COUNT_IMPL_31 -#define PP_COUNT_IMPL_31(_) PP_COUNT_IMPL_32 -#define PP_COUNT_IMPL_32(_) PP_COUNT_IMPL_33 -#define PP_COUNT_IMPL_33(_) PP_COUNT_IMPL_34 -#define PP_COUNT_IMPL_34(_) PP_COUNT_IMPL_35 -#define PP_COUNT_IMPL_35(_) PP_COUNT_IMPL_36 -#define PP_COUNT_IMPL_36(_) PP_COUNT_IMPL_37 -#define PP_COUNT_IMPL_37(_) PP_COUNT_IMPL_38 -#define PP_COUNT_IMPL_38(_) PP_COUNT_IMPL_39 -#define PP_COUNT_IMPL_39(_) PP_COUNT_IMPL_40 -#define PP_COUNT_IMPL_40(_) PP_COUNT_IMPL_41 -#define PP_COUNT_IMPL_41(_) PP_COUNT_IMPL_42 -#define PP_COUNT_IMPL_42(_) PP_COUNT_IMPL_43 -#define PP_COUNT_IMPL_43(_) PP_COUNT_IMPL_44 -#define PP_COUNT_IMPL_44(_) PP_COUNT_IMPL_45 -#define PP_COUNT_IMPL_45(_) PP_COUNT_IMPL_46 -#define PP_COUNT_IMPL_46(_) PP_COUNT_IMPL_47 -#define PP_COUNT_IMPL_47(_) PP_COUNT_IMPL_48 -#define PP_COUNT_IMPL_48(_) PP_COUNT_IMPL_49 -#define PP_COUNT_IMPL_49(_) PP_COUNT_IMPL_50 -#define PP_COUNT_IMPL_50(_) PP_COUNT_IMPL_51 -#define PP_COUNT_IMPL_51(_) PP_COUNT_IMPL_52 -#define PP_COUNT_IMPL_52(_) PP_COUNT_IMPL_53 -#define PP_COUNT_IMPL_53(_) PP_COUNT_IMPL_54 -#define PP_COUNT_IMPL_54(_) PP_COUNT_IMPL_55 -#define PP_COUNT_IMPL_55(_) PP_COUNT_IMPL_56 -#define PP_COUNT_IMPL_56(_) PP_COUNT_IMPL_57 -#define PP_COUNT_IMPL_57(_) PP_COUNT_IMPL_58 -#define PP_COUNT_IMPL_58(_) PP_COUNT_IMPL_59 -#define PP_COUNT_IMPL_59(_) PP_COUNT_IMPL_60 -#define PP_COUNT_IMPL_60(_) PP_COUNT_IMPL_61 -#define PP_COUNT_IMPL_61(_) PP_COUNT_IMPL_62 -#define PP_COUNT_IMPL_62(_) PP_COUNT_IMPL_63 -#define PP_COUNT_IMPL_63(_) PP_COUNT_IMPL_64 -#define PP_COUNT_IMPL_64(_) PP_COUNT_IMPL_65 -#define PP_COUNT_IMPL_65(_) PP_COUNT_IMPL_66 -#define PP_COUNT_IMPL_66(_) PP_COUNT_IMPL_67 -#define PP_COUNT_IMPL_67(_) PP_COUNT_IMPL_68 -#define PP_COUNT_IMPL_68(_) PP_COUNT_IMPL_69 -#define PP_COUNT_IMPL_69(_) PP_COUNT_IMPL_70 -#define PP_COUNT_IMPL_70(_) PP_COUNT_IMPL_71 -#define PP_COUNT_IMPL_71(_) PP_COUNT_IMPL_72 -#define PP_COUNT_IMPL_72(_) PP_COUNT_IMPL_73 -#define PP_COUNT_IMPL_73(_) PP_COUNT_IMPL_74 -#define PP_COUNT_IMPL_74(_) PP_COUNT_IMPL_75 -#define PP_COUNT_IMPL_75(_) PP_COUNT_IMPL_76 -#define PP_COUNT_IMPL_76(_) PP_COUNT_IMPL_77 -#define PP_COUNT_IMPL_77(_) PP_COUNT_IMPL_78 -#define PP_COUNT_IMPL_78(_) PP_COUNT_IMPL_79 -#define PP_COUNT_IMPL_79(_) PP_COUNT_IMPL_80 -#define PP_COUNT_IMPL_80(_) PP_COUNT_IMPL_81 -#define PP_COUNT_IMPL_81(_) PP_COUNT_IMPL_82 -#define PP_COUNT_IMPL_82(_) PP_COUNT_IMPL_83 -#define PP_COUNT_IMPL_83(_) PP_COUNT_IMPL_84 -#define PP_COUNT_IMPL_84(_) PP_COUNT_IMPL_85 -#define PP_COUNT_IMPL_85(_) PP_COUNT_IMPL_86 -#define PP_COUNT_IMPL_86(_) PP_COUNT_IMPL_87 -#define PP_COUNT_IMPL_87(_) PP_COUNT_IMPL_88 -#define PP_COUNT_IMPL_88(_) PP_COUNT_IMPL_89 -#define PP_COUNT_IMPL_89(_) PP_COUNT_IMPL_90 -#define PP_COUNT_IMPL_90(_) PP_COUNT_IMPL_91 -#define PP_COUNT_IMPL_91(_) PP_COUNT_IMPL_92 -#define PP_COUNT_IMPL_92(_) PP_COUNT_IMPL_93 -#define PP_COUNT_IMPL_93(_) PP_COUNT_IMPL_94 -#define PP_COUNT_IMPL_94(_) PP_COUNT_IMPL_95 -#define PP_COUNT_IMPL_95(_) PP_COUNT_IMPL_96 -#define PP_COUNT_IMPL_96(_) PP_COUNT_IMPL_97 -#define PP_COUNT_IMPL_97(_) PP_COUNT_IMPL_98 -#define PP_COUNT_IMPL_98(_) PP_COUNT_IMPL_99 -#define PP_COUNT_IMPL_99(_) PP_COUNT_IMPL_100 -#define PP_COUNT_IMPL_100(_) PP_COUNT_IMPL_101 -#define PP_COUNT_IMPL_101(_) PP_COUNT_IMPL_102 -#define PP_COUNT_IMPL_102(_) PP_COUNT_IMPL_103 -#define PP_COUNT_IMPL_103(_) PP_COUNT_IMPL_104 -#define PP_COUNT_IMPL_104(_) PP_COUNT_IMPL_105 -#define PP_COUNT_IMPL_105(_) PP_COUNT_IMPL_106 -#define PP_COUNT_IMPL_106(_) PP_COUNT_IMPL_107 -#define PP_COUNT_IMPL_107(_) PP_COUNT_IMPL_108 -#define PP_COUNT_IMPL_108(_) PP_COUNT_IMPL_109 -#define PP_COUNT_IMPL_109(_) PP_COUNT_IMPL_110 -#define PP_COUNT_IMPL_110(_) PP_COUNT_IMPL_111 -#define PP_COUNT_IMPL_111(_) PP_COUNT_IMPL_112 -#define PP_COUNT_IMPL_112(_) PP_COUNT_IMPL_113 -#define PP_COUNT_IMPL_113(_) PP_COUNT_IMPL_114 -#define PP_COUNT_IMPL_114(_) PP_COUNT_IMPL_115 -#define PP_COUNT_IMPL_115(_) PP_COUNT_IMPL_116 -#define PP_COUNT_IMPL_116(_) PP_COUNT_IMPL_117 -#define PP_COUNT_IMPL_117(_) PP_COUNT_IMPL_118 -#define PP_COUNT_IMPL_118(_) PP_COUNT_IMPL_119 -#define PP_COUNT_IMPL_119(_) PP_COUNT_IMPL_120 -#define PP_COUNT_IMPL_120(_) PP_COUNT_IMPL_121 -#define PP_COUNT_IMPL_121(_) PP_COUNT_IMPL_122 -#define PP_COUNT_IMPL_122(_) PP_COUNT_IMPL_123 -#define PP_COUNT_IMPL_123(_) PP_COUNT_IMPL_124 -#define PP_COUNT_IMPL_124(_) PP_COUNT_IMPL_125 -#define PP_COUNT_IMPL_125(_) PP_COUNT_IMPL_126 -#define PP_COUNT_IMPL_126(_) PP_COUNT_IMPL_127 -#define PP_COUNT_IMPL_127(_) PP_COUNT_IMPL_128 -#define PP_COUNT_IMPL_128(_) PP_COUNT_IMPL_129 -#define PP_COUNT_IMPL_129(_) PP_COUNT_IMPL_130 -#define PP_COUNT_IMPL_130(_) PP_COUNT_IMPL_131 -#define PP_COUNT_IMPL_131(_) PP_COUNT_IMPL_132 -#define PP_COUNT_IMPL_132(_) PP_COUNT_IMPL_133 -#define PP_COUNT_IMPL_133(_) PP_COUNT_IMPL_134 -#define PP_COUNT_IMPL_134(_) PP_COUNT_IMPL_135 -#define PP_COUNT_IMPL_135(_) PP_COUNT_IMPL_136 -#define PP_COUNT_IMPL_136(_) PP_COUNT_IMPL_137 -#define PP_COUNT_IMPL_137(_) PP_COUNT_IMPL_138 -#define PP_COUNT_IMPL_138(_) PP_COUNT_IMPL_139 -#define PP_COUNT_IMPL_139(_) PP_COUNT_IMPL_140 -#define PP_COUNT_IMPL_140(_) PP_COUNT_IMPL_141 -#define PP_COUNT_IMPL_141(_) PP_COUNT_IMPL_142 -#define PP_COUNT_IMPL_142(_) PP_COUNT_IMPL_143 -#define PP_COUNT_IMPL_143(_) PP_COUNT_IMPL_144 -#define PP_COUNT_IMPL_144(_) PP_COUNT_IMPL_145 -#define PP_COUNT_IMPL_145(_) PP_COUNT_IMPL_146 -#define PP_COUNT_IMPL_146(_) PP_COUNT_IMPL_147 -#define PP_COUNT_IMPL_147(_) PP_COUNT_IMPL_148 -#define PP_COUNT_IMPL_148(_) PP_COUNT_IMPL_149 -#define PP_COUNT_IMPL_149(_) PP_COUNT_IMPL_150 -#define PP_COUNT_IMPL_150(_) PP_COUNT_IMPL_151 -#define PP_COUNT_IMPL_151(_) PP_COUNT_IMPL_152 -#define PP_COUNT_IMPL_152(_) PP_COUNT_IMPL_153 -#define PP_COUNT_IMPL_153(_) PP_COUNT_IMPL_154 -#define PP_COUNT_IMPL_154(_) PP_COUNT_IMPL_155 -#define PP_COUNT_IMPL_155(_) PP_COUNT_IMPL_156 -#define PP_COUNT_IMPL_156(_) PP_COUNT_IMPL_157 -#define PP_COUNT_IMPL_157(_) PP_COUNT_IMPL_158 -#define PP_COUNT_IMPL_158(_) PP_COUNT_IMPL_159 -#define PP_COUNT_IMPL_159(_) PP_COUNT_IMPL_160 -#define PP_COUNT_IMPL_160(_) PP_COUNT_IMPL_161 -#define PP_COUNT_IMPL_161(_) PP_COUNT_IMPL_162 -#define PP_COUNT_IMPL_162(_) PP_COUNT_IMPL_163 -#define PP_COUNT_IMPL_163(_) PP_COUNT_IMPL_164 -#define PP_COUNT_IMPL_164(_) PP_COUNT_IMPL_165 -#define PP_COUNT_IMPL_165(_) PP_COUNT_IMPL_166 -#define PP_COUNT_IMPL_166(_) PP_COUNT_IMPL_167 -#define PP_COUNT_IMPL_167(_) PP_COUNT_IMPL_168 -#define PP_COUNT_IMPL_168(_) PP_COUNT_IMPL_169 -#define PP_COUNT_IMPL_169(_) PP_COUNT_IMPL_170 -#define PP_COUNT_IMPL_170(_) PP_COUNT_IMPL_171 -#define PP_COUNT_IMPL_171(_) PP_COUNT_IMPL_172 -#define PP_COUNT_IMPL_172(_) PP_COUNT_IMPL_173 -#define PP_COUNT_IMPL_173(_) PP_COUNT_IMPL_174 -#define PP_COUNT_IMPL_174(_) PP_COUNT_IMPL_175 -#define PP_COUNT_IMPL_175(_) PP_COUNT_IMPL_176 -#define PP_COUNT_IMPL_176(_) PP_COUNT_IMPL_177 -#define PP_COUNT_IMPL_177(_) PP_COUNT_IMPL_178 -#define PP_COUNT_IMPL_178(_) PP_COUNT_IMPL_179 -#define PP_COUNT_IMPL_179(_) PP_COUNT_IMPL_180 -#define PP_COUNT_IMPL_180(_) PP_COUNT_IMPL_181 -#define PP_COUNT_IMPL_181(_) PP_COUNT_IMPL_182 -#define PP_COUNT_IMPL_182(_) PP_COUNT_IMPL_183 -#define PP_COUNT_IMPL_183(_) PP_COUNT_IMPL_184 -#define PP_COUNT_IMPL_184(_) PP_COUNT_IMPL_185 -#define PP_COUNT_IMPL_185(_) PP_COUNT_IMPL_186 -#define PP_COUNT_IMPL_186(_) PP_COUNT_IMPL_187 -#define PP_COUNT_IMPL_187(_) PP_COUNT_IMPL_188 -#define PP_COUNT_IMPL_188(_) PP_COUNT_IMPL_189 -#define PP_COUNT_IMPL_189(_) PP_COUNT_IMPL_190 -#define PP_COUNT_IMPL_190(_) PP_COUNT_IMPL_191 -#define PP_COUNT_IMPL_191(_) PP_COUNT_IMPL_192 -#define PP_COUNT_IMPL_192(_) PP_COUNT_IMPL_193 -#define PP_COUNT_IMPL_193(_) PP_COUNT_IMPL_194 -#define PP_COUNT_IMPL_194(_) PP_COUNT_IMPL_195 -#define PP_COUNT_IMPL_195(_) PP_COUNT_IMPL_196 -#define PP_COUNT_IMPL_196(_) PP_COUNT_IMPL_197 -#define PP_COUNT_IMPL_197(_) PP_COUNT_IMPL_198 -#define PP_COUNT_IMPL_198(_) PP_COUNT_IMPL_199 -#define PP_COUNT_IMPL_199(_) PP_COUNT_IMPL_200 - -//////////////////////////////////////////////////////////////////////////////// -#define PP_KILL_IMPL(seq, index) PP_CONCAT(PP_KILL_IMPL_, index) seq -#define PP_KILL_IMPL_0 -#define PP_KILL_IMPL_1(_) PP_KILL_IMPL_0 -#define PP_KILL_IMPL_2(_) PP_KILL_IMPL_1 -#define PP_KILL_IMPL_3(_) PP_KILL_IMPL_2 -#define PP_KILL_IMPL_4(_) PP_KILL_IMPL_3 -#define PP_KILL_IMPL_5(_) PP_KILL_IMPL_4 -#define PP_KILL_IMPL_6(_) PP_KILL_IMPL_5 -#define PP_KILL_IMPL_7(_) PP_KILL_IMPL_6 -#define PP_KILL_IMPL_8(_) PP_KILL_IMPL_7 -#define PP_KILL_IMPL_9(_) PP_KILL_IMPL_8 -#define PP_KILL_IMPL_10(_) PP_KILL_IMPL_9 -#define PP_KILL_IMPL_11(_) PP_KILL_IMPL_10 -#define PP_KILL_IMPL_12(_) PP_KILL_IMPL_11 -#define PP_KILL_IMPL_13(_) PP_KILL_IMPL_12 -#define PP_KILL_IMPL_14(_) PP_KILL_IMPL_13 -#define PP_KILL_IMPL_15(_) PP_KILL_IMPL_14 -#define PP_KILL_IMPL_16(_) PP_KILL_IMPL_15 -#define PP_KILL_IMPL_17(_) PP_KILL_IMPL_16 -#define PP_KILL_IMPL_18(_) PP_KILL_IMPL_17 -#define PP_KILL_IMPL_19(_) PP_KILL_IMPL_18 -#define PP_KILL_IMPL_20(_) PP_KILL_IMPL_19 -#define PP_KILL_IMPL_21(_) PP_KILL_IMPL_20 -#define PP_KILL_IMPL_22(_) PP_KILL_IMPL_21 -#define PP_KILL_IMPL_23(_) PP_KILL_IMPL_22 -#define PP_KILL_IMPL_24(_) PP_KILL_IMPL_23 -#define PP_KILL_IMPL_25(_) PP_KILL_IMPL_24 -#define PP_KILL_IMPL_26(_) PP_KILL_IMPL_25 -#define PP_KILL_IMPL_27(_) PP_KILL_IMPL_26 -#define PP_KILL_IMPL_28(_) PP_KILL_IMPL_27 -#define PP_KILL_IMPL_29(_) PP_KILL_IMPL_28 -#define PP_KILL_IMPL_30(_) PP_KILL_IMPL_29 -#define PP_KILL_IMPL_31(_) PP_KILL_IMPL_30 -#define PP_KILL_IMPL_32(_) PP_KILL_IMPL_31 -#define PP_KILL_IMPL_33(_) PP_KILL_IMPL_32 -#define PP_KILL_IMPL_34(_) PP_KILL_IMPL_33 -#define PP_KILL_IMPL_35(_) PP_KILL_IMPL_34 -#define PP_KILL_IMPL_36(_) PP_KILL_IMPL_35 -#define PP_KILL_IMPL_37(_) PP_KILL_IMPL_36 -#define PP_KILL_IMPL_38(_) PP_KILL_IMPL_37 -#define PP_KILL_IMPL_39(_) PP_KILL_IMPL_38 -#define PP_KILL_IMPL_40(_) PP_KILL_IMPL_39 -#define PP_KILL_IMPL_41(_) PP_KILL_IMPL_40 -#define PP_KILL_IMPL_42(_) PP_KILL_IMPL_41 -#define PP_KILL_IMPL_43(_) PP_KILL_IMPL_42 -#define PP_KILL_IMPL_44(_) PP_KILL_IMPL_43 -#define PP_KILL_IMPL_45(_) PP_KILL_IMPL_44 -#define PP_KILL_IMPL_46(_) PP_KILL_IMPL_45 -#define PP_KILL_IMPL_47(_) PP_KILL_IMPL_46 -#define PP_KILL_IMPL_48(_) PP_KILL_IMPL_47 -#define PP_KILL_IMPL_49(_) PP_KILL_IMPL_48 -#define PP_KILL_IMPL_50(_) PP_KILL_IMPL_49 -#define PP_KILL_IMPL_51(_) PP_KILL_IMPL_50 -#define PP_KILL_IMPL_52(_) PP_KILL_IMPL_51 -#define PP_KILL_IMPL_53(_) PP_KILL_IMPL_52 -#define PP_KILL_IMPL_54(_) PP_KILL_IMPL_53 -#define PP_KILL_IMPL_55(_) PP_KILL_IMPL_54 -#define PP_KILL_IMPL_56(_) PP_KILL_IMPL_55 -#define PP_KILL_IMPL_57(_) PP_KILL_IMPL_56 -#define PP_KILL_IMPL_58(_) PP_KILL_IMPL_57 -#define PP_KILL_IMPL_59(_) PP_KILL_IMPL_58 -#define PP_KILL_IMPL_60(_) PP_KILL_IMPL_59 -#define PP_KILL_IMPL_61(_) PP_KILL_IMPL_60 -#define PP_KILL_IMPL_62(_) PP_KILL_IMPL_61 -#define PP_KILL_IMPL_63(_) PP_KILL_IMPL_62 -#define PP_KILL_IMPL_64(_) PP_KILL_IMPL_63 -#define PP_KILL_IMPL_65(_) PP_KILL_IMPL_64 -#define PP_KILL_IMPL_66(_) PP_KILL_IMPL_65 -#define PP_KILL_IMPL_67(_) PP_KILL_IMPL_66 -#define PP_KILL_IMPL_68(_) PP_KILL_IMPL_67 -#define PP_KILL_IMPL_69(_) PP_KILL_IMPL_68 -#define PP_KILL_IMPL_70(_) PP_KILL_IMPL_69 -#define PP_KILL_IMPL_71(_) PP_KILL_IMPL_70 -#define PP_KILL_IMPL_72(_) PP_KILL_IMPL_71 -#define PP_KILL_IMPL_73(_) PP_KILL_IMPL_72 -#define PP_KILL_IMPL_74(_) PP_KILL_IMPL_73 -#define PP_KILL_IMPL_75(_) PP_KILL_IMPL_74 -#define PP_KILL_IMPL_76(_) PP_KILL_IMPL_75 -#define PP_KILL_IMPL_77(_) PP_KILL_IMPL_76 -#define PP_KILL_IMPL_78(_) PP_KILL_IMPL_77 -#define PP_KILL_IMPL_79(_) PP_KILL_IMPL_78 -#define PP_KILL_IMPL_80(_) PP_KILL_IMPL_79 -#define PP_KILL_IMPL_81(_) PP_KILL_IMPL_80 -#define PP_KILL_IMPL_82(_) PP_KILL_IMPL_81 -#define PP_KILL_IMPL_83(_) PP_KILL_IMPL_82 -#define PP_KILL_IMPL_84(_) PP_KILL_IMPL_83 -#define PP_KILL_IMPL_85(_) PP_KILL_IMPL_84 -#define PP_KILL_IMPL_86(_) PP_KILL_IMPL_85 -#define PP_KILL_IMPL_87(_) PP_KILL_IMPL_86 -#define PP_KILL_IMPL_88(_) PP_KILL_IMPL_87 -#define PP_KILL_IMPL_89(_) PP_KILL_IMPL_88 -#define PP_KILL_IMPL_90(_) PP_KILL_IMPL_89 -#define PP_KILL_IMPL_91(_) PP_KILL_IMPL_90 -#define PP_KILL_IMPL_92(_) PP_KILL_IMPL_91 -#define PP_KILL_IMPL_93(_) PP_KILL_IMPL_92 -#define PP_KILL_IMPL_94(_) PP_KILL_IMPL_93 -#define PP_KILL_IMPL_95(_) PP_KILL_IMPL_94 -#define PP_KILL_IMPL_96(_) PP_KILL_IMPL_95 -#define PP_KILL_IMPL_97(_) PP_KILL_IMPL_96 -#define PP_KILL_IMPL_98(_) PP_KILL_IMPL_97 -#define PP_KILL_IMPL_99(_) PP_KILL_IMPL_98 -#define PP_KILL_IMPL_100(_) PP_KILL_IMPL_99 -#define PP_KILL_IMPL_101(_) PP_KILL_IMPL_100 -#define PP_KILL_IMPL_102(_) PP_KILL_IMPL_101 -#define PP_KILL_IMPL_103(_) PP_KILL_IMPL_102 -#define PP_KILL_IMPL_104(_) PP_KILL_IMPL_103 -#define PP_KILL_IMPL_105(_) PP_KILL_IMPL_104 -#define PP_KILL_IMPL_106(_) PP_KILL_IMPL_105 -#define PP_KILL_IMPL_107(_) PP_KILL_IMPL_106 -#define PP_KILL_IMPL_108(_) PP_KILL_IMPL_107 -#define PP_KILL_IMPL_109(_) PP_KILL_IMPL_108 -#define PP_KILL_IMPL_110(_) PP_KILL_IMPL_109 -#define PP_KILL_IMPL_111(_) PP_KILL_IMPL_110 -#define PP_KILL_IMPL_112(_) PP_KILL_IMPL_111 -#define PP_KILL_IMPL_113(_) PP_KILL_IMPL_112 -#define PP_KILL_IMPL_114(_) PP_KILL_IMPL_113 -#define PP_KILL_IMPL_115(_) PP_KILL_IMPL_114 -#define PP_KILL_IMPL_116(_) PP_KILL_IMPL_115 -#define PP_KILL_IMPL_117(_) PP_KILL_IMPL_116 -#define PP_KILL_IMPL_118(_) PP_KILL_IMPL_117 -#define PP_KILL_IMPL_119(_) PP_KILL_IMPL_118 -#define PP_KILL_IMPL_120(_) PP_KILL_IMPL_119 -#define PP_KILL_IMPL_121(_) PP_KILL_IMPL_120 -#define PP_KILL_IMPL_122(_) PP_KILL_IMPL_121 -#define PP_KILL_IMPL_123(_) PP_KILL_IMPL_122 -#define PP_KILL_IMPL_124(_) PP_KILL_IMPL_123 -#define PP_KILL_IMPL_125(_) PP_KILL_IMPL_124 -#define PP_KILL_IMPL_126(_) PP_KILL_IMPL_125 -#define PP_KILL_IMPL_127(_) PP_KILL_IMPL_126 -#define PP_KILL_IMPL_128(_) PP_KILL_IMPL_127 -#define PP_KILL_IMPL_129(_) PP_KILL_IMPL_128 -#define PP_KILL_IMPL_130(_) PP_KILL_IMPL_129 -#define PP_KILL_IMPL_131(_) PP_KILL_IMPL_130 -#define PP_KILL_IMPL_132(_) PP_KILL_IMPL_131 -#define PP_KILL_IMPL_133(_) PP_KILL_IMPL_132 -#define PP_KILL_IMPL_134(_) PP_KILL_IMPL_133 -#define PP_KILL_IMPL_135(_) PP_KILL_IMPL_134 -#define PP_KILL_IMPL_136(_) PP_KILL_IMPL_135 -#define PP_KILL_IMPL_137(_) PP_KILL_IMPL_136 -#define PP_KILL_IMPL_138(_) PP_KILL_IMPL_137 -#define PP_KILL_IMPL_139(_) PP_KILL_IMPL_138 -#define PP_KILL_IMPL_140(_) PP_KILL_IMPL_139 -#define PP_KILL_IMPL_141(_) PP_KILL_IMPL_140 -#define PP_KILL_IMPL_142(_) PP_KILL_IMPL_141 -#define PP_KILL_IMPL_143(_) PP_KILL_IMPL_142 -#define PP_KILL_IMPL_144(_) PP_KILL_IMPL_143 -#define PP_KILL_IMPL_145(_) PP_KILL_IMPL_144 -#define PP_KILL_IMPL_146(_) PP_KILL_IMPL_145 -#define PP_KILL_IMPL_147(_) PP_KILL_IMPL_146 -#define PP_KILL_IMPL_148(_) PP_KILL_IMPL_147 -#define PP_KILL_IMPL_149(_) PP_KILL_IMPL_148 -#define PP_KILL_IMPL_150(_) PP_KILL_IMPL_149 -#define PP_KILL_IMPL_151(_) PP_KILL_IMPL_150 -#define PP_KILL_IMPL_152(_) PP_KILL_IMPL_151 -#define PP_KILL_IMPL_153(_) PP_KILL_IMPL_152 -#define PP_KILL_IMPL_154(_) PP_KILL_IMPL_153 -#define PP_KILL_IMPL_155(_) PP_KILL_IMPL_154 -#define PP_KILL_IMPL_156(_) PP_KILL_IMPL_155 -#define PP_KILL_IMPL_157(_) PP_KILL_IMPL_156 -#define PP_KILL_IMPL_158(_) PP_KILL_IMPL_157 -#define PP_KILL_IMPL_159(_) PP_KILL_IMPL_158 -#define PP_KILL_IMPL_160(_) PP_KILL_IMPL_159 -#define PP_KILL_IMPL_161(_) PP_KILL_IMPL_160 -#define PP_KILL_IMPL_162(_) PP_KILL_IMPL_161 -#define PP_KILL_IMPL_163(_) PP_KILL_IMPL_162 -#define PP_KILL_IMPL_164(_) PP_KILL_IMPL_163 -#define PP_KILL_IMPL_165(_) PP_KILL_IMPL_164 -#define PP_KILL_IMPL_166(_) PP_KILL_IMPL_165 -#define PP_KILL_IMPL_167(_) PP_KILL_IMPL_166 -#define PP_KILL_IMPL_168(_) PP_KILL_IMPL_167 -#define PP_KILL_IMPL_169(_) PP_KILL_IMPL_168 -#define PP_KILL_IMPL_170(_) PP_KILL_IMPL_169 -#define PP_KILL_IMPL_171(_) PP_KILL_IMPL_170 -#define PP_KILL_IMPL_172(_) PP_KILL_IMPL_171 -#define PP_KILL_IMPL_173(_) PP_KILL_IMPL_172 -#define PP_KILL_IMPL_174(_) PP_KILL_IMPL_173 -#define PP_KILL_IMPL_175(_) PP_KILL_IMPL_174 -#define PP_KILL_IMPL_176(_) PP_KILL_IMPL_175 -#define PP_KILL_IMPL_177(_) PP_KILL_IMPL_176 -#define PP_KILL_IMPL_178(_) PP_KILL_IMPL_177 -#define PP_KILL_IMPL_179(_) PP_KILL_IMPL_178 -#define PP_KILL_IMPL_180(_) PP_KILL_IMPL_179 -#define PP_KILL_IMPL_181(_) PP_KILL_IMPL_180 -#define PP_KILL_IMPL_182(_) PP_KILL_IMPL_181 -#define PP_KILL_IMPL_183(_) PP_KILL_IMPL_182 -#define PP_KILL_IMPL_184(_) PP_KILL_IMPL_183 -#define PP_KILL_IMPL_185(_) PP_KILL_IMPL_184 -#define PP_KILL_IMPL_186(_) PP_KILL_IMPL_185 -#define PP_KILL_IMPL_187(_) PP_KILL_IMPL_186 -#define PP_KILL_IMPL_188(_) PP_KILL_IMPL_187 -#define PP_KILL_IMPL_189(_) PP_KILL_IMPL_188 -#define PP_KILL_IMPL_190(_) PP_KILL_IMPL_189 -#define PP_KILL_IMPL_191(_) PP_KILL_IMPL_190 -#define PP_KILL_IMPL_192(_) PP_KILL_IMPL_191 -#define PP_KILL_IMPL_193(_) PP_KILL_IMPL_192 -#define PP_KILL_IMPL_194(_) PP_KILL_IMPL_193 -#define PP_KILL_IMPL_195(_) PP_KILL_IMPL_194 -#define PP_KILL_IMPL_196(_) PP_KILL_IMPL_195 -#define PP_KILL_IMPL_197(_) PP_KILL_IMPL_196 -#define PP_KILL_IMPL_198(_) PP_KILL_IMPL_197 -#define PP_KILL_IMPL_199(_) PP_KILL_IMPL_198 -#define PP_KILL_IMPL_200(_) PP_KILL_IMPL_199 - -//////////////////////////////////////////////////////////////////////////////// -#define PP_ELEMENT_IMPL(seq, \ - index) PP_ELEMENT_IMPL_A((PP_CONCAT(PP_ELEMENT_IMPL_, index) seq)) -#define PP_ELEMENT_IMPL_A(x) PP_ELEMENT_IMPL_C(PP_ELEMENT_IMPL_B x) -#define PP_ELEMENT_IMPL_B(x, _) x -#define PP_ELEMENT_IMPL_C(x) x -#define PP_ELEMENT_IMPL_0(x) x, PP_NIL -#define PP_ELEMENT_IMPL_1(_) PP_ELEMENT_IMPL_0 -#define PP_ELEMENT_IMPL_2(_) PP_ELEMENT_IMPL_1 -#define PP_ELEMENT_IMPL_3(_) PP_ELEMENT_IMPL_2 -#define PP_ELEMENT_IMPL_4(_) PP_ELEMENT_IMPL_3 -#define PP_ELEMENT_IMPL_5(_) PP_ELEMENT_IMPL_4 -#define PP_ELEMENT_IMPL_6(_) PP_ELEMENT_IMPL_5 -#define PP_ELEMENT_IMPL_7(_) PP_ELEMENT_IMPL_6 -#define PP_ELEMENT_IMPL_8(_) PP_ELEMENT_IMPL_7 -#define PP_ELEMENT_IMPL_9(_) PP_ELEMENT_IMPL_8 -#define PP_ELEMENT_IMPL_10(_) PP_ELEMENT_IMPL_9 -#define PP_ELEMENT_IMPL_11(_) PP_ELEMENT_IMPL_10 -#define PP_ELEMENT_IMPL_12(_) PP_ELEMENT_IMPL_11 -#define PP_ELEMENT_IMPL_13(_) PP_ELEMENT_IMPL_12 -#define PP_ELEMENT_IMPL_14(_) PP_ELEMENT_IMPL_13 -#define PP_ELEMENT_IMPL_15(_) PP_ELEMENT_IMPL_14 -#define PP_ELEMENT_IMPL_16(_) PP_ELEMENT_IMPL_15 -#define PP_ELEMENT_IMPL_17(_) PP_ELEMENT_IMPL_16 -#define PP_ELEMENT_IMPL_18(_) PP_ELEMENT_IMPL_17 -#define PP_ELEMENT_IMPL_19(_) PP_ELEMENT_IMPL_18 -#define PP_ELEMENT_IMPL_20(_) PP_ELEMENT_IMPL_19 -#define PP_ELEMENT_IMPL_21(_) PP_ELEMENT_IMPL_20 -#define PP_ELEMENT_IMPL_22(_) PP_ELEMENT_IMPL_21 -#define PP_ELEMENT_IMPL_23(_) PP_ELEMENT_IMPL_22 -#define PP_ELEMENT_IMPL_24(_) PP_ELEMENT_IMPL_23 -#define PP_ELEMENT_IMPL_25(_) PP_ELEMENT_IMPL_24 -#define PP_ELEMENT_IMPL_26(_) PP_ELEMENT_IMPL_25 -#define PP_ELEMENT_IMPL_27(_) PP_ELEMENT_IMPL_26 -#define PP_ELEMENT_IMPL_28(_) PP_ELEMENT_IMPL_27 -#define PP_ELEMENT_IMPL_29(_) PP_ELEMENT_IMPL_28 -#define PP_ELEMENT_IMPL_30(_) PP_ELEMENT_IMPL_29 -#define PP_ELEMENT_IMPL_31(_) PP_ELEMENT_IMPL_30 -#define PP_ELEMENT_IMPL_32(_) PP_ELEMENT_IMPL_31 -#define PP_ELEMENT_IMPL_33(_) PP_ELEMENT_IMPL_32 -#define PP_ELEMENT_IMPL_34(_) PP_ELEMENT_IMPL_33 -#define PP_ELEMENT_IMPL_35(_) PP_ELEMENT_IMPL_34 -#define PP_ELEMENT_IMPL_36(_) PP_ELEMENT_IMPL_35 -#define PP_ELEMENT_IMPL_37(_) PP_ELEMENT_IMPL_36 -#define PP_ELEMENT_IMPL_38(_) PP_ELEMENT_IMPL_37 -#define PP_ELEMENT_IMPL_39(_) PP_ELEMENT_IMPL_38 -#define PP_ELEMENT_IMPL_40(_) PP_ELEMENT_IMPL_39 -#define PP_ELEMENT_IMPL_41(_) PP_ELEMENT_IMPL_40 -#define PP_ELEMENT_IMPL_42(_) PP_ELEMENT_IMPL_41 -#define PP_ELEMENT_IMPL_43(_) PP_ELEMENT_IMPL_42 -#define PP_ELEMENT_IMPL_44(_) PP_ELEMENT_IMPL_43 -#define PP_ELEMENT_IMPL_45(_) PP_ELEMENT_IMPL_44 -#define PP_ELEMENT_IMPL_46(_) PP_ELEMENT_IMPL_45 -#define PP_ELEMENT_IMPL_47(_) PP_ELEMENT_IMPL_46 -#define PP_ELEMENT_IMPL_48(_) PP_ELEMENT_IMPL_47 -#define PP_ELEMENT_IMPL_49(_) PP_ELEMENT_IMPL_48 -#define PP_ELEMENT_IMPL_50(_) PP_ELEMENT_IMPL_49 -#define PP_ELEMENT_IMPL_51(_) PP_ELEMENT_IMPL_50 -#define PP_ELEMENT_IMPL_52(_) PP_ELEMENT_IMPL_51 -#define PP_ELEMENT_IMPL_53(_) PP_ELEMENT_IMPL_52 -#define PP_ELEMENT_IMPL_54(_) PP_ELEMENT_IMPL_53 -#define PP_ELEMENT_IMPL_55(_) PP_ELEMENT_IMPL_54 -#define PP_ELEMENT_IMPL_56(_) PP_ELEMENT_IMPL_55 -#define PP_ELEMENT_IMPL_57(_) PP_ELEMENT_IMPL_56 -#define PP_ELEMENT_IMPL_58(_) PP_ELEMENT_IMPL_57 -#define PP_ELEMENT_IMPL_59(_) PP_ELEMENT_IMPL_58 -#define PP_ELEMENT_IMPL_60(_) PP_ELEMENT_IMPL_59 -#define PP_ELEMENT_IMPL_61(_) PP_ELEMENT_IMPL_60 -#define PP_ELEMENT_IMPL_62(_) PP_ELEMENT_IMPL_61 -#define PP_ELEMENT_IMPL_63(_) PP_ELEMENT_IMPL_62 -#define PP_ELEMENT_IMPL_64(_) PP_ELEMENT_IMPL_63 -#define PP_ELEMENT_IMPL_65(_) PP_ELEMENT_IMPL_64 -#define PP_ELEMENT_IMPL_66(_) PP_ELEMENT_IMPL_65 -#define PP_ELEMENT_IMPL_67(_) PP_ELEMENT_IMPL_66 -#define PP_ELEMENT_IMPL_68(_) PP_ELEMENT_IMPL_67 -#define PP_ELEMENT_IMPL_69(_) PP_ELEMENT_IMPL_68 -#define PP_ELEMENT_IMPL_70(_) PP_ELEMENT_IMPL_69 -#define PP_ELEMENT_IMPL_71(_) PP_ELEMENT_IMPL_70 -#define PP_ELEMENT_IMPL_72(_) PP_ELEMENT_IMPL_71 -#define PP_ELEMENT_IMPL_73(_) PP_ELEMENT_IMPL_72 -#define PP_ELEMENT_IMPL_74(_) PP_ELEMENT_IMPL_73 -#define PP_ELEMENT_IMPL_75(_) PP_ELEMENT_IMPL_74 -#define PP_ELEMENT_IMPL_76(_) PP_ELEMENT_IMPL_75 -#define PP_ELEMENT_IMPL_77(_) PP_ELEMENT_IMPL_76 -#define PP_ELEMENT_IMPL_78(_) PP_ELEMENT_IMPL_77 -#define PP_ELEMENT_IMPL_79(_) PP_ELEMENT_IMPL_78 -#define PP_ELEMENT_IMPL_80(_) PP_ELEMENT_IMPL_79 -#define PP_ELEMENT_IMPL_81(_) PP_ELEMENT_IMPL_80 -#define PP_ELEMENT_IMPL_82(_) PP_ELEMENT_IMPL_81 -#define PP_ELEMENT_IMPL_83(_) PP_ELEMENT_IMPL_82 -#define PP_ELEMENT_IMPL_84(_) PP_ELEMENT_IMPL_83 -#define PP_ELEMENT_IMPL_85(_) PP_ELEMENT_IMPL_84 -#define PP_ELEMENT_IMPL_86(_) PP_ELEMENT_IMPL_85 -#define PP_ELEMENT_IMPL_87(_) PP_ELEMENT_IMPL_86 -#define PP_ELEMENT_IMPL_88(_) PP_ELEMENT_IMPL_87 -#define PP_ELEMENT_IMPL_89(_) PP_ELEMENT_IMPL_88 -#define PP_ELEMENT_IMPL_90(_) PP_ELEMENT_IMPL_89 -#define PP_ELEMENT_IMPL_91(_) PP_ELEMENT_IMPL_90 -#define PP_ELEMENT_IMPL_92(_) PP_ELEMENT_IMPL_91 -#define PP_ELEMENT_IMPL_93(_) PP_ELEMENT_IMPL_92 -#define PP_ELEMENT_IMPL_94(_) PP_ELEMENT_IMPL_93 -#define PP_ELEMENT_IMPL_95(_) PP_ELEMENT_IMPL_94 -#define PP_ELEMENT_IMPL_96(_) PP_ELEMENT_IMPL_95 -#define PP_ELEMENT_IMPL_97(_) PP_ELEMENT_IMPL_96 -#define PP_ELEMENT_IMPL_98(_) PP_ELEMENT_IMPL_97 -#define PP_ELEMENT_IMPL_99(_) PP_ELEMENT_IMPL_98 -#define PP_ELEMENT_IMPL_100(_) PP_ELEMENT_IMPL_99 -#define PP_ELEMENT_IMPL_101(_) PP_ELEMENT_IMPL_100 -#define PP_ELEMENT_IMPL_102(_) PP_ELEMENT_IMPL_101 -#define PP_ELEMENT_IMPL_103(_) PP_ELEMENT_IMPL_102 -#define PP_ELEMENT_IMPL_104(_) PP_ELEMENT_IMPL_103 -#define PP_ELEMENT_IMPL_105(_) PP_ELEMENT_IMPL_104 -#define PP_ELEMENT_IMPL_106(_) PP_ELEMENT_IMPL_105 -#define PP_ELEMENT_IMPL_107(_) PP_ELEMENT_IMPL_106 -#define PP_ELEMENT_IMPL_108(_) PP_ELEMENT_IMPL_107 -#define PP_ELEMENT_IMPL_109(_) PP_ELEMENT_IMPL_108 -#define PP_ELEMENT_IMPL_110(_) PP_ELEMENT_IMPL_109 -#define PP_ELEMENT_IMPL_111(_) PP_ELEMENT_IMPL_110 -#define PP_ELEMENT_IMPL_112(_) PP_ELEMENT_IMPL_111 -#define PP_ELEMENT_IMPL_113(_) PP_ELEMENT_IMPL_112 -#define PP_ELEMENT_IMPL_114(_) PP_ELEMENT_IMPL_113 -#define PP_ELEMENT_IMPL_115(_) PP_ELEMENT_IMPL_114 -#define PP_ELEMENT_IMPL_116(_) PP_ELEMENT_IMPL_115 -#define PP_ELEMENT_IMPL_117(_) PP_ELEMENT_IMPL_116 -#define PP_ELEMENT_IMPL_118(_) PP_ELEMENT_IMPL_117 -#define PP_ELEMENT_IMPL_119(_) PP_ELEMENT_IMPL_118 -#define PP_ELEMENT_IMPL_120(_) PP_ELEMENT_IMPL_119 -#define PP_ELEMENT_IMPL_121(_) PP_ELEMENT_IMPL_120 -#define PP_ELEMENT_IMPL_122(_) PP_ELEMENT_IMPL_121 -#define PP_ELEMENT_IMPL_123(_) PP_ELEMENT_IMPL_122 -#define PP_ELEMENT_IMPL_124(_) PP_ELEMENT_IMPL_123 -#define PP_ELEMENT_IMPL_125(_) PP_ELEMENT_IMPL_124 -#define PP_ELEMENT_IMPL_126(_) PP_ELEMENT_IMPL_125 -#define PP_ELEMENT_IMPL_127(_) PP_ELEMENT_IMPL_126 -#define PP_ELEMENT_IMPL_128(_) PP_ELEMENT_IMPL_127 -#define PP_ELEMENT_IMPL_129(_) PP_ELEMENT_IMPL_128 -#define PP_ELEMENT_IMPL_130(_) PP_ELEMENT_IMPL_129 -#define PP_ELEMENT_IMPL_131(_) PP_ELEMENT_IMPL_130 -#define PP_ELEMENT_IMPL_132(_) PP_ELEMENT_IMPL_131 -#define PP_ELEMENT_IMPL_133(_) PP_ELEMENT_IMPL_132 -#define PP_ELEMENT_IMPL_134(_) PP_ELEMENT_IMPL_133 -#define PP_ELEMENT_IMPL_135(_) PP_ELEMENT_IMPL_134 -#define PP_ELEMENT_IMPL_136(_) PP_ELEMENT_IMPL_135 -#define PP_ELEMENT_IMPL_137(_) PP_ELEMENT_IMPL_136 -#define PP_ELEMENT_IMPL_138(_) PP_ELEMENT_IMPL_137 -#define PP_ELEMENT_IMPL_139(_) PP_ELEMENT_IMPL_138 -#define PP_ELEMENT_IMPL_140(_) PP_ELEMENT_IMPL_139 -#define PP_ELEMENT_IMPL_141(_) PP_ELEMENT_IMPL_140 -#define PP_ELEMENT_IMPL_142(_) PP_ELEMENT_IMPL_141 -#define PP_ELEMENT_IMPL_143(_) PP_ELEMENT_IMPL_142 -#define PP_ELEMENT_IMPL_144(_) PP_ELEMENT_IMPL_143 -#define PP_ELEMENT_IMPL_145(_) PP_ELEMENT_IMPL_144 -#define PP_ELEMENT_IMPL_146(_) PP_ELEMENT_IMPL_145 -#define PP_ELEMENT_IMPL_147(_) PP_ELEMENT_IMPL_146 -#define PP_ELEMENT_IMPL_148(_) PP_ELEMENT_IMPL_147 -#define PP_ELEMENT_IMPL_149(_) PP_ELEMENT_IMPL_148 -#define PP_ELEMENT_IMPL_150(_) PP_ELEMENT_IMPL_149 -#define PP_ELEMENT_IMPL_151(_) PP_ELEMENT_IMPL_150 -#define PP_ELEMENT_IMPL_152(_) PP_ELEMENT_IMPL_151 -#define PP_ELEMENT_IMPL_153(_) PP_ELEMENT_IMPL_152 -#define PP_ELEMENT_IMPL_154(_) PP_ELEMENT_IMPL_153 -#define PP_ELEMENT_IMPL_155(_) PP_ELEMENT_IMPL_154 -#define PP_ELEMENT_IMPL_156(_) PP_ELEMENT_IMPL_155 -#define PP_ELEMENT_IMPL_157(_) PP_ELEMENT_IMPL_156 -#define PP_ELEMENT_IMPL_158(_) PP_ELEMENT_IMPL_157 -#define PP_ELEMENT_IMPL_159(_) PP_ELEMENT_IMPL_158 -#define PP_ELEMENT_IMPL_160(_) PP_ELEMENT_IMPL_159 -#define PP_ELEMENT_IMPL_161(_) PP_ELEMENT_IMPL_160 -#define PP_ELEMENT_IMPL_162(_) PP_ELEMENT_IMPL_161 -#define PP_ELEMENT_IMPL_163(_) PP_ELEMENT_IMPL_162 -#define PP_ELEMENT_IMPL_164(_) PP_ELEMENT_IMPL_163 -#define PP_ELEMENT_IMPL_165(_) PP_ELEMENT_IMPL_164 -#define PP_ELEMENT_IMPL_166(_) PP_ELEMENT_IMPL_165 -#define PP_ELEMENT_IMPL_167(_) PP_ELEMENT_IMPL_166 -#define PP_ELEMENT_IMPL_168(_) PP_ELEMENT_IMPL_167 -#define PP_ELEMENT_IMPL_169(_) PP_ELEMENT_IMPL_168 -#define PP_ELEMENT_IMPL_170(_) PP_ELEMENT_IMPL_169 -#define PP_ELEMENT_IMPL_171(_) PP_ELEMENT_IMPL_170 -#define PP_ELEMENT_IMPL_172(_) PP_ELEMENT_IMPL_171 -#define PP_ELEMENT_IMPL_173(_) PP_ELEMENT_IMPL_172 -#define PP_ELEMENT_IMPL_174(_) PP_ELEMENT_IMPL_173 -#define PP_ELEMENT_IMPL_175(_) PP_ELEMENT_IMPL_174 -#define PP_ELEMENT_IMPL_176(_) PP_ELEMENT_IMPL_175 -#define PP_ELEMENT_IMPL_177(_) PP_ELEMENT_IMPL_176 -#define PP_ELEMENT_IMPL_178(_) PP_ELEMENT_IMPL_177 -#define PP_ELEMENT_IMPL_179(_) PP_ELEMENT_IMPL_178 -#define PP_ELEMENT_IMPL_180(_) PP_ELEMENT_IMPL_179 -#define PP_ELEMENT_IMPL_181(_) PP_ELEMENT_IMPL_180 -#define PP_ELEMENT_IMPL_182(_) PP_ELEMENT_IMPL_181 -#define PP_ELEMENT_IMPL_183(_) PP_ELEMENT_IMPL_182 -#define PP_ELEMENT_IMPL_184(_) PP_ELEMENT_IMPL_183 -#define PP_ELEMENT_IMPL_185(_) PP_ELEMENT_IMPL_184 -#define PP_ELEMENT_IMPL_186(_) PP_ELEMENT_IMPL_185 -#define PP_ELEMENT_IMPL_187(_) PP_ELEMENT_IMPL_186 -#define PP_ELEMENT_IMPL_188(_) PP_ELEMENT_IMPL_187 -#define PP_ELEMENT_IMPL_189(_) PP_ELEMENT_IMPL_188 -#define PP_ELEMENT_IMPL_190(_) PP_ELEMENT_IMPL_189 -#define PP_ELEMENT_IMPL_191(_) PP_ELEMENT_IMPL_190 -#define PP_ELEMENT_IMPL_192(_) PP_ELEMENT_IMPL_191 -#define PP_ELEMENT_IMPL_193(_) PP_ELEMENT_IMPL_192 -#define PP_ELEMENT_IMPL_194(_) PP_ELEMENT_IMPL_193 -#define PP_ELEMENT_IMPL_195(_) PP_ELEMENT_IMPL_194 -#define PP_ELEMENT_IMPL_196(_) PP_ELEMENT_IMPL_195 -#define PP_ELEMENT_IMPL_197(_) PP_ELEMENT_IMPL_196 -#define PP_ELEMENT_IMPL_198(_) PP_ELEMENT_IMPL_197 -#define PP_ELEMENT_IMPL_199(_) PP_ELEMENT_IMPL_198 -#define PP_ELEMENT_IMPL_200(_) PP_ELEMENT_IMPL_199 - -//////////////////////////////////////////////////////////////////////////////// -#define PP_HEAD_IMPL(seq) PP_ELEMENT_IMPL(seq, 0) - -//////////////////////////////////////////////////////////////////////////////// -#define PP_TAIL_IMPL(seq) PP_KILL_IMPL(seq, 1) - -//////////////////////////////////////////////////////////////////////////////// -#define PP_FOR_EACH_IMPL(what, seq) PP_CONCAT(PP_FOR_EACH_IMPL_, \ - PP_COUNT(seq))(what, seq) -#define PP_FOR_EACH_IMPL_0(what, seq) -#define PP_FOR_EACH_IMPL_1(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_0(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_2(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_1(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_3(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_2(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_4(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_3(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_5(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_4(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_6(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_5(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_7(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_6(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_8(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_7(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_9(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_8(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_10(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_9(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_11(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_10(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_12(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_11(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_13(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_12(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_14(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_13(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_15(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_14(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_16(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_15(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_17(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_16(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_18(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_17(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_19(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_18(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_20(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_19(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_21(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_20(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_22(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_21(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_23(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_22(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_24(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_23(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_25(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_24(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_26(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_25(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_27(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_26(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_28(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_27(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_29(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_28(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_30(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_29(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_31(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_30(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_32(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_31(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_33(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_32(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_34(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_33(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_35(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_34(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_36(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_35(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_37(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_36(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_38(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_37(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_39(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_38(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_40(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_39(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_41(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_40(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_42(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_41(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_43(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_42(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_44(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_43(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_45(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_44(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_46(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_45(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_47(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_46(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_48(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_47(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_49(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_48(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_50(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_49(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_51(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_50(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_52(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_51(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_53(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_52(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_54(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_53(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_55(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_54(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_56(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_55(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_57(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_56(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_58(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_57(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_59(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_58(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_60(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_59(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_61(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_60(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_62(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_61(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_63(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_62(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_64(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_63(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_65(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_64(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_66(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_65(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_67(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_66(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_68(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_67(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_69(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_68(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_70(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_69(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_71(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_70(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_72(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_71(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_73(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_72(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_74(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_73(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_75(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_74(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_76(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_75(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_77(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_76(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_78(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_77(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_79(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_78(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_80(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_79(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_81(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_80(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_82(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_81(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_83(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_82(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_84(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_83(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_85(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_84(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_86(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_85(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_87(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_86(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_88(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_87(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_89(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_88(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_90(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_89(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_91(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_90(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_92(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_91(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_93(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_92(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_94(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_93(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_95(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_94(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_96(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_95(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_97(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_96(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_98(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_97(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_99(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_98(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_100(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_99(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_101(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_100(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_102(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_101(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_103(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_102(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_104(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_103(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_105(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_104(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_106(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_105(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_107(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_106(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_108(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_107(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_109(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_108(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_110(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_109(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_111(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_110(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_112(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_111(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_113(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_112(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_114(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_113(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_115(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_114(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_116(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_115(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_117(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_116(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_118(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_117(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_119(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_118(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_120(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_119(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_121(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_120(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_122(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_121(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_123(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_122(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_124(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_123(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_125(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_124(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_126(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_125(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_127(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_126(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_128(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_127(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_129(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_128(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_130(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_129(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_131(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_130(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_132(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_131(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_133(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_132(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_134(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_133(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_135(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_134(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_136(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_135(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_137(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_136(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_138(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_137(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_139(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_138(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_140(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_139(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_141(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_140(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_142(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_141(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_143(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_142(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_144(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_143(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_145(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_144(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_146(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_145(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_147(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_146(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_148(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_147(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_149(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_148(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_150(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_149(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_151(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_150(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_152(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_151(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_153(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_152(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_154(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_153(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_155(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_154(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_156(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_155(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_157(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_156(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_158(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_157(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_159(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_158(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_160(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_159(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_161(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_160(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_162(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_161(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_163(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_162(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_164(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_163(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_165(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_164(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_166(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_165(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_167(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_166(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_168(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_167(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_169(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_168(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_170(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_169(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_171(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_170(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_172(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_171(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_173(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_172(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_174(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_173(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_175(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_174(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_176(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_175(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_177(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_176(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_178(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_177(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_179(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_178(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_180(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_179(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_181(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_180(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_182(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_181(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_183(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_182(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_184(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_183(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_185(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_184(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_186(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_185(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_187(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_186(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_188(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_187(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_189(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_188(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_190(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_189(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_191(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_190(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_192(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_191(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_193(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_192(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_194(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_193(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_195(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_194(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_196(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_195(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_197(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_196(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_198(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_197(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_199(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_198(what, PP_TAIL(seq)) -#define PP_FOR_EACH_IMPL_200(what, \ - seq) what(PP_HEAD(seq)) PP_FOR_EACH_IMPL_199(what, PP_TAIL(seq)) -//////////////////////////////////////////////////////////////////////////////// -/*! - \endinternal -*/ diff --git a/include/ydb-cpp-sdk/library/yt/yson/consumer.h b/include/ydb-cpp-sdk/library/yt/yson/consumer.h deleted file mode 100644 index 95363d06df4..00000000000 --- a/include/ydb-cpp-sdk/library/yt/yson/consumer.h +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once - -#include - -#include - -#include - -namespace NYT::NYson { - -//////////////////////////////////////////////////////////////////////////////// - -//! A SAX-like interface for parsing a YSON stream. -struct IYsonConsumer -{ - virtual ~IYsonConsumer() = default; - - //! The current item is a string scalar (IStringNode). - /*! - * \param value A scalar value. - */ - virtual void OnStringScalar(std::string_view value) = 0; - - //! The current item is an integer scalar (IInt64Node). - /*! - * \param value A scalar value. - */ - virtual void OnInt64Scalar(i64 value) = 0; - - //! The current item is an integer scalar (IUint64Node). - /*! - * \param value A scalar value. - */ - virtual void OnUint64Scalar(ui64 value) = 0; - - //! The current item is an FP scalar (IDoubleNode). - /*! - * \param value A scalar value. - */ - virtual void OnDoubleScalar(double value) = 0; - - //! The current item is an boolean scalar (IBooleanNode). - /*! - * \param value A scalar value. - */ - virtual void OnBooleanScalar(bool value) = 0; - - //! The current item is an entity (IEntityNode). - virtual void OnEntity() = 0; - - //! Starts a list (IListNode). - /*! - * The events describing a list are raised as follows: - * - #OnBeginList - * - For each item: #OnListItem followed by the description of the item - * - #OnEndList - */ - virtual void OnBeginList() = 0; - - //! Designates a list item. - virtual void OnListItem() = 0; - - //! Ends the current list. - virtual void OnEndList() = 0; - - //! Starts a map (IMapNode). - /*! - * The events describing a map are raised as follows: - * - #OnBeginMap - * - For each item: #OnKeyedItem followed by the description of the item - * - #OnEndMap - */ - virtual void OnBeginMap() = 0; - - //! Designates a keyed item (in map or in attributes). - /*! - * \param key Item key in the map. - */ - virtual void OnKeyedItem(std::string_view key) = 0; - - //! Ends the current map. - virtual void OnEndMap() = 0; - - //! Starts attributes. - /*! - * An arbitrary node may be preceded by attributes. - * - * The events describing attributes are raised as follows: - * - #OnBeginAttributes - * - For each item: #OnKeyedItem followed by the description of the item - * - #OnEndAttributes - */ - virtual void OnBeginAttributes() = 0; - - //! Ends the current attribute list. - virtual void OnEndAttributes() = 0; - - //! Inserts YSON-serialized node or fragment. - /*! - * \param yson Serialized data. - * \param type Type of data. - */ - virtual void OnRaw(std::string_view yson, EYsonType type) = 0; - - // Extension methods. - void OnRaw(const TYsonStringBuf& yson); -}; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NYson diff --git a/include/ydb-cpp-sdk/library/yt/yson_string/public.h b/include/ydb-cpp-sdk/library/yt/yson_string/public.h deleted file mode 100644 index dc28474d48c..00000000000 --- a/include/ydb-cpp-sdk/library/yt/yson_string/public.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -namespace NYT::NYson { - -//////////////////////////////////////////////////////////////////////////////// - -//! The data format. -DEFINE_ENUM(EYsonFormat, - // Binary. - // Most compact but not human-readable. - (Binary) - - // Text. - // Not so compact but human-readable. - // Does not use indentation. - // Uses escaping for non-text characters. - (Text) - - // Text with indentation. - // Extremely verbose but human-readable. - // Uses escaping for non-text characters. - (Pretty) -); - -// NB: -1 is used for serializing null TYsonString. -DEFINE_ENUM_WITH_UNDERLYING_TYPE(EYsonType, i8, - ((Node) (0)) - ((ListFragment) (1)) - ((MapFragment) (2)) -); - -class TYsonString; -class TYsonStringBuf; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NYson diff --git a/include/ydb-cpp-sdk/stlfwd.h b/include/ydb-cpp-sdk/stlfwd.h new file mode 100644 index 00000000000..77b97233f95 --- /dev/null +++ b/include/ydb-cpp-sdk/stlfwd.h @@ -0,0 +1,15 @@ +#pragma once + +// STL "forwarding" for the poor + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/ydb-cpp-sdk/util/digest/multi.h b/include/ydb-cpp-sdk/util/digest/multi.h deleted file mode 100644 index 0aeaa6bcafa..00000000000 --- a/include/ydb-cpp-sdk/util/digest/multi.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "numeric.h" -#include - -template -constexpr size_t MultiHash(const TOne& one) noexcept { - return THash()(one); -} - -template -constexpr size_t MultiHash(const THead& head, const TTail&... tail) noexcept { - return CombineHashes(MultiHash(tail...), THash()(head)); -} diff --git a/include/ydb-cpp-sdk/util/digest/numeric.h b/include/ydb-cpp-sdk/util/digest/numeric.h deleted file mode 100644 index e280665d4c4..00000000000 --- a/include/ydb-cpp-sdk/util/digest/numeric.h +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include -#include - -#include - -/* - * original url (now dead): http://www.cris.com/~Ttwang/tech/inthash.htm - * copy: https://gist.github.com/badboy/6267743 - */ - -static constexpr ui8 IntHashImpl(ui8 key8) noexcept { - size_t key = key8; - - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - - return static_cast(key); -} - -static constexpr ui16 IntHashImpl(ui16 key16) noexcept { - size_t key = key16; - - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - - return static_cast(key); -} - -static constexpr ui32 IntHashImpl(ui32 key) noexcept { - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - - return key; -} - -static constexpr ui64 IntHashImpl(ui64 key) noexcept { - key += ~(key << 32); - key ^= (key >> 22); - key += ~(key << 13); - key ^= (key >> 8); - key += (key << 3); - key ^= (key >> 15); - key += ~(key << 27); - key ^= (key >> 31); - - return key; -} - -template -static constexpr T IntHash(T t) noexcept { - using TCvt = TFixedWidthUnsignedInt; - - return IntHashImpl(static_cast(t)); -} - -/* - * can handle floats && pointers - */ -template -static constexpr size_t NumericHash(T t) noexcept { - using TCvt = TFixedWidthUnsignedInt; - - auto cvt = std::bit_cast(t); - return static_cast(IntHash(cvt)); -} - -template -static constexpr T CombineHashes(T l, T r) noexcept { - return IntHash(l) ^ r; -} diff --git a/include/ydb-cpp-sdk/util/generic/cast.h b/include/ydb-cpp-sdk/util/generic/cast.h deleted file mode 100644 index cb15f6375f3..00000000000 --- a/include/ydb-cpp-sdk/util/generic/cast.h +++ /dev/null @@ -1,176 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include - -#include - -template -static inline T VerifyDynamicCast(F f) { - if (!f) { - return nullptr; - } - - T ret = dynamic_cast(f); - - Y_ABORT_UNLESS(ret, "verify cast failed"); - - return ret; -} - -#if !defined(NDEBUG) - #define USE_DEBUG_CHECKED_CAST -#endif - -namespace NPrivate { - template - static T DynamicCast(F f) { - return dynamic_cast(f); - } -} - -/* - * replacement for dynamic_cast(dynamic_cast in debug mode, else static_cast) - */ -template -static inline T CheckedCast(F f) { -#if defined(USE_DEBUG_CHECKED_CAST) - return VerifyDynamicCast(f); -#else - /* Make sure F is polymorphic. - * Without this cast, CheckedCast with non-polymorphic F - * incorrectly compiled without error in release mode. - */ - { - auto&& x = &::NPrivate::DynamicCast; - - (void)x; - } - - return static_cast(f); -#endif // USE_DEBUG_CHECKED_CAST -} - -/* - * be polite - */ -#undef USE_DEBUG_CHECKED_CAST - -template -class TInteger; - -template <> -class TInteger { -public: - template - static constexpr bool IsNegative(TUnsigned) noexcept { - return false; - } -}; - -template <> -class TInteger { -public: - template - static constexpr bool IsNegative(const TSigned value) noexcept { - return value < 0; - } -}; - -template -constexpr bool IsNegative(const TType value) noexcept { - return TInteger::value>::IsNegative(value); -} - -namespace NPrivate { - template - using TUnderlyingTypeOrSelf = typename std::conditional< - std::is_enum::value, - std::underlying_type, // Lazy evaluatuion: do not call ::type here, because underlying_type is undefined if T is not an enum. - std::enable_if // Wrapping T in a class, that has member ::type typedef. - >::type::type; // Left ::type is for std::conditional, right ::type is for underlying_type/enable_if - - template - struct TSafelyConvertible { - using TSmallInt = TUnderlyingTypeOrSelf; - using TLargeInt = TUnderlyingTypeOrSelf; - - static constexpr bool Result = std::is_integral::value && std::is_integral::value && - ((std::is_signed::value == std::is_signed::value && sizeof(TSmallInt) >= sizeof(TLargeInt)) || - (std::is_signed::value && sizeof(TSmallInt) > sizeof(TLargeInt))); - }; -} - -template -constexpr std::enable_if_t<::NPrivate::TSafelyConvertible::Result, TSmallInt> SafeIntegerCast(TLargeInt largeInt) noexcept { - return static_cast(largeInt); -} - -template -inline std::enable_if_t::Result, TSmall> SafeIntegerCast(TLarge largeInt) { - using TSmallInt = ::NPrivate::TUnderlyingTypeOrSelf; - using TLargeInt = ::NPrivate::TUnderlyingTypeOrSelf; - - if (std::is_unsigned::value && std::is_signed::value) { - if (IsNegative(largeInt)) { - ythrow TBadCastException() << "Conversion '" << TypeName() << '{' << TLargeInt(largeInt) << "}' to '" - << TypeName() - << "', negative value converted to unsigned"; - } - } - - TSmallInt smallInt = TSmallInt(largeInt); - - if (std::is_signed::value && std::is_unsigned::value) { - if (IsNegative(smallInt)) { - ythrow TBadCastException() << "Conversion '" << TypeName() << '{' << TLargeInt(largeInt) << "}' to '" - << TypeName() - << "', positive value converted to negative"; - } - } - - if (TLargeInt(smallInt) != largeInt) { - ythrow TBadCastException() << "Conversion '" << TypeName() << '{' << TLargeInt(largeInt) << "}' to '" - << TypeName() << "', loss of data"; - } - - return static_cast(smallInt); -} - -template -inline TSmallInt IntegerCast(TLargeInt largeInt) noexcept { - try { - return SafeIntegerCast(largeInt); - } catch (const yexception& exc) { - Y_ABORT("IntegerCast: %s", exc.what()); - } -} - -/* Convert given enum value to its underlying type. This is just a shortcut for - * `static_cast>(enum_)`. - */ -template -constexpr std::underlying_type_t ToUnderlying(const T enum_) noexcept { - return static_cast>(enum_); -} - -// std::bit_cast from c++20 -template -TTarget BitCast(const TSource& source) { - static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); - static_assert(std::is_trivially_copyable::value, "TSource is not trivially copyable"); - static_assert(std::is_trivial::value, "TTarget is not trivial"); - - // Support volatile qualifiers. - // ReadUnaligned does not work with volatile pointers, so cast away - // volatileness beforehand. - using TNonvolatileSource = std::remove_volatile_t; - using TNonvolatileTarget = std::remove_volatile_t; - - return ReadUnaligned(&const_cast(source)); -} diff --git a/include/ydb-cpp-sdk/util/generic/fwd.h b/include/ydb-cpp-sdk/util/generic/fwd.h deleted file mode 100644 index c8ae2839c98..00000000000 --- a/include/ydb-cpp-sdk/util/generic/fwd.h +++ /dev/null @@ -1,100 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -//misc -class TBuffer; - -//functors -template -struct TLess; - -template -struct TGreater; - -template -struct TEqualTo; - -template -struct THash; - -//intrusive containers -struct TIntrusiveListDefaultTag; -template -class TIntrusiveList; - -template -class TIntrusiveListWithAutoDelete; - -template -class TIntrusiveSList; - -template -class TRbTree; - -//containers -template > -class TStack; - -template -class TBitMap; - -//autopointers -class TDelete; -class TDeleteArray; -class TFree; -class TCopyNew; - -template -class TAutoPtr; - -template -class THolder; - -template -class TRefCounted; - -template -class TDefaultIntrusivePtrOps; - -template -class TSimpleIntrusiveOps; - -template > -class TIntrusivePtr; - -template > -class TIntrusiveConstPtr; - -template > -using TSimpleIntrusivePtr = TIntrusivePtr>; - -template -class TSharedPtr; - -template -class TCopyPtr; - -template -class TCowPtr; - -template -class TPtrArg; - -template -using TArrayHolder = THolder; - -template -using TMallocHolder = THolder; - -template -using TArrayPtr = TAutoPtr; - -template -using TMallocPtr = TAutoPtr; - -struct TGUID; diff --git a/include/ydb-cpp-sdk/util/generic/singleton.h b/include/ydb-cpp-sdk/util/generic/singleton.h deleted file mode 100644 index 85f6be7b82d..00000000000 --- a/include/ydb-cpp-sdk/util/generic/singleton.h +++ /dev/null @@ -1,137 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -template -struct TSingletonTraits { - static constexpr size_t Priority = 65536; -}; - -namespace NPrivate { - void FillWithTrash(void* ptr, size_t len); - - void LockRecursive(std::atomic& lock) noexcept; - void UnlockRecursive(std::atomic& lock) noexcept; - - template - void Destroyer(void* ptr) { - ((T*)ptr)->~T(); - FillWithTrash(ptr, sizeof(T)); - } - - template - Y_NO_INLINE T* SingletonBase(std::atomic& ptr, TArgs&&... args) { - alignas(T) static char buf[sizeof(T)]; - static std::atomic lock; - - LockRecursive(lock); - - auto ret = ptr.load(); - - try { - if (!ret) { - ret = ::new (buf) T(std::forward(args)...); - - try { - AtExit(Destroyer, ret, P); - } catch (...) { - Destroyer(ret); - - throw; - } - - ptr.store(ret); - } - } catch (...) { - UnlockRecursive(lock); - - throw; - } - - UnlockRecursive(lock); - - return ret; - } - - template - T* SingletonInt(TArgs&&... args) { - static_assert(sizeof(T) < 32000, "use HugeSingleton instead"); - - static std::atomic ptr; - auto ret = ptr.load(); - - if (Y_UNLIKELY(!ret)) { - ret = SingletonBase(ptr, std::forward(args)...); - } - - return ret; - } - - template - class TDefault { - public: - template - inline TDefault(TArgs&&... args) - : T_(std::forward(args)...) - { - } - - inline const T* Get() const noexcept { - return &T_; - } - - private: - T T_; - }; - - template - struct THeapStore { - template - inline THeapStore(TArgs&&... args) - : D(new T(std::forward(args)...)) - { - } - - inline ~THeapStore() { - delete D; - } - - T* D; - }; -} - -#define Y_DECLARE_SINGLETON_FRIEND() \ - template \ - friend T* ::NPrivate::SingletonInt(TArgs&&...); \ - template \ - friend T* ::NPrivate::SingletonBase(std::atomic&, TArgs&&...); - -template -Y_RETURNS_NONNULL T* Singleton(TArgs&&... args) { - return ::NPrivate::SingletonInt::Priority>(std::forward(args)...); -} - -template -Y_RETURNS_NONNULL T* HugeSingleton(TArgs&&... args) { - return Singleton<::NPrivate::THeapStore>(std::forward(args)...)->D; -} - -template -Y_RETURNS_NONNULL T* SingletonWithPriority(TArgs&&... args) { - return ::NPrivate::SingletonInt(std::forward(args)...); -} - -template -Y_RETURNS_NONNULL T* HugeSingletonWithPriority(TArgs&&... args) { - return SingletonWithPriority<::NPrivate::THeapStore, P>(std::forward(args)...)->D; -} - -template -const T& Default() { - return *(::NPrivate::SingletonInt, TSingletonTraits::Priority>()->Get()); -} diff --git a/include/ydb-cpp-sdk/util/memory/blob.h b/include/ydb-cpp-sdk/util/memory/blob.h deleted file mode 100644 index 595c1246d46..00000000000 --- a/include/ydb-cpp-sdk/util/memory/blob.h +++ /dev/null @@ -1,326 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -class TMemoryMap; -class IInputStream; -class TFile; -class TBuffer; - -enum class EMappingMode { - /// Just mmap a file allowing lazy page loading at access - Standard, - /// Same as previous but warmup the buffer with sequential access to it's data - Precharged, - /// Try to lock file in memory so that it doesn't wash away. See mlock(2) - Locked -}; - -/// @addtogroup BLOBs -/// @{ -class TBlob { -public: - class TBase { - public: - inline TBase() noexcept = default; - virtual ~TBase() = default; - - virtual void Ref() noexcept = 0; - virtual void UnRef() noexcept = 0; - }; - -private: - struct TStorage { - const void* Data; - size_t Length; - TBase* Base; - - inline TStorage(const void* data, size_t length, TBase* base) noexcept - : Data(data) - , Length(length) - , Base(base) - { - } - - inline ~TStorage() = default; - - inline void Swap(TStorage& r) noexcept { - DoSwap(Data, r.Data); - DoSwap(Length, r.Length); - DoSwap(Base, r.Base); - } - }; - -public: - using value_type = ui8; - using const_reference = const value_type&; - using const_pointer = const value_type*; - using const_iterator = const_pointer; - - /** - * Constructs a null blob (data array points to nullptr). - */ - TBlob() noexcept - : S_(nullptr, 0, nullptr) - { - } - - inline TBlob(const TBlob& r) noexcept - : S_(r.S_) - { - Ref(); - } - - TBlob(TBlob&& r) noexcept - : TBlob() - { - this->Swap(r); - } - - inline TBlob(const void* data, size_t length, TBase* base) noexcept - : S_(data, length, base) - { - Ref(); - } - - inline ~TBlob() { - UnRef(); - } - - inline TBlob& operator=(const TBlob& r) noexcept { - TBlob(r).Swap(*this); - - return *this; - } - - /// Swaps content of two data arrays. - inline void Swap(TBlob& r) noexcept { - S_.Swap(r.S_); - } - - /// Returns a const reference to the data array. - inline const void* Data() const noexcept { - return S_.Data; - } - - /// Returns the size of the data array in bytes. - inline size_t Length() const noexcept { - return S_.Length; - } - - /// Checks if the object has an empty data array. - Y_PURE_FUNCTION inline bool Empty() const noexcept { - return !Length(); - } - - /// Checks if the blob owns data - Y_PURE_FUNCTION inline bool OwnsData() const noexcept { - return S_.Base != nullptr; - } - - /// Checks if the object has a data array. - inline bool IsNull() const noexcept { - return !Data(); - } - - /// Returns a const pointer of char type to the data array. - inline const char* AsCharPtr() const noexcept { - return (const char*)Data(); - } - - /// Returns a const pointer of unsigned char type to the data array. - inline const unsigned char* AsUnsignedCharPtr() const noexcept { - return (const unsigned char*)Data(); - } - - inline std::string_view AsStringBuf() const noexcept { - return std::string_view(AsCharPtr(), size()); - } - - /// Drops the data array. - inline void Drop() noexcept { - TBlob().Swap(*this); - } - - /* - * Some stl-like methods - */ - - /// Returns a const reference to the data array. - /// result type is const ui8* which is not consistent with Data method above - /// but it's consistent with operator[], Begin and End methods below - inline const_pointer data() const noexcept { - return static_cast(Data()); - } - - /// Returns the size of the data array in bytes. - inline size_t size() const noexcept { - return Length(); - } - - /// Returns the size of the data array in bytes. - inline size_t Size() const noexcept { - return Length(); - } - - /// Standard iterator. - inline const_iterator Begin() const noexcept { - return AsUnsignedCharPtr(); - } - - /// Standard iterator. - inline const_iterator End() const noexcept { - return Begin() + Size(); - } - - inline value_type operator[](size_t n) const noexcept { - return *(Begin() + n); - } - - /// Shortcut to SubBlob(0, len) - TBlob SubBlob(size_t len) const; - - /// Creates a new object from the provided range [begin, end) of internal data. No memory allocation and no copy. - /// @details Increments the refcounter of the current object - TBlob SubBlob(size_t begin, size_t end) const; - - /// Calls Copy() for the internal data. - TBlob DeepCopy() const; - - /// Creates a new blob with a single-threaded (non atomic) refcounter. Dynamically allocates memory and copies the data content. - static TBlob CopySingleThreaded(const void* data, size_t length); - - /// Creates a new blob with a multi-threaded (atomic) refcounter. Dynamically allocates memory and copies the data content. - static TBlob Copy(const void* data, size_t length); - - /// Creates a blob which doesn't own data. No refcounter, no memory allocation, no data copy. - static TBlob NoCopy(const void* data, size_t length); - - /// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob FromFileSingleThreaded(const std::string& path, EMappingMode); - - /// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob FromFile(const std::string& path, EMappingMode); - - /// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob FromFileSingleThreaded(const TFile& file, EMappingMode); - - /// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob FromFile(const TFile& file, EMappingMode); - - /// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob FromFileSingleThreaded(const std::string& path); - - /// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob FromFile(const std::string& path); - - /// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob FromFileSingleThreaded(const TFile& file); - - /// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob FromFile(const TFile& file); - - // TODO: drop Precharged* functions. - - /// Creates a precharged blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob PrechargedFromFileSingleThreaded(const std::string& path); - - /// Creates a precharged blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob PrechargedFromFile(const std::string& path); - - /// Creates a precharged blob with a single-threaded (non atomic) refcounter. It maps the file content as data. - static TBlob PrechargedFromFileSingleThreaded(const TFile& file); - - /// Creates a precharged blob with a multi-threaded (atomic) refcounter. It maps the file content as data. - static TBlob PrechargedFromFile(const TFile& file); - - /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. - static TBlob LockedFromFileSingleThreaded(const std::string& path); - - /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data. - static TBlob LockedFromFile(const std::string& path); - - /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file content as data. - static TBlob LockedFromFileSingleThreaded(const TFile& file); - - /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file content as data. - static TBlob LockedFromFile(const TFile& file); - - /// Creates a locked blob with a single-threaded (non atomic) refcounter from the mapped memory. - static TBlob LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length); - - /// Creates a locked blob with a multi-threaded (atomic) refcounter from the mapped memory. - static TBlob LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length); - - /// Creates a blob with a single-threaded (non atomic) refcounter from the mapped memory. - static TBlob FromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length); - - /// Creates a blob with a multi-threaded (atomic) refcounter from the mapped memory. - static TBlob FromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length); - - /// Creates a blob with a single-threaded (non atomic) refcounter. Dynamically allocates memory and copies data from the file on the path using pread(). - static TBlob FromFileContentSingleThreaded(const std::string& path); - - /// Creates a blob with a multi-threaded (atomic) refcounter. Dynamically allocates memory and copies data from the file on the path using pread(). - static TBlob FromFileContent(const std::string& path); - - /// Creates a blob with a single-threaded (non atomic) refcounter. Dynamically allocates memory and copies data from the file using pread(). - static TBlob FromFileContentSingleThreaded(const TFile& file); - - /// Creates a blob with a multi-threaded (atomic) refcounter. Dynamically allocates memory and copies data from the file using pread(). - static TBlob FromFileContent(const TFile& file); - - /// Creates a blob with a single-threaded (non atomic) refcounter. Dynamically allocates memory and copies data from the provided range of the file content using pread(). - static TBlob FromFileContentSingleThreaded(const TFile& file, ui64 offset, size_t length); - - /// Creates a blob with a multi-threaded (atomic) refcounter. Dynamically allocates memory and copies data from the provided range of the file content using pread(). - static TBlob FromFileContent(const TFile& file, ui64 offset, size_t length); - - /// Creates a blob from the stream content with a single-threaded (non atomic) refcounter. - static TBlob FromStreamSingleThreaded(IInputStream& in); - - /// Creates a blob from the stream content with a multi-threaded (atomic) refcounter. - static TBlob FromStream(IInputStream& in); - - /// Creates a blob with a single-threaded (non atomic) refcounter. No memory allocation, no content copy. - /// @details The input object becomes empty. - static TBlob FromBufferSingleThreaded(TBuffer& in); - - /// Creates a blob with a multi-threaded (atomic) refcounter. No memory allocation, no content copy. - /// @details The input object becomes empty. - static TBlob FromBuffer(TBuffer& in); - - /// Creates a blob from std::string with a single-threaded (non atomic) refcounter. - static TBlob FromStringSingleThreaded(const std::string& s); - - /// Creates a blob from std::string with a single-threaded (non atomic) refcounter. Doesn't copy its content. - static TBlob FromStringSingleThreaded(std::string&& s); - - /// Creates a blob from std::string with a multi-threaded (atomic) refcounter. - static TBlob FromString(const std::string& s); - - /// Creates a blob from std::string with a multi-threaded (atomic) refcounter. Doesn't copy its content. - static TBlob FromString(std::string&& s); - -private: - inline void Ref() noexcept { - if (S_.Base) { - S_.Base->Ref(); - } - } - - inline void UnRef() noexcept { - if (S_.Base) { - S_.Base->UnRef(); - } - } - -private: - TStorage S_; -}; - -/// @} diff --git a/include/ydb-cpp-sdk/util/memory/tempbuf.h b/include/ydb-cpp-sdk/util/memory/tempbuf.h deleted file mode 100644 index 3e541b89ea2..00000000000 --- a/include/ydb-cpp-sdk/util/memory/tempbuf.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once - -#include -#include - -#include - -/* - * This is really fast buffer for temporary data. - * For small sizes it works almost fast as pure alloca() - * (by using perthreaded list of free blocks), - * for big sizes it works as fast as malloc()/operator new()/... - * Over-aligned types are not supported. - */ -class TTempBuf { -public: - static constexpr std::size_t TmpBufLen = 64 * 1024; - - /* - * we do not want many friends for this class :) - */ - class TImpl; - - TTempBuf(); - TTempBuf(std::size_t len); - TTempBuf(const TTempBuf& b) noexcept; - TTempBuf(TTempBuf&& b) noexcept; - ~TTempBuf(); - - TTempBuf& operator=(const TTempBuf& b) noexcept; - TTempBuf& operator=(TTempBuf&& b) noexcept; - - Y_PURE_FUNCTION char* Data() noexcept; - - Y_PURE_FUNCTION const char* Data() const noexcept; - - Y_PURE_FUNCTION char* Current() noexcept; - - Y_PURE_FUNCTION const char* Current() const noexcept; - - Y_PURE_FUNCTION std::size_t Size() const noexcept; - - Y_PURE_FUNCTION std::size_t Filled() const noexcept; - - Y_PURE_FUNCTION std::size_t Left() const noexcept; - - void Reset() noexcept; - void SetPos(std::size_t off); - char* Proceed(std::size_t off); - void Append(const void* data, std::size_t len); - - Y_PURE_FUNCTION bool IsNull() const noexcept; - -private: - TIntrusivePtr Impl_; -}; - -template -class TTempArray: private TTempBuf { -private: - static T* TypedPointer(char* pointer) noexcept { - return reinterpret_cast(pointer); - } - static const T* TypedPointer(const char* pointer) noexcept { - return reinterpret_cast(pointer); - } - static constexpr std::size_t RawSize(const std::size_t size) noexcept { - return size * sizeof(T); - } - static constexpr std::size_t TypedSize(const std::size_t size) noexcept { - return size / sizeof(T); - } - -public: - TTempArray() = default; - - TTempArray(std::size_t len) - : TTempBuf(RawSize(len)) - { - } - - T* Data() noexcept { - return TypedPointer(TTempBuf::Data()); - } - - const T* Data() const noexcept { - return TypedPointer(TTempBuf::Data()); - } - - T* Current() noexcept { - return TypedPointer(TTempBuf::Current()); - } - - const T* Current() const noexcept { - return TypedPointer(TTempBuf::Current()); - } - - std::size_t Size() const noexcept { - return TypedSize(TTempBuf::Size()); - } - std::size_t Filled() const noexcept { - return TypedSize(TTempBuf::Filled()); - } - - T* Proceed(std::size_t off) { - return reinterpret_cast(TTempBuf::Proceed(RawSize(off))); - } -}; diff --git a/include/ydb-cpp-sdk/util/network/ip.h b/include/ydb-cpp-sdk/util/network/ip.h deleted file mode 100644 index 0e4548b53ce..00000000000 --- a/include/ydb-cpp-sdk/util/network/ip.h +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -#include "socket.h" -#include "hostip.h" - -#include -#include -#include - -#include - -/// IPv4 address in network format -using TIpHost = ui32; - -/// Port number in host format -using TIpPort = ui16; - -/* - * ipStr is in 'ddd.ddd.ddd.ddd' format - * returns IPv4 address in inet format - */ -static inline TIpHost IpFromString(const char* ipStr) { - in_addr ia; - - if (inet_aton(ipStr, &ia) == 0) { - ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ip address"; - } - - return (ui32)ia.s_addr; -} - -static inline char* IpToString(TIpHost ip, char* buf, size_t len) { - if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) { - ythrow TSystemError() << "Failed to get ip address string"; - } - - return buf; -} - -static inline std::string IpToString(TIpHost ip) { - char buf[INET_ADDRSTRLEN]; - - return std::string(IpToString(ip, buf, sizeof(buf))); -} - -static inline TIpHost ResolveHost(const char* data, size_t len) { - TIpHost ret; - const std::string s(data, len); - - if (NResolver::GetHostIP(s.data(), &ret) != 0) { - ythrow TSystemError(NResolver::GetDnsError()) << "can not resolve(" << s << ")"; - } - - return HostToInet(ret); -} - -/// socket address -struct TIpAddress: public sockaddr_in { - inline TIpAddress() noexcept { - Clear(); - } - - inline TIpAddress(const sockaddr_in& addr) noexcept - : sockaddr_in(addr) - , tmp(0) - { - } - - inline TIpAddress(TIpHost ip, TIpPort port) noexcept { - Set(ip, port); - } - - inline TIpAddress(std::string_view ip, TIpPort port) { - Set(ResolveHost(ip.data(), ip.size()), port); - } - - inline TIpAddress(const char* ip, TIpPort port) { - Set(ResolveHost(ip, strlen(ip)), port); - } - - inline operator sockaddr*() const noexcept { - return (sockaddr*)(sockaddr_in*)this; - } - - inline operator socklen_t*() const noexcept { - tmp = sizeof(sockaddr_in); - - return (socklen_t*)&tmp; - } - - inline operator socklen_t() const noexcept { - tmp = sizeof(sockaddr_in); - - return tmp; - } - - inline void Clear() noexcept { - Zero((sockaddr_in&)(*this)); - } - - inline void Set(TIpHost ip, TIpPort port) noexcept { - Clear(); - - sin_family = AF_INET; - sin_addr.s_addr = ip; - sin_port = HostToInet(port); - } - - inline TIpHost Host() const noexcept { - return sin_addr.s_addr; - } - - inline TIpPort Port() const noexcept { - return InetToHost(sin_port); - } - -private: - // required for "operator socklen_t*()" - mutable socklen_t tmp; -}; diff --git a/include/ydb-cpp-sdk/util/str_stl.h b/include/ydb-cpp-sdk/util/str_stl.h deleted file mode 100644 index 11c5156e5af..00000000000 --- a/include/ydb-cpp-sdk/util/str_stl.h +++ /dev/null @@ -1,263 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace std { - template <> - struct less { - bool operator()(const char* x, const char* y) const { - return std::strcmp(x, y) < 0; - } - }; - template <> - struct equal_to { - bool operator()(const char* x, const char* y) const { - return std::strcmp(x, y) == 0; - } - using is_transparent = void; - }; -} - -namespace NHashPrivate { - template - struct THashHelper { - inline size_t operator()(const T& t) const noexcept { - return static_cast(t); // If you have a compilation error here, look at explanation below: - // Probably error is caused by undefined template specialization of THash - // You can find examples of specialization in this file - } - }; - - template - struct THashHelper { - inline size_t operator()(const T& t) const noexcept { - return NumericHash(t); - } - }; - - template - struct TStringHash { - using is_transparent = void; - - inline size_t operator()(const std::basic_string_view s) const noexcept { - return NHashPrivate::ComputeStringHash(s.data(), s.size()); - } - }; -} - -template -struct hash: public NHashPrivate::THashHelper::value && !std::is_integral::value> { -}; - -template -struct hash { - inline size_t operator()(const T* t) const noexcept { - return NumericHash(t); - } -}; - -template -struct hash: public ::hash { -}; - -template <> -struct hash: ::NHashPrivate::TStringHash { -}; - -template -struct hash: ::NHashPrivate::TStringHash { -}; - -template <> -struct THash: ::NHashPrivate::TStringHash { -}; - -// template <> -// struct hash: ::NHashPrivate::TStringHash { -// }; - -// template <> -// struct hash: ::NHashPrivate::TStringHash { -// }; - -template <> -struct THash: ::NHashPrivate::TStringHash { -}; - -// template <> -// struct hash: ::NHashPrivate::TStringHash { -// }; - -template <> -struct THash: ::NHashPrivate::TStringHash { -}; - -template -struct hash>: ::NHashPrivate::TStringHash { -}; - -template <> -struct THash { - inline size_t operator()(const std::type_index& index) const { - return index.hash_code(); - } -}; - -namespace NHashPrivate { - template - Y_FORCE_INLINE static size_t HashObject(const T& val) { - return THash()(val); - } - - template - struct TupleHashHelper { - Y_FORCE_INLINE static size_t Hash(const std::tuple& tuple) { - return CombineHashes(HashObject(std::get(tuple)), - TupleHashHelper= sizeof...(TArgs), TArgs...>::Hash(tuple)); - } - }; - - template - struct TupleHashHelper { - Y_FORCE_INLINE static size_t Hash(const std::tuple& tuple) { - return HashObject(std::get(tuple)); - } - }; - -} - -template -struct THash> { - size_t operator()(const std::tuple& tuple) const { - return NHashPrivate::TupleHashHelper<0, 1 >= sizeof...(TArgs), TArgs...>::Hash(tuple); - } -}; - -template -struct THash: public ::hash { -}; - -namespace NHashPrivate { - template >::value&& std::is_empty>::value> - struct TPairHash { - private: - THash FirstHash; - THash SecondHash; - - public: - template - inline size_t operator()(const T& pair) const { - return CombineHashes(FirstHash(pair.first), SecondHash(pair.second)); - } - }; - - /** - * Specialization for the case where both hash functors are empty. Basically the - * only one we care about. We don't introduce additional specializations for - * cases where only one of the functors is empty as the code bloat is just not worth it. - */ - template - struct TPairHash { - template - inline size_t operator()(const T& pair) const { - // maps have TFirst = const TFoo, which would make for an undefined specialization - using TFirstClean = std::remove_cv_t; - using TSecondClean = std::remove_cv_t; - return CombineHashes(THash()(pair.first), THash()(pair.second)); - } - }; -} - -template -struct hash>: public NHashPrivate::TPairHash { -}; - -template -struct TEqualTo: public std::equal_to { -}; - -template <> -struct TEqualTo: public TEqualTo { - using is_transparent = void; -}; - -template <> -struct TEqualTo: public TEqualTo { - using is_transparent = void; -}; - -template <> -struct TEqualTo: public TEqualTo { - using is_transparent = void; -}; - -template -struct TEqualTo> { - template - inline bool operator()(const std::pair& a, const TOther& b) const { - return TEqualTo()(a.first, b.first) && TEqualTo()(a.second, b.second); - } - using is_transparent = void; -}; - -template -struct TCIEqualTo { -}; - -template <> -struct TCIEqualTo { - inline bool operator()(const char* a, const char* b) const { - return stricmp(a, b) == 0; - } -}; - -template <> -struct TCIEqualTo { - inline bool operator()(const std::string& a, const std::string& b) const { - return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0; - } -}; - -template -struct TLess: public std::less { -}; - -template <> -struct TLess: public TLess { - using is_transparent = void; -}; - -template <> -struct TLess: public TLess { - using is_transparent = void; -}; - -template <> -struct TLess: public TLess { - using is_transparent = void; -}; - -template -struct TGreater: public std::greater { -}; - -template <> -struct TGreater: public TGreater { - using is_transparent = void; -}; - -template <> -struct TGreater: public TGreater { - using is_transparent = void; -}; diff --git a/include/ydb-cpp-sdk/util/stream/debug.h b/include/ydb-cpp-sdk/util/stream/debug.h deleted file mode 100644 index f661794ffe3..00000000000 --- a/include/ydb-cpp-sdk/util/stream/debug.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -/** - * @returns Standard debug stream. - * @see Cdbg - */ -std::ostream& StdDbgStream() noexcept; - -/** - * Standard debug stream. - * - * Behavior of this stream is controlled via `DBGOUT` environment variable. - * If this variable is set, then this stream is redirected into `stderr`, - * otherwise whatever is written into it is simply ignored. - */ -#define Cdbg (StdDbgStream()) - -/** @} */ diff --git a/include/ydb-cpp-sdk/util/stream/fwd.h b/include/ydb-cpp-sdk/util/stream/fwd.h deleted file mode 100644 index 113c1c80f2d..00000000000 --- a/include/ydb-cpp-sdk/util/stream/fwd.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include - -class IInputStream; -class IOutputStream; - -class IZeroCopyInput; -class IZeroCopyInputFastReadTo; -class IZeroCopyOutput; - -using TStreamManipulator = void (*)(IOutputStream&); - -class TLengthLimitedInput; - -class TMemoryInput; -class TMemoryOutput; -class TMemoryWriteBuffer; - -class TMultiInput; - -class TNullInput; -class TNullOutput; -class TNullIO; - -class TPipeBase; -class TPipeInput; -class TPipeOutput; -class TPipedBase; -class TPipedInput; -class TPipedOutput; - -class TStringInput; -class TStringOutput; -class TStringStream; - -class TTeeOutput; - -class TTempBufOutput; - -class IWalkInput; - -struct TZLibError; -struct TZLibCompressorError; -struct TZLibDecompressorError; - -namespace ZLib { - enum StreamType: ui8; -} - -class TZLibDecompress; -class TZLibCompress; - -class TBufferInput; -class TBufferOutput; -class TBufferStream; - -class TBufferedInput; -class TBufferedOutputBase; -class TBufferedOutput; -class TAdaptiveBufferedOutput; - -template -class TBuffered; - -template -class TAdaptivelyBuffered; - -class TUnbufferedFileInput; -class TUnbufferedFileOutput; - -class TFileInput; -using TIFStream = TFileInput; - -class TFixedBufferFileOutput; -using TOFStream = TFixedBufferFileOutput; - -using TFileOutput = TAdaptivelyBuffered; diff --git a/include/ydb-cpp-sdk/util/stream/output.h b/include/ydb-cpp-sdk/util/stream/output.h deleted file mode 100644 index 0d1c0b14d11..00000000000 --- a/include/ydb-cpp-sdk/util/stream/output.h +++ /dev/null @@ -1,285 +0,0 @@ -#pragma once - -#include "fwd.h" - -#include -#include - -#include -#include - -/** - * @addtogroup Streams_Base - * @{ - */ - -/** - * Abstract output stream. - */ -class IOutputStream: public TNonCopyable { -public: - /** - * Data block for output. - */ - struct TPart { - inline TPart(const void* Buf, size_t Len) noexcept - : buf(Buf) - , len(Len) - { - } - - inline TPart(const std::string_view s) noexcept - : buf(s.data()) - , len(s.size()) - { - } - - inline TPart() noexcept - : buf(nullptr) - , len(0) - { - } - - inline ~TPart() = default; - - static inline TPart CrLf() noexcept { - return TPart("\r\n", 2); - } - - const void* buf; - size_t len; - }; - - IOutputStream() noexcept; - virtual ~IOutputStream(); - - IOutputStream(IOutputStream&&) noexcept { - } - - IOutputStream& operator=(IOutputStream&&) noexcept { - return *this; - } - - /** - * Writes into this stream. - * - * @param buf Data to write. - * @param len Number of bytes to write. - */ - inline void Write(const void* buf, size_t len) { - if (len) { - DoWrite(buf, len); - } - } - - /** - * Writes a string into this stream. - * - * @param st String to write. - */ - inline void Write(const std::string_view st) { - Write(st.data(), st.size()); - } - - /** - * Writes several data blocks into this stream. - * - * @param parts Pointer to the start of the data blocks - * array. - * @param count Number of data blocks to write. - */ - inline void Write(const TPart* parts, size_t count) { - if (count > 1) { - DoWriteV(parts, count); - } else if (count) { - DoWrite(parts->buf, parts->len); - } - } - - /** - * Writes a single character into this stream. - * - * @param ch Character to write. - */ - inline void Write(char ch) { - DoWriteC(ch); - } - - /** - * Flushes this stream's buffer, if any. - * - * Note that this can also be done with a `Flush` manipulator: - * @code - * stream << "some string" << Flush; - * @endcode - */ - inline void Flush() { - DoFlush(); - } - - /** - * Flushes and closes this stream. No more data can be written into a stream - * once it's closed. - */ - inline void Finish() { - DoFinish(); - } - -protected: - /** - * Writes into this stream. - * - * @param buf Data to write. - * @param len Number of bytes to write. - * @throws yexception If IO error occurs. - */ - virtual void DoWrite(const void* buf, size_t len) = 0; - - /** - * Writes several data blocks into this stream. - * - * @param parts Pointer to the start of the data blocks - * array. - * @param count Number of data blocks to write. - * @throws yexception If IO error occurs. - */ - virtual void DoWriteV(const TPart* parts, size_t count); - - /** - * Writes a single character into this stream. Can be overridden with a faster implementation. - * - * @param ch Character to write. - */ - virtual void DoWriteC(char ch); - - /** - * Flushes this stream's buffer, if any. - * - * @throws yexception If IO error occurs. - */ - virtual void DoFlush(); - - /** - * Flushes and closes this stream. No more data can be written into a stream - * once it's closed. - * - * @throws yexception If IO error occurs. - */ - virtual void DoFinish(); -}; - -/** - * `operator<<` for `IOutputStream` by default delegates to this function. - * - * Note that while `operator<<` uses overloading (and thus argument-dependent - * lookup), `Out` uses template specializations. This makes it possible to - * have a single `Out` declaration, and then just provide specializations in - * cpp files, letting the linker figure everything else out. This approach - * reduces compilation times. - * - * However, if the flexibility of overload resolution is needed, then one should - * just overload `operator<<`. - * - * @param out Output stream to write into. - * @param value Value to write. - */ -template -void Out(IOutputStream& out, typename TTypeTraits::TFuncParam value); - -#define Y_DECLARE_OUT_SPEC(MODIF, T, stream, value) \ - template <> \ - MODIF void Out(IOutputStream & stream, TTypeTraits::TFuncParam value) - -template <> -inline void Out(IOutputStream& o, const char* t) { - if (t) { - o.Write(t); - } else { - o.Write("(null)"); - } -} - -template <> -void Out(IOutputStream& o, const wchar16* w); - -template <> -void Out(IOutputStream& o, const wchar32* w); - -static inline IOutputStream& operator<<(IOutputStream& o, TStreamManipulator m) { - m(o); - - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, const char* t) { - Out(o, t); - - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, char* t) { - Out(o, t); - - return o; -} - -template -static inline std::enable_if_t::value, IOutputStream&> operator<<(IOutputStream& o, T t) { - Out(o, t); - - return o; -} - -template -static inline std::enable_if_t::value, IOutputStream&> operator<<(IOutputStream& o, const T& t) { - Out(o, t); - - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) { - Out(o, t); - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, wchar16* t) { - Out(o, t); - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, const wchar32* t) { - Out(o, t); - return o; -} - -static inline IOutputStream& operator<<(IOutputStream& o, wchar32* t) { - Out(o, t); - return o; -} - -namespace NPrivate { - IOutputStream& StdErrStream() noexcept; -} - -/** - * Standard error stream. - */ -#define Cerr (::NPrivate::StdErrStream()) - - -/** - * End-of-line output manipulator, basically the same as `std::endl`. - */ -static inline void Endl(IOutputStream& o) { - (o << '\n').Flush(); -} - -/* - * Also see format.h for additional manipulators. - */ - -#include "debug.h" - -void RedirectStdioToAndroidLog(bool redirect); - -/** @} */ diff --git a/include/ydb-cpp-sdk/util/stream/tempbuf.h b/include/ydb-cpp-sdk/util/stream/tempbuf.h deleted file mode 100644 index be75bb4d518..00000000000 --- a/include/ydb-cpp-sdk/util/stream/tempbuf.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "output.h" - -#include - -class TTempBufOutput: public IOutputStream, public TTempBuf { -public: - inline TTempBufOutput() = default; - - explicit TTempBufOutput(size_t size) - : TTempBuf(size) - { - } - - TTempBufOutput(TTempBufOutput&&) noexcept = default; - TTempBufOutput& operator=(TTempBufOutput&&) noexcept = default; - -protected: - void DoWrite(const void* data, size_t len) override; -}; diff --git a/include/ydb-cpp-sdk/util/string/cast.h b/include/ydb-cpp-sdk/util/string/cast.h deleted file mode 100644 index 7eda085b507..00000000000 --- a/include/ydb-cpp-sdk/util/string/cast.h +++ /dev/null @@ -1,466 +0,0 @@ -#pragma once - -#include - -#include -#include -#include -#include - -#include -#include - -/* - * specialized for all arithmetic types - */ - -template -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 - */ -template -inline size_t ToString(const T& t, char* buf, size_t len) { - using TParam = typename TTypeTraits::TFuncParam; - - return ToStringImpl(t, buf, len); -} - -/** - * Floating point to string conversion mode, values are enforced by `dtoa_impl.cpp`. - */ -enum EFloatToStringMode { - /** 0.1f -> "0.1", 0.12345678f -> "0.12345678", ignores ndigits. */ - PREC_AUTO = 0, - - /** "%g" mode, writes up to the given number of significant digits: - * 0.1f -> "0.1", 0.12345678f -> "0.123457" for ndigits=6, 1.2e-06f -> "1.2e-06" */ - PREC_NDIGITS = 2, - - /** "%f" mode, writes the given number of digits after decimal point: - * 0.1f -> "0.100000", 1.2e-06f -> "0.000001" for ndigits=6 */ - PREC_POINT_DIGITS = 3, - - /** same as PREC_POINT_DIGITS, but stripping trailing zeroes: - * 0.1f for ndgigits=6 -> "0.1" */ - PREC_POINT_DIGITS_STRIP_ZEROES = 4 -}; - -size_t FloatToString(float t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0); -size_t FloatToString(double t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0); - -template -inline std::string FloatToString(const T& t, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0) { - char buf[512]; // Max() with mode = PREC_POINT_DIGITS has 309 digits before the decimal point - size_t count = FloatToString(t, buf, sizeof(buf), mode, ndigits); - return std::string(buf, count); -} - -namespace NPrivate { - template - struct TToString { - static inline std::string Cvt(const T& t) { - char buf[512]; - - return std::string(buf, ToString(t, buf, sizeof(buf))); - } - }; - - template - struct TToString { - static inline std::string Cvt(const T& t) { - std::string s; - TStringOutput o(s); - o << t; - return s; - } - }; -} - -/* - * some clever implementations... - */ -template -inline std::string ToString(const T& t) { - using TR = std::remove_cv_t; - - return ::NPrivate::TToString::value>::Cvt((const TR&)t); -} - -inline const std::string& ToString(const std::string& s Y_LIFETIME_BOUND) noexcept { - return s; -} - -inline std::string&& ToString(std::string&& s Y_LIFETIME_BOUND) noexcept { - return std::move(s); -} - -inline std::string ToString(const char* s) { - return s; -} - -inline std::string ToString(char* s) { - return s; -} - -/* - * Wrapper for wide strings. - */ -template -inline std::u16string ToWtring(const T& t) { - return NUtils::FromAscii(ToString(t)); -} - -inline const std::u16string& ToWtring(const std::u16string& w Y_LIFETIME_BOUND) noexcept { - return w; -} - -inline std::u16string&& ToWtring(std::u16string&& w Y_LIFETIME_BOUND) noexcept { - return std::move(w); -} - -struct TFromStringException: public TBadCastException { -}; - -/* - * specialized for: - * bool - * short - * unsigned short - * int - * unsigned int - * long - * unsigned long - * long long - * unsigned long long - * float - * double - * long double - */ -template -T FromStringImpl(const TChar* data, size_t len); - -template -inline T FromString(const TChar* data, size_t len) { - return ::FromStringImpl(data, len); -} - -template -inline T FromString(const TChar* data) { - return ::FromString(data, std::char_traits::length(data)); -} - -template -inline T FromString(const std::string_view& s) { - return ::FromString(s.data(), s.size()); -} - -template -inline T FromString(const std::string& s) { - return ::FromString(s.data(), s.size()); -} - -template <> -inline std::string FromString(const std::string& s) { - return s; -} - -template -inline T FromString(const std::u16string_view& s) { - return ::FromString(s.data(), s.size()); -} - -template -inline T FromString(const std::u16string& s) { - return ::FromString(s.data(), s.size()); -} - -namespace NPrivate { - template - class TFromString { - const TChar* const Data; - const size_t Len; - - public: - inline TFromString(const TChar* data, size_t len) - : Data(data) - , Len(len) - { - } - - template - inline operator T() const { - return FromString(Data, Len); - } - }; -} - -template -inline ::NPrivate::TFromString FromString(const TChar* data, size_t len) { - return ::NPrivate::TFromString(data, len); -} - -template -inline ::NPrivate::TFromString FromString(const TChar* data) { - return ::NPrivate::TFromString(data, std::char_traits::length(data)); -} - -template -inline ::NPrivate::TFromString FromString(const T& s) { - return ::NPrivate::TFromString(s.data(), s.size()); -} - -// Conversion exception free versions -template -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 -inline bool TryFromString(const TChar* data, size_t len, T& result) { - return TryFromStringImpl(data, len, result); -} - -template -inline bool TryFromString(const TChar* data, T& result) { - return TryFromString(data, std::char_traits::length(data), result); -} - -template -inline bool TryFromString(const TChar* data, const size_t len, T& result, const T& def) { - if (TryFromString(data, len, result)) { - return true; - } - result = def; - return false; -} - -template -inline bool TryFromString(const std::string_view& s, T& result) { - return TryFromString(s.data(), s.size(), result); -} - -template -inline bool TryFromString(const std::string& s, T& result) { - return TryFromString(s.data(), s.size(), result); -} - -template -inline bool TryFromString(const std::u16string_view& s, T& result) { - return TryFromString(s.data(), s.size(), result); -} - -template -inline bool TryFromString(const std::u16string& s, T& result) { - return TryFromString(s.data(), s.size(), result); -} - -template -inline std::optional TryFromString(std::basic_string_view s) { - std::optional result{std::in_place}; - if (!TryFromString(s, *result)) { - result.reset(); - } - - return result; -} - -template -inline std::optional TryFromString(const TChar* data) { - return TryFromString(std::basic_string_view(data)); -} - -template -inline std::optional TryFromString(const std::string& s) { - return TryFromString(std::string_view(s)); -} - -template -inline std::optional TryFromString(const std::u16string& s) { - return TryFromString(std::u16string_view(s)); -} - -template -inline bool TryFromStringWithDefault(const TStringType& s, T& result, const T& def) { - return TryFromString(s.data(), s.size(), result, def); -} - -template -inline bool TryFromStringWithDefault(const char* s, T& result, const T& def) { - return TryFromStringWithDefault(std::string_view(s), result, def); -} - -template -inline bool TryFromStringWithDefault(const TStringType& s, T& result) { - return TryFromStringWithDefault(s, result, T()); -} - -// FromString methods with default value if data is invalid -template -inline T FromString(const TChar* data, const size_t len, const T& def) { - T result; - TryFromString(data, len, result, def); - return result; -} - -template -inline T FromStringWithDefault(const TStringType& s, const T& def) { - return FromString(s.data(), s.size(), def); -} - -template -inline T FromStringWithDefault(const char* s, const T& def) { - return FromStringWithDefault(std::string_view(s), def); -} - -template -inline T FromStringWithDefault(const TStringType& s) { - return FromStringWithDefault(s, T()); -} - -double StrToD(const char* b, char** se); -double StrToD(const char* b, const char* e, char** se); - -template -size_t IntToString(T t, char* buf, size_t len); - -template -inline std::string IntToString(T t) { - static_assert(std::is_arithmetic>::value, "expect std::is_arithmetic>::value"); - - char buf[256]; - - return std::string(buf, IntToString(t, buf, sizeof(buf))); -} - -template -bool TryIntFromString(const TChar* data, size_t len, TInt& result); - -template -inline bool TryIntFromString(const TStringType& s, TInt& result) { - return TryIntFromString(s.data(), s.size(), result); -} - -template -TInt IntFromString(const TChar* str, size_t len); - -template -inline TInt IntFromString(const TChar* str) { - return IntFromString(str, std::char_traits::length(str)); -} - -template -inline TInt IntFromString(const TStringType& str) { - return IntFromString(str.data(), str.size()); -} - -static inline std::string ToString(const std::string_view str) { - return std::string(str); -} - -static inline std::u16string ToWtring(const std::u16string_view wtr) { - return std::u16string(wtr); -} - -static inline std::u32string ToUtf32String(const std::u32string_view wtr) { - return std::u32string(wtr); -} - -template -class TIntStringBuf { -private: - // inline constexprs are not supported by CUDA yet - static constexpr char IntToChar[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - static_assert(1 < radix && radix < 17, "expect 1 < radix && radix < 17"); - - // auxiliary recursive template used to calculate maximum buffer size for the given type - template - struct TBufSizeRec { - // MSVC is tries to evaluate both sides of ?: operator and doesn't break recursion - static constexpr ui32 GetValue() { - if (v == 0) { - return 1; - } - return 1 + TBufSizeRec::value; - } - - static constexpr ui32 value = GetValue(); - }; - -public: - static constexpr ui32 bufferSize = (std::is_signed::value ? 1 : 0) + - ((radix == 2) ? sizeof(T) * 8 : TBufSizeRec::max()>::value); - - template ::value, bool> = true> - explicit constexpr TIntStringBuf(T t) { - Size_ = Convert(t, Buf_, sizeof(Buf_)); -#if __cplusplus >= 202002L // is_constant_evaluated is not supported by CUDA yet - if (std::is_constant_evaluated()) { -#endif - // Init the rest of the array, - // otherwise constexpr copy and move constructors don't work due to uninitialized data access - std::fill(Buf_ + Size_, Buf_ + sizeof(Buf_), '\0'); -#if __cplusplus >= 202002L - } -#endif - } - - constexpr operator std::string_view() const noexcept { - return std::string_view(Buf_, Size_); - } - - constexpr static ui32 Convert(T t, TChar* buf, size_t bufLen) { - bufLen = std::min(bufferSize, bufLen); - if (std::is_signed::value && t < 0) { - Y_ENSURE(bufLen >= 2, std::string_view("not enough room in buffer")); - buf[0] = '-'; - const auto mt = std::make_unsigned_t(-(t + 1)) + std::make_unsigned_t(1); - return ConvertUnsigned(mt, &buf[1], bufLen - 1) + 1; - } else { - return ConvertUnsigned(t, buf, bufLen); - } - } - -private: - constexpr static ui32 ConvertUnsigned(typename std::make_unsigned::type t, TChar* buf, ui32 bufLen) { - Y_ENSURE(bufLen, std::string_view("zero length")); - - if (t == 0) { - *buf = '0'; - return 1; - } - auto* be = buf + bufLen; - ui32 l = 0; - while (t > 0 && be > buf) { - const auto v = t / radix; - const auto r = (radix == 2 || radix == 4 || radix == 8 || radix == 16) ? t & (radix - 1) : t - radix * v; - --be; - if /*constexpr*/ (radix <= 10) { // if constexpr is not supported by CUDA yet - *be = r + '0'; - } else { - *be = IntToChar[r]; - } - ++l; - t = v; - } - Y_ENSURE(!t, std::string_view("not enough room in buffer")); - if (buf != be) { - for (ui32 i = 0; i < l; ++i) { - *buf = *be; - ++buf; - ++be; - } - } - return l; - } - ui32 Size_; - TChar Buf_[bufferSize]; -}; diff --git a/include/ydb-cpp-sdk/util/string/escape.h b/include/ydb-cpp-sdk/util/string/escape.h deleted file mode 100644 index 460096118d7..00000000000 --- a/include/ydb-cpp-sdk/util/string/escape.h +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#include - -template -std::basic_string& EscapeCImpl(const TChar* str, size_t len, std::basic_string&); - -template -std::basic_string& UnescapeCImpl(const TChar* str, size_t len, std::basic_string&); - -template -TChar* UnescapeC(const TChar* str, size_t len, TChar* buf); - -template -static inline std::basic_string& EscapeC(const TChar* str, size_t len, std::basic_string& s) { - return EscapeCImpl(str, len, s); -} - -template -static inline std::basic_string EscapeC(const TChar* str, size_t len) { - std::basic_string s; - return EscapeC(str, len, s); -} - -template -static inline std::basic_string EscapeC(const std::basic_string_view& str) { - return EscapeC(str.data(), str.size()); -} - -template -static inline std::basic_string& UnescapeC(const TChar* str, size_t len, std::basic_string& s) { - return UnescapeCImpl(str, len, s); -} - -template -static inline std::basic_string UnescapeC(const TChar* str, size_t len) { - std::basic_string s; - return UnescapeCImpl(str, len, s); -} - -template -static inline std::basic_string EscapeC(TChar ch) { - return EscapeC(&ch, 1); -} - -template -static inline std::basic_string EscapeC(const TChar* str) { - return EscapeC(str, std::char_traits::length(str)); -} - -std::string& EscapeC(const std::string_view str, std::string& res); -std::u16string& EscapeC(const std::u16string_view str, std::u16string& res); - -// these two need to be methods, because of std::basic_string::Quote implementation -std::string EscapeC(const std::string& str); -std::u16string EscapeC(const std::u16string& str); - -std::string& UnescapeC(const std::string_view str, std::string& res); -std::u16string& UnescapeC(const std::u16string_view str, std::u16string& res); - -std::string UnescapeC(const std::string_view str); -std::u16string UnescapeC(const std::u16string_view wtr); - -/// Returns number of chars in escape sequence. -/// - 0, if begin >= end -/// - 1, if [begin, end) starts with an unescaped char -/// - at least 2 (including '\'), if [begin, end) starts with an escaped symbol -template -size_t UnescapeCCharLen(const TChar* begin, const TChar* end); - -namespace NUtils { - -template -std::basic_string GetQuoteLiteral(); - -template -std::basic_string Quote(std::basic_string_view s) { - return GetQuoteLiteral() + EscapeC(s) + GetQuoteLiteral(); -} - -template -std::basic_string Quote(const std::basic_string& s) { - return Quote(std::basic_string_view(s)); -} - -} diff --git a/include/ydb-cpp-sdk/util/string/subst.h b/include/ydb-cpp-sdk/util/string/subst.h deleted file mode 100644 index 99c88618601..00000000000 --- a/include/ydb-cpp-sdk/util/string/subst.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include - -#include -#include - -/* Replace all occurences of substring `what` with string `with` starting from position `from`. - * - * @param text String to modify. - * @param what Substring to replace. - * @param with Substring to use as replacement. - * @param from Position at with to start replacement. - * - * @return Number of replacements occured. - */ -size_t SubstGlobal(std::string& text, std::string_view what, std::string_view with, size_t from = 0); -size_t SubstGlobal(std::u16string& text, std::u16string_view what, std::u16string_view with, size_t from = 0); -size_t SubstGlobal(std::u32string& text, std::u32string_view what, std::u32string_view with, size_t from = 0); - -/* Replace all occurences of character `what` with character `with` starting from position `from`. - * - * @param text String to modify. - * @param what Character to replace. - * @param with Character to use as replacement. - * @param from Position at with to start replacement. - * - * @return Number of replacements occured. - */ -size_t SubstGlobal(std::string& text, char what, char with, size_t from = 0); -size_t SubstGlobal(std::u16string& text, wchar16 what, wchar16 with, size_t from = 0); -size_t SubstGlobal(std::u32string& text, wchar32 what, wchar32 with, size_t from = 0); - -// TODO(yazevnul): -// - rename `SubstGlobal` to `ReplaceAll` for convenience -// - add `SubstGlobalCopy(std::string_view)` for convenience -// - add `RemoveAll(text, what, from)` as a shortcut for `SubstGlobal(text, what, "", from)` -// - rename file to `replace.h` - -/* Replace all occurences of substring or character `what` with string or character `with` starting from position `from`, and return result string. - * - * @param text String to modify. - * @param what Substring/character to replace. - * @param with Substring/character to use as replacement. - * @param from Position at with to start replacement. - * - * @return Result string - */ -template -Y_WARN_UNUSED_RESULT TStringType SubstGlobalCopy(TStringType result, TPatternType what, TPatternType with, size_t from = 0) { - SubstGlobal(result, what, with, from); - return result; -} diff --git a/include/ydb-cpp-sdk/util/system/atexit.h b/include/ydb-cpp-sdk/util/system/atexit.h deleted file mode 100644 index e11c665d144..00000000000 --- a/include/ydb-cpp-sdk/util/system/atexit.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include - -using TAtExitFunc = void (*)(void*); -using TTraditionalAtExitFunc = void (*)(); - -void AtExit(TAtExitFunc func, void* ctx); -void AtExit(TAtExitFunc func, void* ctx, size_t priority); - -void AtExit(TTraditionalAtExitFunc func); -void AtExit(TTraditionalAtExitFunc func, size_t priority); - -bool ExitStarted(); - -/** - * Generally it's a bad idea to call this method except for some rare cases, - * like graceful python DLL module unload. - * This function is not threadsafe. - * Calls in the moment when application is not terminating - bad idea. - */ -void ManualRunAtExitFinalizers(); diff --git a/include/ydb-cpp-sdk/util/system/error.h b/include/ydb-cpp-sdk/util/system/error.h deleted file mode 100644 index 25393767f6d..00000000000 --- a/include/ydb-cpp-sdk/util/system/error.h +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once - -#include - -#if defined(_win_) - #include - #include - - #undef E_FAIL - #undef ERROR_TIMEOUT - - #if defined(_MSC_VER) - #undef EADDRINUSE - #undef EADDRNOTAVAIL - #undef EAFNOSUPPORT - #undef EALREADY - #undef ECANCELED - #undef ECONNABORTED - #undef ECONNREFUSED - #undef ECONNRESET - #undef EDESTADDRREQ - #undef EHOSTUNREACH - #undef EINPROGRESS - #undef EISCONN - #undef ELOOP - #undef EMSGSIZE - #undef ENETDOWN - #undef ENETRESET - #undef ENETUNREACH - #undef ENOBUFS - #undef ENOPROTOOPT - #undef ENOTCONN - #undef ENOTSOCK - #undef EOPNOTSUPP - #undef EPROTONOSUPPORT - #undef EPROTOTYPE - #undef ETIMEDOUT - #undef EWOULDBLOCK - #undef ENAMETOOLONG - #undef ENOTEMPTY - - #define EWOULDBLOCK WSAEWOULDBLOCK - #define EINPROGRESS WSAEINPROGRESS - #define EALREADY WSAEALREADY - #define ENOTSOCK WSAENOTSOCK - #define EDESTADDRREQ WSAEDESTADDRREQ - #define EMSGSIZE WSAEMSGSIZE - #define EPROTOTYPE WSAEPROTOTYPE - #define ENOPROTOOPT WSAENOPROTOOPT - #define EPROTONOSUPPORT WSAEPROTONOSUPPORT - #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT - #define EOPNOTSUPP WSAEOPNOTSUPP - #define EPFNOSUPPORT WSAEPFNOSUPPORT - #define EAFNOSUPPORT WSAEAFNOSUPPORT - #define EADDRINUSE WSAEADDRINUSE - #define EADDRNOTAVAIL WSAEADDRNOTAVAIL - #define ENETDOWN WSAENETDOWN - #define ENETUNREACH WSAENETUNREACH - #define ENETRESET WSAENETRESET - #define ECONNABORTED WSAECONNABORTED - #define ECONNRESET WSAECONNRESET - #define ENOBUFS WSAENOBUFS - #define EISCONN WSAEISCONN - #define ENOTCONN WSAENOTCONN - #define ESHUTDOWN WSAESHUTDOWN - #define ETOOMANYREFS WSAETOOMANYREFS - #define ETIMEDOUT WSAETIMEDOUT - #define ECONNREFUSED WSAECONNREFUSED - #define ELOOP WSAELOOP - #define ENAMETOOLONG WSAENAMETOOLONG - #define EHOSTDOWN WSAEHOSTDOWN - #define EHOSTUNREACH WSAEHOSTUNREACH - #define ENOTEMPTY WSAENOTEMPTY - #define EPROCLIM WSAEPROCLIM - #define EUSERS WSAEUSERS - #define ESTALE WSAESTALE - #define EREMOTE WSAEREMOTE - #define ECANCELED WSAECANCELLED - #endif - - #define EDQUOT WSAEDQUOT -#endif - -void ClearLastSystemError(); -int LastSystemError(); -void LastSystemErrorText(char* str, size_t size, int code); -const char* LastSystemErrorText(int code); - -inline const char* LastSystemErrorText() { - return LastSystemErrorText(LastSystemError()); -} - -inline void LastSystemErrorText(char* str, size_t size) { - LastSystemErrorText(str, size, LastSystemError()); -} diff --git a/include/ydb-cpp-sdk/util/system/file.h b/include/ydb-cpp-sdk/util/system/file.h deleted file mode 100644 index ed5b3641457..00000000000 --- a/include/ydb-cpp-sdk/util/system/file.h +++ /dev/null @@ -1,231 +0,0 @@ -#pragma once - -#include "fhandle.h" -#include "flock.h" - -#include -#include -#include -#include - -#include -#include - -enum EOpenModeFlag { - OpenExisting = 0, // Opens a file. It fails if the file does not exist. - TruncExisting = 1, // Opens a file and truncates it to zero size. It fails if the file does not exist. - OpenAlways = 2, // Opens a file, always. If a file does not exist, it creates a file. - CreateNew = 3, // Creates a new file. It fails if a specified file exists. - CreateAlways = 4, // Creates a new file, always. If a file exists, it overwrites the file. - MaskCreation = 7, - - RdOnly = 8, // open for reading only - WrOnly = 16, // open for writing only - RdWr = 24, // open for reading and writing - MaskRW = 24, - - Seq = 0x20, // file access is primarily sequential (POSIX_FADV_SEQUENTIAL) - Direct = 0x40, // file is being opened with no system caching (Does not work as intended! See implementation) - Temp = 0x80, // avoid writing data back to disk if sufficient cache memory is available (no op for linux) - ForAppend = 0x100, // write appends data to the end of file (O_APPEND) - Transient = 0x200, // actually, temporary file - 'delete on close' for windows, unlink after creation for unix - NoReuse = 0x400, // no second access expected (POSIX_FADV_NOREUSE) - CloseOnExec = 0x800, // set close-on-exec right at open (O_CLOEXEC) - DirectAligned = 0x1000, // file is actually being opened with no system caching (may require buffer alignment) (O_DIRECT) - Sync = 0x2000, // no write call will return before the data is transferred to the disk (O_SYNC) - NoReadAhead = 0x4000, // no sequential access expected, opposite for Seq (POSIX_FADV_RANDOM) - - AXOther = 0x00010000, - AWOther = 0x00020000, - AROther = 0x00040000, - AXGroup = 0x00100000, - AWGroup = 0x00200000, - ARGroup = 0x00400000, - AXUser = 0x01000000, - AWUser = 0x02000000, - ARUser = 0x04000000, - AX = AXUser | AXGroup | AXOther, - AW = AWUser | AWGroup, - AR = ARUser | ARGroup | AROther, - ARW = AR | AW, - AMask = 0x0FFF0000, -}; - -Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag); -Y_DECLARE_OPERATORS_FOR_FLAGS(EOpenMode); - -std::string DecodeOpenMode(ui32 openMode); - -enum SeekDir { - sSet = 0, - sCur = 1, - sEnd = 2, -}; - -class TFileHandle: public TNonCopyable { -public: - constexpr TFileHandle() = default; - - /// Warning: takes ownership of fd, so closes it in destructor. - inline TFileHandle(FHANDLE fd) noexcept - : Fd_(fd) - { - } - - inline TFileHandle(TFileHandle&& other) noexcept - : Fd_(other.Fd_) - { - other.Fd_ = INVALID_FHANDLE; - } - - TFileHandle(const char* fName, EOpenMode oMode) noexcept; - TFileHandle(const std::string& fName, EOpenMode oMode) noexcept; - TFileHandle(const std::filesystem::path& path, EOpenMode oMode) noexcept; - - inline ~TFileHandle() { - Close(); - } - - bool Close() noexcept; - - inline FHANDLE Release() noexcept { - FHANDLE ret = Fd_; - Fd_ = INVALID_FHANDLE; - return ret; - } - - inline void Swap(TFileHandle& r) noexcept { - DoSwap(Fd_, r.Fd_); - } - - inline operator FHANDLE() const noexcept { - return Fd_; - } - - inline bool IsOpen() const noexcept { - return Fd_ != INVALID_FHANDLE; - } - - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; - - i64 Seek(i64 offset, SeekDir origin) noexcept; - bool Resize(i64 length) noexcept; - bool Reserve(i64 length) noexcept; - bool FallocateNoResize(i64 length) noexcept; - bool ShrinkToFit() noexcept; - bool Flush() noexcept; - //flush data only, without file metadata - bool FlushData() noexcept; - i32 Read(void* buffer, ui32 byteCount) noexcept; - i32 Write(const void* buffer, ui32 byteCount) noexcept; - i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept; - i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept; - int Flock(int op) noexcept; - - FHANDLE Duplicate() const noexcept; - int Duplicate2Posix(int dstHandle) const noexcept; - - //dup2 - like semantics, return true on success - bool LinkTo(const TFileHandle& fh) const noexcept; - - //very low-level methods - bool SetDirect(); - void ResetDirect(); - - /* Manual file cache management, length = 0 means "as much as possible" */ - - //measure amount of cached data in bytes, returns -1 if failed - i64 CountCache(i64 offset = 0, i64 length = 0) const noexcept; - //read data into cache and optionally wait for completion - void PrefetchCache(i64 offset = 0, i64 length = 0, bool wait = true) const noexcept; - //remove clean and unused data from cache - void EvictCache(i64 offset = 0, i64 length = 0) const noexcept; - //flush unwritten data in this range and optionally wait for completion - bool FlushCache(i64 offset = 0, i64 length = 0, bool wait = true) noexcept; - -private: - FHANDLE Fd_ = INVALID_FHANDLE; -}; - -class TFile { -public: - TFile(); - /// Takes ownership of handle, so closes it when the last holder of descriptor dies. - explicit TFile(FHANDLE fd); - TFile(FHANDLE fd, const std::string& fname); - TFile(const char* fName, EOpenMode oMode); - TFile(const std::string& fName, EOpenMode oMode); - TFile(const std::filesystem::path& path, EOpenMode oMode); - ~TFile(); - - void Close(); - - const std::string& GetName() const noexcept; - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; - bool IsOpen() const noexcept; - FHANDLE GetHandle() const noexcept; - - i64 Seek(i64 offset, SeekDir origin); - void Resize(i64 length); - void Reserve(i64 length); - void FallocateNoResize(i64 length); - void ShrinkToFit(); - void Flush(); - void FlushData(); - - void LinkTo(const TFile& f) const; - TFile Duplicate() const; - - // Reads up to 1 GB without retrying, returns -1 on error - i32 RawRead(void* buf, size_t len); - // Reads up to 1 GB without retrying, throws on error - size_t ReadOrFail(void* buf, size_t len); - // Retries incomplete reads until EOF, throws on error - size_t Read(void* buf, size_t len); - // Reads exactly len bytes, throws on premature EOF or error - void Load(void* buf, size_t len); - - // Retries incomplete writes, will either write len bytes or throw - void Write(const void* buf, size_t len); - - // Retries incomplete reads until EOF, throws on error - size_t Pread(void* buf, size_t len, i64 offset) const; - // Single pread call - i32 RawPread(void* buf, ui32 len, i64 offset) const; - // Reads exactly len bytes, throws on premature EOF or error - void Pload(void* buf, size_t len, i64 offset) const; - - // Retries incomplete writes, will either write len bytes or throw - void Pwrite(const void* buf, size_t len, i64 offset) const; - - void Flock(int op); - - //do not use, their meaning very platform-dependant - void SetDirect(); - void ResetDirect(); - - /* Manual file cache management, length = 0 means "as much as possible" */ - - //measure amount of cached data in bytes, returns -1 if failed - i64 CountCache(i64 offset = 0, i64 length = 0) const noexcept; - //read data into cache and optionally wait for completion - void PrefetchCache(i64 offset = 0, i64 length = 0, bool wait = true) const noexcept; - //remove clean and unused data from cache, incomplete pages could stay - void EvictCache(i64 offset = 0, i64 length = 0) const noexcept; - //flush unwritten data in this range and optionally wait for completion - void FlushCache(i64 offset = 0, i64 length = 0, bool wait = true); - - static TFile Temporary(const std::string& prefix); - static TFile ForAppend(const std::string& path); - -private: - class TImpl; - TSimpleIntrusivePtr Impl_; -}; - -TFile Duplicate(FILE*); -TFile Duplicate(int); - -bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept; diff --git a/include/ydb-cpp-sdk/util/system/progname.h b/include/ydb-cpp-sdk/util/system/progname.h deleted file mode 100644 index 9f92d756675..00000000000 --- a/include/ydb-cpp-sdk/util/system/progname.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -void SetProgramName(const char* argv0); - -#define SAVE_PROGRAM_NAME \ - do { \ - SetProgramName(argv[0]); \ - } while (0) - -/// guaranted return the same immutable instance of std::string -const std::string& GetProgramName(); diff --git a/include/ydb-cpp-sdk/util/system/src_location.h b/include/ydb-cpp-sdk/util/system/src_location.h deleted file mode 100644 index 3abdaff6c4f..00000000000 --- a/include/ydb-cpp-sdk/util/system/src_location.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include - -struct TSourceLocation { - constexpr TSourceLocation(const std::string_view f, int l) noexcept - : File(f) - , Line(l) - { - } - - std::string_view File; - int Line; -}; - -// __SOURCE_FILE__ should be used instead of __FILE__ -#if !defined(__NVCC__) - #define __SOURCE_FILE__ (__SOURCE_FILE_IMPL__.As()) -#else - #define __SOURCE_FILE__ (__SOURCE_FILE_IMPL__.template As()) -#endif - -#define __LOCATION__ ::TSourceLocation(__SOURCE_FILE__, __LINE__) diff --git a/include/ydb-cpp-sdk/util/system/type_name.h b/include/ydb-cpp-sdk/util/system/type_name.h deleted file mode 100644 index b47b8b16eea..00000000000 --- a/include/ydb-cpp-sdk/util/system/type_name.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include -#include - -// Consider using TypeName function family. -std::string CppDemangle(const std::string& name); - -// TypeName function family return human readable type name. - -std::string TypeName(const std::type_info& typeInfo); -std::string TypeName(const std::type_index& typeInfo); - -// Works for types known at compile-time -// (thus, does not take any inheritance into account) -template -inline std::string TypeName() { - return TypeName(typeid(T)); -} - -// Works for dynamic type, including complex class hierarchies. -// Also, distinguishes between T, T*, T const*, T volatile*, T const volatile*, -// but not T and T const. -template -inline std::string TypeName(const T& t) { - return TypeName(typeid(t)); -} diff --git a/include/ydb-cpp-sdk/util/system/unaligned_mem.h b/include/ydb-cpp-sdk/util/system/unaligned_mem.h deleted file mode 100644 index 64e14592076..00000000000 --- a/include/ydb-cpp-sdk/util/system/unaligned_mem.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -// The following code used to have smart tricks assuming that unaligned reads and writes are OK on x86. This assumption -// is wrong because compiler may emit alignment-sensitive x86 instructions e.g. movaps. See IGNIETFERRO-735. - -template -inline T ReadUnaligned(const void* from) noexcept { - T ret; - memcpy(&ret, from, sizeof(T)); - return ret; -} - -// std::remove_reference_t for non-deduced context to prevent such code to blow below: -// ui8 first = f(); ui8 second = g(); -// WriteUnaligned(to, first - second) (int will be deduced) -template -inline void WriteUnaligned(void* to, const std::remove_reference_t& t) noexcept { - memcpy(to, &t, sizeof(T)); -} - -template -class TUnalignedMemoryIterator { -public: - inline TUnalignedMemoryIterator(const void* buf, size_t len) - : C_((const unsigned char*)buf) - , E_(C_ + len) - , L_(E_ - (len % Align)) - { - Y_FAKE_READ(buf); - } - - inline bool AtEnd() const noexcept { - return C_ == L_; - } - - inline T Cur() const noexcept { - Y_ASSERT(C_ < L_ || sizeof(T) < Align); - return ::ReadUnaligned(C_); - } - - inline T Next() noexcept { - T ret(Cur()); - - C_ += sizeof(T); - - return ret; - } - - inline const unsigned char* Last() const noexcept { - return C_; - } - - inline size_t Left() const noexcept { - return E_ - C_; - } - -private: - const unsigned char* C_; - const unsigned char* E_; - const unsigned char* L_; -}; diff --git a/include/ydb-cpp-sdk/util/system/winint.h b/include/ydb-cpp-sdk/util/system/winint.h deleted file mode 100644 index eaf3fb163bc..00000000000 --- a/include/ydb-cpp-sdk/util/system/winint.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -/* - * WARN: - * including this header does not make a lot of sense. - * You should just #include all necessary headers from Windows SDK, - * and then #include in order to undefine some common macros. - */ - -#include - -#if defined(_win_) - #include -#endif - -#include diff --git a/include/ydb-cpp-sdk/util/thread/pool.h b/include/ydb-cpp-sdk/util/thread/pool.h deleted file mode 100644 index ce933a462c6..00000000000 --- a/include/ydb-cpp-sdk/util/thread/pool.h +++ /dev/null @@ -1,390 +0,0 @@ -#pragma once - -#include "factory.h" - -#include -#include -#include -#include - -#include -#include - -class TDuration; - -struct IObjectInQueue { - virtual ~IObjectInQueue() = default; - - /** - * Supposed to be implemented by user, to define jobs processed - * in multiple threads. - * - * @param threadSpecificResource is nullptr by default. But if you override - * IThreadPool::CreateThreadSpecificResource, then result of - * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource - * parameter. - */ - virtual void Process(void* threadSpecificResource) = 0; -}; - -/** - * Mighty class to add 'Pool' method to derived classes. - * Useful only for creators of new queue classes. - */ -class TThreadFactoryHolder { -public: - TThreadFactoryHolder() noexcept; - - inline TThreadFactoryHolder(IThreadFactory* pool) noexcept - : Pool_(pool) - { - } - - inline ~TThreadFactoryHolder() = default; - - inline IThreadFactory* Pool() const noexcept { - return Pool_; - } - -private: - IThreadFactory* Pool_; -}; - -class TThreadPoolException: public yexception { -}; - -template -class TThrFuncObj: public IObjectInQueue { -public: - TThrFuncObj(const T& func) - : Func(func) - { - } - - TThrFuncObj(T&& func) - : Func(std::move(func)) - { - } - - void Process(void*) override { - THolder self(this); - Func(); - } - -private: - T Func; -}; - -template -IObjectInQueue* MakeThrFuncObj(T&& func) { - return new TThrFuncObj>>(std::forward(func)); -} - -struct TThreadPoolParams { - bool Catching_ = true; - bool Blocking_ = false; - IThreadFactory* Factory_ = SystemThreadFactory(); - std::string ThreadName_; - bool EnumerateThreads_ = false; - - using TSelf = TThreadPoolParams; - - TThreadPoolParams() { - } - - TThreadPoolParams(IThreadFactory* factory) - : Factory_(factory) - { - } - - TThreadPoolParams(const std::string& name) { - SetThreadName(name); - } - - TThreadPoolParams(const char* name) { - SetThreadName(name); - } - - TSelf& SetCatching(bool val) { - Catching_ = val; - return *this; - } - - TSelf& SetBlocking(bool val) { - Blocking_ = val; - return *this; - } - - TSelf& SetFactory(IThreadFactory* factory) { - Factory_ = factory; - return *this; - } - - TSelf& SetThreadName(const std::string& name) { - ThreadName_ = name; - EnumerateThreads_ = false; - return *this; - } - - TSelf& SetThreadNamePrefix(const std::string& prefix) { - ThreadName_ = prefix; - EnumerateThreads_ = true; - return *this; - } -}; - -/** - * A queue processed simultaneously by several threads - */ -class IThreadPool: public IThreadFactory, public TNonCopyable { -public: - using TParams = TThreadPoolParams; - - ~IThreadPool() override = default; - - /** - * Safe versions of Add*() functions. Behave exactly like as non-safe - * version of Add*(), but use exceptions instead returning false - */ - void SafeAdd(IObjectInQueue* obj); - - template - void SafeAddFunc(T&& func) { - Y_ENSURE_EX(AddFunc(std::forward(func)), TThreadPoolException() << "can not add function to queue"); - } - - void SafeAddAndOwn(THolder obj); - - /** - * Add object to queue, run obj->Proccess in other threads. - * Obj is not deleted after execution - * @return true of obj is successfully added to queue - * @return false if queue is full or shutting down - */ - virtual bool Add(IObjectInQueue* obj) Y_WARN_UNUSED_RESULT = 0; - - template - Y_WARN_UNUSED_RESULT bool AddFunc(T&& func) { - THolder wrapper(MakeThrFuncObj(std::forward(func))); - bool added = Add(wrapper.Get()); - if (added) { - Y_UNUSED(wrapper.Release()); - } - return added; - } - - bool AddAndOwn(THolder 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 */ - virtual void Stop() noexcept = 0; - /** Number of tasks currently in queue */ - virtual size_t Size() const noexcept = 0; - -public: - /** - * RAII wrapper for Create/DestroyThreadSpecificResource. - * Useful only for implementers of new IThreadPool queues. - */ - class TTsr { - public: - inline TTsr(IThreadPool* q) - : Q_(q) - , Data_(Q_->CreateThreadSpecificResource()) - { - } - - inline ~TTsr() { - try { - Q_->DestroyThreadSpecificResource(Data_); - } catch (...) { - // ¯\_(ツ)_/¯ - } - } - - inline operator void*() noexcept { - return Data_; - } - - private: - IThreadPool* Q_; - void* Data_; - }; - - /** - * CreateThreadSpecificResource and DestroyThreadSpecificResource - * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, - * not by user of IThreadPool interface. - * Created resource is passed to IObjectInQueue::Proccess function. - */ - virtual void* CreateThreadSpecificResource() { - return nullptr; - } - - virtual void DestroyThreadSpecificResource(void* resource) { - if (resource != nullptr) { - Y_ASSERT(resource == nullptr); - } - } - -private: - IThread* DoCreate() override; -}; - -/** - * Single-threaded implementation of IThreadPool, process tasks in same thread when - * added. - * Can be used to remove multithreading. - */ -class TFakeThreadPool: public IThreadPool { -public: - bool Add(IObjectInQueue* pObj) override Y_WARN_UNUSED_RESULT { - TTsr tsr(this); - pObj->Process(tsr); - - return true; - } - - void Start(size_t, size_t = 0) override { - } - - void Stop() noexcept override { - } - - size_t Size() const noexcept override { - return 0; - } -}; - -class TThreadPoolBase: public IThreadPool, public TThreadFactoryHolder { -public: - TThreadPoolBase(const TParams& params); - -protected: - TParams Params; -}; - -/** queue processed by fixed size thread pool */ -class TThreadPool: public TThreadPoolBase { -public: - TThreadPool(const TParams& params = {}); - ~TThreadPool() override; - - bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** - * @param queueSizeLimit means "unlimited" when = 0 - * @param threadCount means "single thread" when = 0 - */ - void Start(size_t threadCount, size_t queueSizeLimit = 0) override; - void Stop() noexcept override; - size_t Size() const noexcept override; - size_t GetThreadCountExpected() const noexcept; - size_t GetThreadCountReal() const noexcept; - size_t GetMaxQueueSize() const noexcept; - -private: - class TImpl; - THolder Impl_; -}; - -/** - * Always create new thread for new task, when all existing threads are busy. - * Maybe dangerous, number of threads is not limited. - */ -class TAdaptiveThreadPool: public TThreadPoolBase { -public: - TAdaptiveThreadPool(const TParams& params = {}); - ~TAdaptiveThreadPool() override; - - /** - * If working thread waits task too long (more then interval parameter), - * then the thread would be killed. Default value - infinity, all created threads - * waits for new task forever, before Stop. - */ - void SetMaxIdleTime(TDuration interval); - - bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** @param thrnum, @param maxque are ignored */ - void Start(size_t thrnum = 0, size_t maxque = 0) override; - void Stop() noexcept override; - size_t Size() const noexcept override; - -private: - class TImpl; - THolder Impl_; -}; - -/** Behave like TThreadPool or TAdaptiveThreadPool, choosen by thrnum parameter of Start() */ -class TSimpleThreadPool: public TThreadPoolBase { -public: - TSimpleThreadPool(const TParams& params = {}); - ~TSimpleThreadPool() override; - - bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** - * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small - * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool - */ - void Start(size_t thrnum, size_t maxque = 0) override; - void Stop() noexcept override; - size_t Size() const noexcept override; - -private: - THolder Slave_; -}; - -/** - * Helper to override virtual functions Create/DestroyThreadSpecificResource - * from IThreadPool and implement them using functions with same name from - * pointer to TSlave. - */ -template -class TThreadPoolBinder: public TQueueType { -public: - inline TThreadPoolBinder(TSlave* slave) - : Slave_(slave) - { - } - - template - inline TThreadPoolBinder(TSlave* slave, Args&&... args) - : TQueueType(std::forward(args)...) - , Slave_(slave) - { - } - - inline TThreadPoolBinder(TSlave& slave) - : Slave_(&slave) - { - } - - ~TThreadPoolBinder() override { - try { - this->Stop(); - } catch (...) { - // ¯\_(ツ)_/¯ - } - } - - void* CreateThreadSpecificResource() override { - return Slave_->CreateThreadSpecificResource(); - } - - void DestroyThreadSpecificResource(void* resource) override { - Slave_->DestroyThreadSpecificResource(resource); - } - -private: - TSlave* Slave_; -}; - -inline void Delete(THolder q) { - if (q.Get()) { - q->Stop(); - } -} - -/** - * Creates and starts TThreadPool if threadsCount > 1, or TFakeThreadPool otherwise - * You could specify blocking and catching modes for TThreadPool only - */ -std::unique_ptr CreateThreadPool(size_t threadCount, size_t queueSizeLimit = 0, const IThreadPool::TParams& params = {}); diff --git a/library/cpp/CMakeLists.txt b/library/cpp/CMakeLists.txt new file mode 100644 index 00000000000..3760364ac93 --- /dev/null +++ b/library/cpp/CMakeLists.txt @@ -0,0 +1,63 @@ +add_subdirectory(blockcodecs) +add_subdirectory(build_info) +add_subdirectory(cache) +add_subdirectory(case_insensitive_string) +add_subdirectory(cgiparam) +add_subdirectory(charset) +add_subdirectory(colorizer) +add_subdirectory(containers/disjoint_interval_tree) +add_subdirectory(containers/intrusive_rb_tree) +add_subdirectory(containers/paged_vector) +add_subdirectory(containers/stack_vector) +add_subdirectory(coroutine/engine) +add_subdirectory(coroutine/listener) +add_subdirectory(cppparser) +add_subdirectory(dbg_output) +add_subdirectory(diff) +add_subdirectory(digest/lower_case) +add_subdirectory(digest/md5) +add_subdirectory(digest/murmur) +add_subdirectory(getopt) +add_subdirectory(http/fetch) +add_subdirectory(http/io) +add_subdirectory(http/misc) +add_subdirectory(http/server) +add_subdirectory(http/simple) +add_subdirectory(iterator) +add_subdirectory(json) +add_subdirectory(lcs) +add_subdirectory(logger) +add_subdirectory(mime/types) +add_subdirectory(monlib/dynamic_counters) +add_subdirectory(monlib/encode) +add_subdirectory(monlib/exception) +add_subdirectory(monlib/metrics) +add_subdirectory(monlib/service) +add_subdirectory(openssl/holders) +add_subdirectory(openssl/init) +add_subdirectory(openssl/io) +add_subdirectory(openssl/method) +add_subdirectory(resource) +add_subdirectory(streams/brotli) +add_subdirectory(streams/bzip2) +add_subdirectory(streams/lzma) +add_subdirectory(streams/zstd) +add_subdirectory(string_utils/quote) +add_subdirectory(string_utils/relaxed_escaper) +add_subdirectory(string_utils/scan) +add_subdirectory(string_utils/url) +add_subdirectory(svnversion) +add_subdirectory(terminate_handler) +add_subdirectory(testing) +add_subdirectory(threading/chunk_queue) +add_subdirectory(threading/equeue) +add_subdirectory(threading/future) +add_subdirectory(threading/light_rw_lock) +add_subdirectory(unicode/normalization) +add_subdirectory(uri) +add_subdirectory(yson) +add_subdirectory(yt) + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") + add_subdirectory(cpuid_check) +endif() diff --git a/library/cpp/blockcodecs/CMakeLists.txt b/library/cpp/blockcodecs/CMakeLists.txt new file mode 100644 index 00000000000..2982c27142c --- /dev/null +++ b/library/cpp/blockcodecs/CMakeLists.txt @@ -0,0 +1,165 @@ +_ydb_sdk_add_library(blockcodecs-core) +target_link_libraries(blockcodecs-core + PUBLIC + yutil +) +target_sources(blockcodecs-core PRIVATE + core/codecs.cpp + core/stream.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-core) + + +_ydb_sdk_add_library(blockcodecs-codecs-brotli INTERFACE) +add_global_library_for(blockcodecs-codecs-brotli.global blockcodecs-codecs-brotli) +target_link_libraries(blockcodecs-codecs-brotli.global + PRIVATE + yutil + Brotli::enc + Brotli::dec + blockcodecs-core +) +target_sources(blockcodecs-codecs-brotli.global + PRIVATE + codecs/brotli/brotli.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-brotli.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-brotli) + + +_ydb_sdk_add_library(blockcodecs-codecs-bzip INTERFACE) +add_global_library_for(blockcodecs-codecs-bzip.global blockcodecs-codecs-bzip) +target_link_libraries(blockcodecs-codecs-bzip.global + PRIVATE + yutil + BZip2::BZip2 + blockcodecs-core +) +target_sources(blockcodecs-codecs-bzip.global + PRIVATE + codecs/bzip/bzip.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-bzip.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-bzip) + + +_ydb_sdk_add_library(blockcodecs-codecs-fastlz INTERFACE) +add_global_library_for(blockcodecs-codecs-fastlz.global blockcodecs-codecs-fastlz) +target_link_libraries(blockcodecs-codecs-fastlz.global + PRIVATE + yutil + FastLZ + blockcodecs-core +) +target_sources(blockcodecs-codecs-fastlz.global + PRIVATE + codecs/fastlz/fastlz.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-fastlz.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-fastlz) + + +_ydb_sdk_add_library(blockcodecs-codecs-lz4 INTERFACE) +add_global_library_for(blockcodecs-codecs-lz4.global blockcodecs-codecs-lz4) +target_link_libraries(blockcodecs-codecs-lz4.global + PRIVATE + yutil + LZ4::LZ4 + blockcodecs-core +) +target_sources(blockcodecs-codecs-lz4.global + PRIVATE + codecs/lz4/lz4.cpp +) +target_compile_options(blockcodecs-codecs-lz4.global + PRIVATE + -Wno-deprecated +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-lz4.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-lz4) + + +_ydb_sdk_add_library(blockcodecs-codecs-lzma INTERFACE) +add_global_library_for(blockcodecs-codecs-lzma.global blockcodecs-codecs-lzma) +target_link_libraries(blockcodecs-codecs-lzma.global + PRIVATE + yutil + contrib-libs-lzmasdk + blockcodecs-core +) +target_sources(blockcodecs-codecs-lzma.global + PRIVATE + codecs/lzma/lzma.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-lzma.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-lzma) + + +_ydb_sdk_add_library(blockcodecs-codecs-snappy INTERFACE) +add_global_library_for(blockcodecs-codecs-snappy.global blockcodecs-codecs-snappy) +target_link_libraries(blockcodecs-codecs-snappy.global + PRIVATE + yutil + Snappy::snappy + blockcodecs-core +) +target_sources(blockcodecs-codecs-snappy.global + PRIVATE + codecs/snappy/snappy.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-snappy.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-snappy) + + +_ydb_sdk_add_library(blockcodecs-codecs-zlib INTERFACE) +add_global_library_for(blockcodecs-codecs-zlib.global blockcodecs-codecs-zlib) +target_link_libraries(blockcodecs-codecs-zlib.global + PRIVATE + yutil + ZLIB::ZLIB + blockcodecs-core +) +target_sources(blockcodecs-codecs-zlib.global + PRIVATE + codecs/zlib/zlib.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-zlib.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-zlib) + + +_ydb_sdk_add_library(blockcodecs-codecs-zstd INTERFACE) +add_global_library_for(blockcodecs-codecs-zstd.global blockcodecs-codecs-zstd) +target_link_libraries(blockcodecs-codecs-zstd.global + PRIVATE + yutil + ZSTD::ZSTD + blockcodecs-core +) +target_sources(blockcodecs-codecs-zstd.global + PRIVATE + codecs/zstd/zstd.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-zstd.global) +_ydb_sdk_install_targets(TARGETS blockcodecs-codecs-zstd) + + +_ydb_sdk_add_library(blockcodecs) +target_link_libraries(blockcodecs + PUBLIC + yutil + blockcodecs-core + blockcodecs-codecs-brotli + blockcodecs-codecs-bzip + blockcodecs-codecs-fastlz + blockcodecs-codecs-lz4 + blockcodecs-codecs-lzma + blockcodecs-codecs-snappy + blockcodecs-codecs-zlib + blockcodecs-codecs-zstd +) +target_sources(blockcodecs + PRIVATE + codecs.cpp + stream.cpp +) +_ydb_sdk_install_targets(TARGETS blockcodecs) diff --git a/library/cpp/blockcodecs/README.md b/library/cpp/blockcodecs/README.md new file mode 100644 index 00000000000..417917a475b --- /dev/null +++ b/library/cpp/blockcodecs/README.md @@ -0,0 +1,23 @@ +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). + +Using codec plugins +=================== +If you don't want your code to bloat from unused codecs, you can use the small version of the +library: `library/cpp/blockcodecs/core`. In that case, you need to manually set `PEERDIR()`s to +needed codecs (i.e. `PEERDIR(library/cpp/blockcodecs/codecs/lzma)`). diff --git a/src/library/blockcodecs/codecs.cpp b/library/cpp/blockcodecs/codecs.cpp similarity index 100% rename from src/library/blockcodecs/codecs.cpp rename to library/cpp/blockcodecs/codecs.cpp diff --git a/library/cpp/blockcodecs/codecs.h b/library/cpp/blockcodecs/codecs.h new file mode 100644 index 00000000000..fd499b54b0d --- /dev/null +++ b/library/cpp/blockcodecs/codecs.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/library/cpp/blockcodecs/codecs/brotli/brotli.cpp b/library/cpp/blockcodecs/codecs/brotli/brotli.cpp new file mode 100644 index 00000000000..e523310d0e7 --- /dev/null +++ b/library/cpp/blockcodecs/codecs/brotli/brotli.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +#include +#include + +using namespace NBlockCodecs; + +namespace { + struct TBrotliCodec : public TAddLengthCodec { + static constexpr int BEST_QUALITY = 11; + + inline TBrotliCodec(ui32 level) + : Quality(level) + , MyName(TStringBuf("brotli_") + ToString(level)) + { + } + + static inline size_t DoMaxCompressedLength(size_t l) noexcept { + return BrotliEncoderMaxCompressedSize(l); + } + + inline size_t DoCompress(const TData& in, void* out) const { + size_t resultSize = MaxCompressedLength(in); + auto result = BrotliEncoderCompress( + /*quality*/ Quality, + /*window*/ BROTLI_DEFAULT_WINDOW, + /*mode*/ BrotliEncoderMode::BROTLI_MODE_GENERIC, + /*input_size*/ in.size(), + /*input_buffer*/ (const unsigned char*)(in.data()), + /*encoded_size*/ &resultSize, + /*encoded_buffer*/ static_cast(out)); + if (result != BROTLI_TRUE) { + ythrow yexception() << "internal brotli error during compression"; + } + + return resultSize; + } + + inline void DoDecompress(const TData& in, void* out, size_t dsize) const { + size_t decoded = dsize; + auto result = BrotliDecoderDecompress(in.size(), (const unsigned char*)in.data(), &decoded, static_cast(out)); + if (result != BROTLI_DECODER_RESULT_SUCCESS) { + ythrow yexception() << "internal brotli error during decompression"; + } else if (decoded != dsize) { + ythrow TDecompressError(dsize, decoded); + } + } + + TStringBuf Name() const noexcept override { + return MyName; + } + + const int Quality = BEST_QUALITY; + const TString MyName; + }; + + struct TBrotliRegistrar { + TBrotliRegistrar() { + for (int i = 1; i <= TBrotliCodec::BEST_QUALITY; ++i) { + RegisterCodec(MakeHolder(i)); + } + } + }; + const TBrotliRegistrar Registrar{}; +} diff --git a/src/library/blockcodecs/codecs/bzip/bzip.cpp b/library/cpp/blockcodecs/codecs/bzip/bzip.cpp similarity index 83% rename from src/library/blockcodecs/codecs/bzip/bzip.cpp rename to library/cpp/blockcodecs/codecs/bzip/bzip.cpp index b6bbbfd99c5..2aa0d3065f0 100644 --- a/src/library/blockcodecs/codecs/bzip/bzip.cpp +++ b/library/cpp/blockcodecs/codecs/bzip/bzip.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include @@ -10,7 +10,7 @@ namespace { struct TBZipCodec: public TAddLengthCodec { inline TBZipCodec(int level) : Level(level) - , MyName("bzip2-" + std::to_string(Level)) + , MyName("bzip2-" + ToString(Level)) { } @@ -19,7 +19,7 @@ namespace { return in * 2 + 128; } - std::string_view Name() const noexcept override { + TStringBuf Name() const noexcept override { return MyName; } @@ -47,7 +47,7 @@ namespace { } const int Level; - const std::string MyName; + const TString MyName; }; struct TBZipRegistrar { diff --git a/src/library/blockcodecs/codecs/fastlz/fastlz.cpp b/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp similarity index 76% rename from src/library/blockcodecs/codecs/fastlz/fastlz.cpp rename to library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp index c391888c579..c675b7fac54 100644 --- a/src/library/blockcodecs/codecs/fastlz/fastlz.cpp +++ b/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include @@ -9,7 +9,7 @@ using namespace NBlockCodecs; namespace { struct TFastLZCodec: public TAddLengthCodec { inline TFastLZCodec(int level) - : MyName("fastlz-" + std::to_string(level)) + : MyName("fastlz-" + ToString(level)) , Level(level) { } @@ -18,7 +18,7 @@ namespace { return Max(in + in / 20, 128); } - std::string_view Name() const noexcept override { + TStringBuf Name() const noexcept override { return MyName; } @@ -34,11 +34,11 @@ namespace { const int ret = fastlz_decompress(in.data(), in.size(), out, len); if (ret < 0 || (size_t)ret != len) { - ythrow TDataError() << std::string_view("can not decompress"); + ythrow TDataError() << TStringBuf("can not decompress"); } } - const std::string MyName; + const TString MyName; const int Level; }; diff --git a/src/library/blockcodecs/codecs/lz4/lz4.cpp b/library/cpp/blockcodecs/codecs/lz4/lz4.cpp similarity index 77% rename from src/library/blockcodecs/codecs/lz4/lz4.cpp rename to library/cpp/blockcodecs/codecs/lz4/lz4.cpp index 2b93b9f9d1e..c3876bd68bb 100644 --- a/src/library/blockcodecs/codecs/lz4/lz4.cpp +++ b/library/cpp/blockcodecs/codecs/lz4/lz4.cpp @@ -1,8 +1,6 @@ -#include -#include -#include - -#include +#include +#include +#include #include #include @@ -26,8 +24,8 @@ namespace { return LZ4_compress_default(in.data(), (char*)buf, in.size(), LZ4_compressBound(in.size())); } - inline std::string CPrefix() { - return "fast" + std::to_string(Memory); + inline TString CPrefix() { + return "fast" + ToString(Memory); } const int Memory; @@ -38,7 +36,7 @@ namespace { return LZ4_compress_HC(in.data(), (char*)buf, in.size(), LZ4_compressBound(in.size()), 0); } - static inline std::string CPrefix() { + static inline TString CPrefix() { return "hc"; } }; @@ -51,8 +49,8 @@ namespace { } } - static inline std::string_view DPrefix() { - return std::string_view("fast"); + static inline TStringBuf DPrefix() { + return TStringBuf("fast"); } }; @@ -64,30 +62,30 @@ namespace { } } - static inline std::string_view DPrefix() { - return std::string_view("safe"); + static inline TStringBuf DPrefix() { + return TStringBuf("safe"); } }; template struct TLz4Codec: public TAddLengthCodec>, public TLz4Base, public TC, public TD { inline TLz4Codec() - : MyName(TStringBuilder() << "lz4-" << TC::CPrefix() << "-" << TD::DPrefix()) + : MyName("lz4-" + TC::CPrefix() + "-" + TD::DPrefix()) { } template inline TLz4Codec(const T& t) : TC(t) - , MyName(TStringBuilder() << "lz4-" << TC::CPrefix() << "-" << TD::DPrefix()) + , MyName("lz4-" + TC::CPrefix() + "-" + TD::DPrefix()) { } - std::string_view Name() const noexcept override { + TStringBuf Name() const noexcept override { return MyName; } - const std::string MyName; + const TString MyName; }; struct TLz4Registrar { diff --git a/library/cpp/blockcodecs/codecs/lzma/lzma.cpp b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp new file mode 100644 index 00000000000..6c8d5fded42 --- /dev/null +++ b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp @@ -0,0 +1,74 @@ +#include +#include +#include + +#include + +using namespace NBlockCodecs; + +namespace { + struct TLzmaCodec: public TAddLengthCodec { + inline TLzmaCodec(int level) + : Level(level) + , MyName("lzma-" + ToString(Level)) + { + } + + static inline size_t DoMaxCompressedLength(size_t in) noexcept { + return Max(in + in / 20, 128) + LZMA_PROPS_SIZE; + } + + TStringBuf Name() const noexcept override { + return MyName; + } + + inline size_t DoCompress(const TData& in, void* buf) const { + unsigned char* props = (unsigned char*)buf; + unsigned char* data = props + LZMA_PROPS_SIZE; + size_t destLen = Max(); + size_t outPropsSize = LZMA_PROPS_SIZE; + + const int ret = LzmaCompress(data, &destLen, (const unsigned char*)in.data(), in.size(), props, &outPropsSize, Level, 0, -1, -1, -1, -1, -1); + + if (ret != SZ_OK) { + ythrow TCompressError(ret); + } + + return destLen + LZMA_PROPS_SIZE; + } + + inline void DoDecompress(const TData& in, void* out, size_t len) const { + if (in.size() <= LZMA_PROPS_SIZE) { + ythrow TDataError() << TStringBuf("broken lzma stream"); + } + + const unsigned char* props = (const unsigned char*)in.data(); + const unsigned char* data = props + LZMA_PROPS_SIZE; + size_t destLen = len; + SizeT srcLen = in.size() - LZMA_PROPS_SIZE; + + const int res = LzmaUncompress((unsigned char*)out, &destLen, data, &srcLen, props, LZMA_PROPS_SIZE); + + if (res != SZ_OK) { + ythrow TDecompressError(res); + } + + if (destLen != len) { + ythrow TDecompressError(len, destLen); + } + } + + const int Level; + const TString MyName; + }; + + struct TLzmaRegistrar { + TLzmaRegistrar() { + for (int i = 0; i < 10; ++i) { + RegisterCodec(MakeHolder(i)); + } + RegisterAlias("lzma", "lzma-5"); + } + }; + const TLzmaRegistrar Registrar{}; +} diff --git a/src/library/blockcodecs/codecs/snappy/snappy.cpp b/library/cpp/blockcodecs/codecs/snappy/snappy.cpp similarity index 85% rename from src/library/blockcodecs/codecs/snappy/snappy.cpp rename to library/cpp/blockcodecs/codecs/snappy/snappy.cpp index cc4ae070a83..f11d6ecb22a 100644 --- a/src/library/blockcodecs/codecs/snappy/snappy.cpp +++ b/library/cpp/blockcodecs/codecs/snappy/snappy.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include @@ -38,7 +38,7 @@ namespace { ythrow TDecompressError(0); } - std::string_view Name() const noexcept override { + TStringBuf Name() const noexcept override { return "snappy"; } }; diff --git a/library/cpp/blockcodecs/codecs/zlib/zlib.cpp b/library/cpp/blockcodecs/codecs/zlib/zlib.cpp new file mode 100644 index 00000000000..ac6f0c1e636 --- /dev/null +++ b/library/cpp/blockcodecs/codecs/zlib/zlib.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +#include + +using namespace NBlockCodecs; + +namespace { + struct TZLibCodec: public TAddLengthCodec { + inline TZLibCodec(int level) + : MyName("zlib-" + ToString(level)) + , Level(level) + { + } + + static inline size_t DoMaxCompressedLength(size_t in) noexcept { + return compressBound(in); + } + + TStringBuf Name() const noexcept override { + return MyName; + } + + inline size_t DoCompress(const TData& in, void* buf) const { + //TRASH detected + uLong ret = Max(); + + int cres = compress2((Bytef*)buf, &ret, (const Bytef*)in.data(), in.size(), Level); + + if (cres != Z_OK) { + ythrow TCompressError(cres); + } + + return ret; + } + + inline void DoDecompress(const TData& in, void* out, size_t len) const { + uLong ret = len; + + int uncres = uncompress((Bytef*)out, &ret, (const Bytef*)in.data(), in.size()); + if (uncres != Z_OK) { + ythrow TDecompressError(uncres); + } + + if (ret != len) { + ythrow TDecompressError(len, ret); + } + } + + const TString MyName; + const int Level; + }; + + struct TZLibRegistrar { + TZLibRegistrar() { + for (int i = 0; i < 10; ++i) { + RegisterCodec(MakeHolder(i)); + } + RegisterAlias("zlib", "zlib-6"); + } + }; + const TZLibRegistrar Registrar{}; +} diff --git a/library/cpp/blockcodecs/codecs/zstd/zstd.cpp b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp new file mode 100644 index 00000000000..bcbc4005840 --- /dev/null +++ b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp @@ -0,0 +1,59 @@ +#include +#include +#include + +#define ZSTD_STATIC_LINKING_ONLY +#include + +using namespace NBlockCodecs; + +namespace { + struct TZStd08Codec: public TAddLengthCodec { + inline TZStd08Codec(unsigned level) + : Level(level) + , MyName(TStringBuf("zstd08_") + ToString(Level)) + { + } + + static inline size_t CheckError(size_t ret, const char* what) { + if (ZSTD_isError(ret)) { + ythrow yexception() << what << TStringBuf(" zstd error: ") << ZSTD_getErrorName(ret); + } + + return ret; + } + + static inline size_t DoMaxCompressedLength(size_t l) noexcept { + return ZSTD_compressBound(l); + } + + inline size_t DoCompress(const TData& in, void* out) const { + return CheckError(ZSTD_compress(out, DoMaxCompressedLength(in.size()), in.data(), in.size(), Level), "compress"); + } + + inline void DoDecompress(const TData& in, void* out, size_t dsize) const { + const size_t res = CheckError(ZSTD_decompress(out, dsize, in.data(), in.size()), "decompress"); + + if (res != dsize) { + ythrow TDecompressError(dsize, res); + } + } + + TStringBuf Name() const noexcept override { + return MyName; + } + + const unsigned Level; + const TString MyName; + }; + + struct TZStd08Registrar { + TZStd08Registrar() { + for (int i = 1; i <= ZSTD_maxCLevel(); ++i) { + RegisterCodec(MakeHolder(i)); + RegisterAlias("zstd_" + ToString(i), "zstd08_" + ToString(i)); + } + } + }; + const TZStd08Registrar Registrar{}; +} diff --git a/src/library/blockcodecs/codecs_ut.cpp b/library/cpp/blockcodecs/codecs_ut.cpp similarity index 86% rename from src/library/blockcodecs/codecs_ut.cpp rename to library/cpp/blockcodecs/codecs_ut.cpp index fd90831f465..bfe5a236909 100644 --- a/src/library/blockcodecs/codecs_ut.cpp +++ b/library/cpp/blockcodecs/codecs_ut.cpp @@ -1,34 +1,34 @@ #include "codecs.h" #include "stream.h" -#include +#include -#include -#include -#include +#include +#include +#include Y_UNIT_TEST_SUITE(TBlockCodecsTest) { using namespace NBlockCodecs; - TBuffer Buffer(std::string_view b) { + TBuffer Buffer(TStringBuf b) { TBuffer bb; bb.Assign(b.data(), b.size()); return bb; } void TestAllAtOnce(size_t n, size_t m) { - std::vector datas; + TVector datas; datas.emplace_back(); datas.push_back(Buffer("na gorshke sidel korol")); - datas.push_back(Buffer(std::string_view("", 1))); + datas.push_back(Buffer(TStringBuf("", 1))); datas.push_back(Buffer(" ")); datas.push_back(Buffer(" ")); datas.push_back(Buffer(" ")); datas.push_back(Buffer(" ")); { - std::stringStream data; + TStringStream data; for (size_t i = 0; i < 1024; ++i) { data << " " << i; @@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { for (size_t j = 0; j < datas.size(); ++j) { const TBuffer& data = datas[j]; - std::string res; + TString res; try { TBuffer e, d; @@ -59,7 +59,7 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { d.AsString(res); UNIT_ASSERT_EQUAL(NBlockCodecs::TData(res), NBlockCodecs::TData(data)); } catch (...) { - std::cerr << c->Name() << "(" << res.Quote() << ")(" << std::string{NBlockCodecs::TData(data)}.Quote() << ")" << std::endl; + Cerr << c->Name() << "(" << res.Quote() << ")(" << TString{NBlockCodecs::TData(data)}.Quote() << ")" << Endl; throw; } @@ -144,11 +144,11 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { } void TestStreams(size_t n, size_t m) { - std::vector datas; - std::string res; + TVector datas; + TString res; for (size_t i = 0; i < 256; ++i) { - datas.push_back(std::string(i, (char)(i % 128))); + datas.push_back(TString(i, (char)(i % 128))); } for (size_t i = 0; i < datas.size(); ++i) { @@ -158,7 +158,7 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { TCodecList lst = ListAllCodecs(); for (size_t i = 0; i < lst.size(); ++i) { - std::stringStream ss; + TStringStream ss; const ICodec* c = Codec(lst[i]); const auto h = MultiHash(c->Name(), i, 2); @@ -178,12 +178,12 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { out.Finish(); } - const std::string resNew = TDecodedInput(&ss).ReadAll(); + const TString resNew = TDecodedInput(&ss).ReadAll(); try { UNIT_ASSERT_EQUAL(resNew, res); } catch (...) { - std::cerr << c->Name() << std::endl; + Cerr << c->Name() << Endl; throw; } @@ -274,7 +274,7 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { UNIT_ASSERT_VALUES_EQUAL(GetMaxPossibleDecompressedLength(), Max()); - std::vector input(10001, ' '); + TVector input(10001, ' '); TCodecList codecs = ListAllCodecs(); SetMaxPossibleDecompressedLength(10000); @@ -292,7 +292,7 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { } Y_UNIT_TEST(TestListAllCodecs) { - static const std::string ALL_CODECS = + static const TString ALL_CODECS = "brotli_1,brotli_10,brotli_11,brotli_2,brotli_3,brotli_4,brotli_5,brotli_6,brotli_7,brotli_8,brotli_9," "bzip2,bzip2-1,bzip2-2,bzip2-3,bzip2-4,bzip2-5,bzip2-6,bzip2-7,bzip2-8,bzip2-9," @@ -313,6 +313,10 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { "zlib,zlib-0,zlib-1,zlib-2,zlib-3,zlib-4,zlib-5,zlib-6,zlib-7,zlib-8,zlib-9," + "zstd06_1,zstd06_10,zstd06_11,zstd06_12,zstd06_13,zstd06_14,zstd06_15,zstd06_16,zstd06_17,zstd06_18," + "zstd06_19,zstd06_2,zstd06_20,zstd06_21,zstd06_22,zstd06_3,zstd06_4,zstd06_5,zstd06_6,zstd06_7,zstd06_8," + "zstd06_9," + "zstd08_1,zstd08_10,zstd08_11,zstd08_12,zstd08_13,zstd08_14,zstd08_15,zstd08_16,zstd08_17,zstd08_18," "zstd08_19,zstd08_2,zstd08_20,zstd08_21,zstd08_22,zstd08_3,zstd08_4,zstd08_5,zstd08_6,zstd08_7,zstd08_8," "zstd08_9,zstd_1,zstd_10,zstd_11,zstd_12,zstd_13,zstd_14,zstd_15,zstd_16,zstd_17,zstd_18,zstd_19,zstd_2," @@ -322,13 +326,13 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { } Y_UNIT_TEST(TestEncodeDecodeIntoString) { - std::string_view data = "na gorshke sidel korol"; + TStringBuf data = "na gorshke sidel korol"; TCodecList codecs = ListAllCodecs(); for (const auto& codec : codecs) { const ICodec* c = Codec(codec); - std::string encoded = c->Encode(data); - std::string decoded = c->Decode(encoded); + TString encoded = c->Encode(data); + TString decoded = c->Decode(encoded); UNIT_ASSERT_VALUES_EQUAL(decoded, data); } diff --git a/library/cpp/blockcodecs/core/codecs.cpp b/library/cpp/blockcodecs/core/codecs.cpp new file mode 100644 index 00000000000..1378432de90 --- /dev/null +++ b/library/cpp/blockcodecs/core/codecs.cpp @@ -0,0 +1,144 @@ +#include "codecs.h" +#include "common.h" +#include "register.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace NBlockCodecs; + +namespace { + + struct TCodecFactory { + inline TCodecFactory() { + Add(&Null); + } + + inline const ICodec* Find(const TStringBuf& name) const { + auto it = Registry.find(name); + + if (it == Registry.end()) { + ythrow TNotFound() << "can not found " << name << " codec"; + } + + return it->second; + } + + inline void ListCodecs(TCodecList& lst) const { + for (const auto& it : Registry) { + lst.push_back(it.first); + } + + Sort(lst.begin(), lst.end()); + } + + inline void Add(ICodec* codec) { + Registry[codec->Name()] = codec; + } + + inline void Add(TCodecPtr codec) { + Codecs.push_back(std::move(codec)); + Add(Codecs.back().Get()); + } + + inline void Alias(TStringBuf from, TStringBuf to) { + Tmp.emplace_back(from); + Registry[Tmp.back()] = Registry[to]; + } + + TDeque Tmp; + TNullCodec Null; + TVector Codecs; + typedef THashMap TRegistry; + TRegistry Registry; + + // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) + size_t MaxPossibleDecompressedLength = Max(); + }; +} + +const ICodec* NBlockCodecs::Codec(const TStringBuf& name) { + return Singleton()->Find(name); +} + +TCodecList NBlockCodecs::ListAllCodecs() { + TCodecList ret; + + Singleton()->ListCodecs(ret); + + return ret; +} + +TString NBlockCodecs::ListAllCodecsAsString() { + return JoinSeq(TStringBuf(","), ListAllCodecs()); +} + +void NBlockCodecs::RegisterCodec(TCodecPtr codec) { + Singleton()->Add(std::move(codec)); +} + +void NBlockCodecs::RegisterAlias(TStringBuf from, TStringBuf to) { + Singleton()->Alias(from, to); +} + +void NBlockCodecs::SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength) { + Singleton()->MaxPossibleDecompressedLength = maxPossibleDecompressedLength; +} + +size_t NBlockCodecs::GetMaxPossibleDecompressedLength() { + return Singleton()->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); + + out.Reserve(maxLen); + out.Resize(Compress(in, out.Data())); +} + +void ICodec::Decode(const TData& in, TBuffer& out) const { + const size_t len = GetDecompressedLength(in); + + out.Reserve(len); + out.Resize(Decompress(in, out.Data())); +} + +void ICodec::Encode(const TData& in, TString& out) const { + const size_t maxLen = MaxCompressedLength(in); + out.ReserveAndResize(maxLen); + + size_t actualLen = Compress(in, out.begin()); + Y_ASSERT(actualLen <= maxLen); + out.resize(actualLen); +} + +void ICodec::Decode(const TData& in, TString& out) const { + const size_t maxLen = GetDecompressedLength(in); + out.ReserveAndResize(maxLen); + + size_t actualLen = Decompress(in, out.begin()); + Y_ASSERT(actualLen <= maxLen); + out.resize(actualLen); +} + +ICodec::~ICodec() = default; diff --git a/library/cpp/blockcodecs/core/codecs.h b/library/cpp/blockcodecs/core/codecs.h new file mode 100644 index 00000000000..9c93c002748 --- /dev/null +++ b/library/cpp/blockcodecs/core/codecs.h @@ -0,0 +1,90 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace NBlockCodecs { + struct TData: public TStringBuf { + inline TData() = default; + + Y_HAS_MEMBER(Data); + Y_HAS_MEMBER(Size); + + template ::value || !THasData::value, int> = 0> + inline TData(const T& t) + : TStringBuf((const char*)t.data(), t.size()) + { + } + + template ::value && THasData::value, int> = 0> + inline TData(const T& t) + : TStringBuf((const char*)t.Data(), t.Size()) + { + } + }; + + struct TCodecError: public yexception { + }; + + struct TNotFound: public TCodecError { + }; + + struct TDataError: public TCodecError { + }; + + struct ICodec { + virtual ~ICodec(); + + // 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; + virtual size_t Decompress(const TData& in, void* out) const = 0; + + virtual TStringBuf Name() const noexcept = 0; + + // some useful helpers + void Encode(const TData& in, TBuffer& out) const; + void Decode(const TData& in, TBuffer& out) const; + + void Encode(const TData& in, TString& out) const; + void Decode(const TData& in, TString& out) const; + + inline TString Encode(const TData& in) const { + TString out; + + Encode(in, out); + + return out; + } + + inline TString Decode(const TData& in) const { + TString out; + + Decode(in, out); + + return out; + } + private: + size_t GetDecompressedLength(const TData& in) const; + }; + + using TCodecPtr = THolder; + + const ICodec* Codec(const TStringBuf& name); + + // some aux methods + typedef TVector 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); + +} diff --git a/library/cpp/blockcodecs/core/common.h b/library/cpp/blockcodecs/core/common.h new file mode 100644 index 00000000000..f05df4d3341 --- /dev/null +++ b/library/cpp/blockcodecs/core/common.h @@ -0,0 +1,105 @@ +#pragma once + +#include "codecs.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NBlockCodecs { + struct TDecompressError: public TDataError { + TDecompressError(int code) { + *this << "cannot decompress (errcode " << code << ")"; + } + + TDecompressError(size_t exp, size_t real) { + *this << "broken input (expected len: " << exp << ", got: " << real << ")"; + } + }; + + struct TCompressError: public TDataError { + TCompressError(int code) { + *this << "cannot compress (errcode " << code << ")"; + } + }; + + struct TNullCodec: public ICodec { + size_t DecompressedLength(const TData& in) const override { + return in.size(); + } + + size_t MaxCompressedLength(const TData& in) const override { + return in.size(); + } + + size_t Compress(const TData& in, void* out) const override { + MemCopy((char*)out, in.data(), in.size()); + + return in.size(); + } + + size_t Decompress(const TData& in, void* out) const override { + MemCopy((char*)out, in.data(), in.size()); + + return in.size(); + } + + TStringBuf Name() const noexcept override { + return TStringBuf("null"); + } + }; + + template + struct TAddLengthCodec: public ICodec { + static inline void Check(const TData& in) { + if (in.size() < sizeof(ui64)) { + ythrow TDataError() << "too small input"; + } + } + + size_t DecompressedLength(const TData& in) const override { + Check(in); + + return ReadUnaligned(in.data()); + } + + size_t MaxCompressedLength(const TData& in) const override { + return T::DoMaxCompressedLength(in.size()) + sizeof(ui64); + } + + size_t Compress(const TData& in, void* out) const override { + ui64* ptr = (ui64*)out; + + WriteUnaligned(ptr, (ui64) in.size()); + + return Base()->DoCompress(!in ? TData(TStringBuf("")) : in, ptr + 1) + sizeof(*ptr); + } + + size_t Decompress(const TData& in, void* out) const override { + Check(in); + + const auto len = ReadUnaligned(in.data()); + + if (!len) + return 0; + + Base()->DoDecompress(TData(in).Skip(sizeof(len)), out, len); + return len; + } + + inline const T* Base() const noexcept { + return static_cast(this); + } + }; +} diff --git a/library/cpp/blockcodecs/core/register.h b/library/cpp/blockcodecs/core/register.h new file mode 100644 index 00000000000..fa1186dd705 --- /dev/null +++ b/library/cpp/blockcodecs/core/register.h @@ -0,0 +1,10 @@ +#pragma once + +#include "codecs.h" + +namespace NBlockCodecs{ + + void RegisterCodec(TCodecPtr codec); + void RegisterAlias(TStringBuf from, TStringBuf to); + +} diff --git a/library/cpp/blockcodecs/core/stream.cpp b/library/cpp/blockcodecs/core/stream.cpp new file mode 100644 index 00000000000..39e8786db67 --- /dev/null +++ b/library/cpp/blockcodecs/core/stream.cpp @@ -0,0 +1,212 @@ +#include "stream.h" +#include "codecs.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace NBlockCodecs; + +namespace { + constexpr size_t MAX_BUF_LEN = 128 * 1024 * 1024; + + typedef ui16 TCodecID; + typedef ui64 TBlockLen; + + struct TIds { + inline TIds() { + const TCodecList lst = ListAllCodecs(); + + for (size_t i = 0; i < lst.size(); ++i) { + const ICodec* c = Codec(lst[i]); + + ByID[CodecID(c)] = c; + } + } + + static inline TCodecID CodecID(const ICodec* c) { + const TStringBuf name = c->Name(); + + union { + ui16 Parts[2]; + ui32 Data; + } x; + + x.Data = MurmurHash(name.data(), name.size()); + + return x.Parts[1] ^ x.Parts[0]; + } + + inline const ICodec* Find(TCodecID id) const { + TByID::const_iterator it = ByID.find(id); + + if (it != ByID.end()) { + return it->second; + } + + ythrow yexception() << "can not find codec by id " << id; + } + + typedef THashMap TByID; + TByID ByID; + }; + + TCodecID CodecID(const ICodec* c) { + return TIds::CodecID(c); + } + + const ICodec* CodecByID(TCodecID id) { + return Singleton()->Find(id); + } +} + +TCodedOutput::TCodedOutput(IOutputStream* out, const ICodec* c, size_t bufLen) + : C_(c) + , D_(bufLen) + , S_(out) +{ + if (bufLen > MAX_BUF_LEN) { + ythrow yexception() << TStringBuf("too big buffer size: ") << bufLen; + } +} + +TCodedOutput::~TCodedOutput() { + try { + Finish(); + } catch (...) { + } +} + +void TCodedOutput::DoWrite(const void* buf, size_t len) { + const char* in = (const char*)buf; + + while (len) { + const size_t avail = D_.Avail(); + + if (len < avail) { + D_.Append(in, len); + + return; + } + + D_.Append(in, avail); + + Y_ASSERT(!D_.Avail()); + + in += avail; + len -= avail; + + Y_ABORT_UNLESS(FlushImpl(), "flush on writing failed"); + } +} + +bool TCodedOutput::FlushImpl() { + const bool ret = !D_.Empty(); + const size_t payload = sizeof(TCodecID) + sizeof(TBlockLen); + O_.Reserve(C_->MaxCompressedLength(D_) + payload); + + void* out = O_.Data() + payload; + const size_t olen = C_->Compress(D_, out); + + { + TMemoryOutput mo(O_.Data(), payload); + + ::Save(&mo, CodecID(C_)); + ::Save(&mo, SafeIntegerCast(olen)); + } + + S_->Write(O_.Data(), payload + olen); + + D_.Clear(); + O_.Clear(); + + return ret; +} + +void TCodedOutput::DoFlush() { + if (S_ && !D_.Empty()) { + FlushImpl(); + } +} + +void TCodedOutput::DoFinish() { + if (S_) { + Y_DEFER { + S_ = nullptr; + }; + + if (FlushImpl()) { + //always write zero-length block as eos marker + FlushImpl(); + } + } +} + +TDecodedInput::TDecodedInput(IInputStream* in) + : S_(in) + , C_(nullptr) +{ +} + +TDecodedInput::TDecodedInput(IInputStream* in, const ICodec* codec) + : S_(in) + , C_(codec) +{ +} + +TDecodedInput::~TDecodedInput() = default; + +size_t TDecodedInput::DoUnboundedNext(const void** ptr) { + if (!S_) { + return 0; + } + + TCodecID codecId; + TBlockLen blockLen; + + { + const size_t payload = sizeof(TCodecID) + sizeof(TBlockLen); + char buf[32]; + + S_->LoadOrFail(buf, payload); + + TMemoryInput in(buf, payload); + + ::Load(&in, codecId); + ::Load(&in, blockLen); + } + + if (!blockLen) { + S_ = nullptr; + + return 0; + } + + if (Y_UNLIKELY(blockLen > 1024 * 1024 * 1024)) { + ythrow yexception() << "block size exceeds 1 GiB"; + } + + TBuffer block; + block.Resize(blockLen); + + S_->LoadOrFail(block.Data(), blockLen); + + auto codec = CodecByID(codecId); + + if (C_) { + Y_ENSURE(C_->Name() == codec->Name(), TStringBuf("incorrect stream codec")); + } + + if (codec->DecompressedLength(block) > MAX_BUF_LEN) { + ythrow yexception() << "broken stream"; + } + + codec->Decode(block, D_); + *ptr = D_.Data(); + + return D_.Size(); +} diff --git a/library/cpp/blockcodecs/core/stream.h b/library/cpp/blockcodecs/core/stream.h new file mode 100644 index 00000000000..fd44ef88f2c --- /dev/null +++ b/library/cpp/blockcodecs/core/stream.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace NBlockCodecs { + struct ICodec; + + class TCodedOutput: public IOutputStream { + public: + TCodedOutput(IOutputStream* out, const ICodec* c, size_t bufLen); + ~TCodedOutput() override; + + private: + void DoWrite(const void* buf, size_t len) override; + void DoFlush() override; + void DoFinish() override; + + bool FlushImpl(); + + private: + const ICodec* C_; + TBuffer D_; + TBuffer O_; + IOutputStream* S_; + }; + + class TDecodedInput: public IWalkInput { + public: + TDecodedInput(IInputStream* in); + TDecodedInput(IInputStream* in, const ICodec* codec); + + ~TDecodedInput() override; + + private: + size_t DoUnboundedNext(const void** ptr) override; + + private: + TBuffer D_; + IInputStream* S_; + const ICodec* C_; + }; +} diff --git a/library/cpp/blockcodecs/fuzz/main.cpp b/library/cpp/blockcodecs/fuzz/main.cpp new file mode 100644 index 00000000000..a89fee7ab73 --- /dev/null +++ b/library/cpp/blockcodecs/fuzz/main.cpp @@ -0,0 +1,84 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +using NBlockCodecs::NFuzz::TPackUnpackCase; +using NBlockCodecs::TCodedOutput; +using NBlockCodecs::TDecodedInput; + +static void ValidateBufferSize(const ui32 size) { + Y_ENSURE(size > 0 && size <= 16ULL * 1024); +} + +static void DoOnlyDecode(const TPackUnpackCase& case_) { + if (!case_.GetPacked()) { + return; + } + + TMemoryInput mi(case_.GetData().data(), case_.GetData().size()); + TDecodedInput di(&mi); + TNullOutput no; + TCountingOutput cno(&no); + TransferData(&di, &cno); +} + +static void DoDecodeEncode(const TPackUnpackCase& case_) { + auto* const codec = NBlockCodecs::Codec(case_.GetCodecName()); + Y_ENSURE(codec); + + TMemoryInput mi(case_.GetData().data(), case_.GetData().size()); + TDecodedInput di(&mi, codec); + TStringStream decoded; + TransferData(&di, &decoded); + TNullOutput no; + TCountingOutput cno(&no); + TCodedOutput co(&cno, codec, case_.GetBufferLength()); + TransferData(&decoded, &co); + co.Flush(); + + Y_ABORT_UNLESS((case_.GetData().size() > 0) == (cno.Counter() > 0)); + Y_ABORT_UNLESS((case_.GetData().size() > 0) == (decoded.Str().size() > 0)); +} + +static void DoEncodeDecode(const TPackUnpackCase& case_) { + auto* const codec = NBlockCodecs::Codec(case_.GetCodecName()); + Y_ENSURE(codec); + + TMemoryInput mi(case_.GetData().data(), case_.GetData().size()); + TStringStream encoded; + TCodedOutput co(&encoded, codec, case_.GetBufferLength()); + TransferData(&mi, &co); + co.Flush(); + TStringStream decoded; + TDecodedInput di(&encoded, codec); + TransferData(&di, &decoded); + + Y_ABORT_UNLESS((case_.GetData().size() > 0) == (encoded.Str().size() > 0)); + Y_ABORT_UNLESS(case_.GetData() == decoded.Str()); +} + +DEFINE_BINARY_PROTO_FUZZER(const TPackUnpackCase& case_) { + try { + if (!case_.GetCodecName()) { + DoOnlyDecode(case_); + return; + } + + ValidateBufferSize(case_.GetBufferLength()); + if (case_.GetPacked()) { + DoDecodeEncode(case_); + } else { + DoEncodeDecode(case_); + } + } catch (const std::exception&) { + } +} diff --git a/library/cpp/blockcodecs/fuzz/proto/case.proto b/library/cpp/blockcodecs/fuzz/proto/case.proto new file mode 100644 index 00000000000..85518b0da9e --- /dev/null +++ b/library/cpp/blockcodecs/fuzz/proto/case.proto @@ -0,0 +1,10 @@ +syntax="proto3"; + +package NBlockCodecs.NFuzz; + +message TPackUnpackCase { + bool Packed = 1; + uint32 BufferLength = 2; + string CodecName = 3; + bytes Data = 4; +} diff --git a/src/library/blockcodecs/stream.cpp b/library/cpp/blockcodecs/stream.cpp similarity index 100% rename from src/library/blockcodecs/stream.cpp rename to library/cpp/blockcodecs/stream.cpp diff --git a/library/cpp/blockcodecs/stream.h b/library/cpp/blockcodecs/stream.h new file mode 100644 index 00000000000..96c479cf7e1 --- /dev/null +++ b/library/cpp/blockcodecs/stream.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/library/cpp/build_info/CMakeLists.txt b/library/cpp/build_info/CMakeLists.txt new file mode 100644 index 00000000000..00f7926afbd --- /dev/null +++ b/library/cpp/build_info/CMakeLists.txt @@ -0,0 +1,49 @@ +find_package(Python3 REQUIRED) + +set(KOSHER_SVN_VERSION "") +set(SANDBOX_TASK_ID 0) +set(BUILD_TYPE RELEASE) + +_ydb_sdk_add_library(build_info) +target_include_directories(build_info + PRIVATE + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info +) + +target_link_libraries(build_info + PRIVATE + yutil + string_utils-base64 +) + +target_sources(build_info + PRIVATE + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/sandbox.cpp + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/build_info.cpp + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/buildinfo_data.h + build_info_static.cpp +) + +add_custom_command( + OUTPUT + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/buildinfo_data.h + DEPENDS + ${YDB_SDK_SOURCE_DIR}/scripts/build_info_gen.py + COMMAND + Python3::Interpreter + ${YDB_SDK_SOURCE_DIR}/scripts/build_info_gen.py + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/buildinfo_data.h + \"${CMAKE_CXX_COMPILER}\" + \"${CMAKE_CXX_FLAGS}\" +) + +configure_file( + ${YDB_SDK_SOURCE_DIR}/library/cpp/build_info/sandbox.cpp.in + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/sandbox.cpp +) +configure_file( + ${YDB_SDK_SOURCE_DIR}/library/cpp/build_info/build_info.cpp.in + ${YDB_SDK_BINARY_DIR}/library/cpp/build_info/build_info.cpp +) + +_ydb_sdk_install_targets(TARGETS build_info) diff --git a/library/cpp/build_info/build_info.cpp.in b/library/cpp/build_info/build_info.cpp.in new file mode 100644 index 00000000000..71403af13e0 --- /dev/null +++ b/library/cpp/build_info/build_info.cpp.in @@ -0,0 +1,5 @@ +#include + +extern "C" const char* GetBuildType() { + return "@BUILD_TYPE@"; +} diff --git a/src/library/build_info/build_info.h b/library/cpp/build_info/build_info.h similarity index 100% rename from src/library/build_info/build_info.h rename to library/cpp/build_info/build_info.h diff --git a/src/library/build_info/build_info_static.cpp b/library/cpp/build_info/build_info_static.cpp similarity index 89% rename from src/library/build_info/build_info_static.cpp rename to library/cpp/build_info/build_info_static.cpp index af4c43114d6..238fb1ecb0f 100644 --- a/src/library/build_info/build_info_static.cpp +++ b/library/cpp/build_info/build_info_static.cpp @@ -1,6 +1,6 @@ #include "build_info_static.h" -#include +#include extern "C" const char* GetCompilerVersion() { #if defined(BUILD_COMPILER_VERSION) diff --git a/src/library/build_info/build_info_static.h b/library/cpp/build_info/build_info_static.h similarity index 100% rename from src/library/build_info/build_info_static.h rename to library/cpp/build_info/build_info_static.h diff --git a/library/cpp/build_info/sandbox.cpp.in b/library/cpp/build_info/sandbox.cpp.in new file mode 100644 index 00000000000..e4f8d399a0b --- /dev/null +++ b/library/cpp/build_info/sandbox.cpp.in @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +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()->Version(); +} diff --git a/src/library/build_info/sandbox.h b/library/cpp/build_info/sandbox.h similarity index 100% rename from src/library/build_info/sandbox.h rename to library/cpp/build_info/sandbox.h diff --git a/library/cpp/cache/CMakeLists.txt b/library/cpp/cache/CMakeLists.txt new file mode 100644 index 00000000000..520789268e1 --- /dev/null +++ b/library/cpp/cache/CMakeLists.txt @@ -0,0 +1,17 @@ +if (YDB_SDK_TESTS) + add_subdirectory(ut) +endif() + +_ydb_sdk_add_library(library-cache) + +target_link_libraries(library-cache PUBLIC + yutil +) + +target_sources(library-cache + PRIVATE + cache.cpp + thread_safe_cache.cpp +) + +_ydb_sdk_install_targets(TARGETS library-cache) diff --git a/src/library/cache/cache.cpp b/library/cpp/cache/cache.cpp similarity index 100% rename from src/library/cache/cache.cpp rename to library/cpp/cache/cache.cpp diff --git a/src/library/cache/cache.h b/library/cpp/cache/cache.h similarity index 92% rename from src/library/cache/cache.h rename to library/cpp/cache/cache.h index a559917ed81..9fe98d53666 100644 --- a/src/library/cache/cache.h +++ b/library/cpp/cache/cache.h @@ -1,14 +1,12 @@ #pragma once -#include -#include -#include -#include - -#include - +#include +#include +#include +#include +#include +#include #include -#include template struct TUniformSizeProvider { @@ -70,7 +68,6 @@ class TLRUList { TValue Value; struct THash { - using is_transparent = void; size_t operator()(const TItem& item) const { return ::THash()(item.Key); } @@ -80,7 +77,6 @@ class TLRUList { }; struct TEqualTo { - using is_transparent = void; bool operator()(const TItem& lhs, const TItem& rhs) const { return lhs.Key == rhs.Key; } @@ -128,11 +124,11 @@ class TLRUList { List.PushBack(item); } - size_t GetSize() const { + [[nodiscard]] size_t GetSize() const { return ItemsAmount; } - size_t GetTotalSize() const { + [[nodiscard]] size_t GetTotalSize() const { return TotalSize; } @@ -161,7 +157,8 @@ class TLFUList { TLFUList(size_t maxSize, const TSizeProvider& sizeProvider = TSizeProvider()) : List() , SizeProvider(sizeProvider) - , ListSize(0) + , ItemsAmount(0) + , TotalSize(0) , MaxSize(maxSize) { } @@ -208,7 +205,6 @@ class TLFUList { size_t Counter; struct THash { - using is_transparent = void; size_t operator()(const TItem& item) const { return ::THash()(item.Key); } @@ -218,7 +214,6 @@ class TLFUList { }; struct TEqualTo { - using is_transparent = void; bool operator()(const TItem& lhs, const TItem& rhs) const { return lhs.Key == rhs.Key; } @@ -234,14 +229,15 @@ class TLFUList { public: TItem* Insert(TItem* item) { List.PushBack(item); // give a chance for promotion - ListSize += SizeProvider(item->Value); + ++ItemsAmount; + TotalSize += SizeProvider(item->Value); return RemoveIfOverflown(); } TItem* RemoveIfOverflown() { TItem* deleted = nullptr; - if (ListSize > MaxSize) { + if (TotalSize > MaxSize && ItemsAmount > 1) { deleted = GetLeastFrequentlyUsed(); Erase(deleted); } @@ -256,7 +252,8 @@ class TLFUList { void Erase(TItem* item) { item->Unlink(); - ListSize -= SizeProvider(item->Value); + --ItemsAmount; + TotalSize -= SizeProvider(item->Value); } void Promote(TItem* item) { @@ -268,8 +265,12 @@ class TLFUList { item->LinkBefore(&*it); } - size_t GetSize() const { - return ListSize; + [[nodiscard]] size_t GetSize() const { + return ItemsAmount; + } + + [[nodiscard]] size_t GetTotalSize() const { + return TotalSize; } size_t GetMaxSize() const { @@ -286,7 +287,8 @@ class TLFUList { typedef TIntrusiveList TListType; TListType List; TSizeProvider SizeProvider; - size_t ListSize; + size_t ItemsAmount; + size_t TotalSize; size_t MaxSize; }; @@ -340,7 +342,6 @@ class TLWList { TWeight Weight; struct THash { - using is_transparent = void; size_t operator()(const TItem& item) const { return ::THash()(item.Key); } @@ -350,7 +351,6 @@ class TLWList { }; struct TEqualTo { - using is_transparent = void; bool operator()(const TItem& lhs, const TItem& rhs) const { return lhs.Key == rhs.Key; } @@ -421,6 +421,10 @@ class TLWList { return Size; } + [[nodiscard]] size_t GetTotalSize() const { + return Size; + } + size_t GetMaxSize() const { return MaxSize; } @@ -454,18 +458,18 @@ class TLWList { } private: - std::vector Heap; - std::unordered_set Removed; + TVector Heap; + THashSet Removed; size_t Size; size_t MaxSize; }; -template > +template > class TCache { typedef typename TListType::TItem TItem; typedef typename TItem::THash THash; - typedef std::unordered_multiset TIndex; + typedef THashMultiSet TIndex; typedef typename TIndex::iterator TIndexIterator; typedef typename TIndex::const_iterator TIndexConstIterator; @@ -523,10 +527,14 @@ class TCache { Clear(); } - size_t Size() const { + [[nodiscard]] size_t Size() const { return Index.size(); } + [[nodiscard]] size_t TotalSize() const { + return List.GetTotalSize(); + } + TIterator Begin() const { return TIterator(Index.begin()); } @@ -666,7 +674,7 @@ class TCache { Index.reserve(hint); } - typedef typename std::allocator_traits::template rebind_alloc TNodeAllocatorType; + typedef typename TIndex::node_allocator_type TNodeAllocatorType; TNodeAllocatorType& GetNodeAllocator() { return Index.GetNodeAllocator(); } @@ -700,7 +708,7 @@ struct TNoopDelete { } }; -template , typename TAllocator = std::allocator::TItem>> +template , typename TAllocator = std::allocator> class TLRUCache: public TCache, TDeleter, TAllocator> { using TListType = TLRUList; typedef TCache TBase; @@ -727,7 +735,7 @@ class TLRUCache: public TCache, typename TAllocator = std::allocator::TItem>> +template , class TSizeProvider = TUniformSizeProvider> class TLFUCache: public TCache, TDeleter, TAllocator> { typedef TCache, TDeleter, TAllocator> TBase; using TListType = TLFUList; @@ -752,7 +760,7 @@ class TLFUCache: public TCache::TItem>> +template > class TLWCache: public TCache, TDeleter, TAllocator> { typedef TCache, TDeleter, TAllocator> TBase; using TListType = TLWList; diff --git a/src/library/cache/thread_safe_cache.cpp b/library/cpp/cache/thread_safe_cache.cpp similarity index 100% rename from src/library/cache/thread_safe_cache.cpp rename to library/cpp/cache/thread_safe_cache.cpp diff --git a/library/cpp/cache/thread_safe_cache.h b/library/cpp/cache/thread_safe_cache.h new file mode 100644 index 00000000000..e77d1a45fd8 --- /dev/null +++ b/library/cpp/cache/thread_safe_cache.h @@ -0,0 +1,267 @@ +#pragma once + +#include "cache.h" + +#include +#include + +namespace NPrivate { + // We are interested in getters promotion policy _here_ because of Read-Write-Lock optimizations. + enum class EGettersPromotionPolicy { + Promoted, // LRU, TLRU, MRU, etc. + Unpromoted // FIFO, LIFO, LW, etc. + }; + + template class List, EGettersPromotionPolicy GettersPromotionPolicy, class... TArgs> + class TThreadSafeCache { + public: + using TPtr = TAtomicSharedPtr; + + class ICallbacks { + public: + using TKey = Key; + using TValue = Value; + using TOwner = TThreadSafeCache; + + public: + virtual ~ICallbacks() = default; + virtual TKey GetKey(TArgs... args) const = 0; + virtual TValue* CreateObject(TArgs... args) const = 0; + }; + + public: + TThreadSafeCache(const ICallbacks& callbacks, size_t maxSize = Max()) + : Callbacks(callbacks) + , Cache(maxSize) + { + } + + bool Insert(const Key& key, const TPtr& value) { + if (!Contains(key)) { + TWriteGuard w(Mutex); + return Cache.Insert(key, value); + } + return false; + } + + void Update(const Key& key, const TPtr& value) { + TWriteGuard w(Mutex); + Cache.Update(key, value); + } + + const TPtr GetOrNull(TArgs... args) { + Key key = Callbacks.GetKey(args...); + TReadGuard r(Mutex); + auto iter = Cache.Find(key); + if (iter == Cache.End()) { + return nullptr; + } + return iter.Value(); + } + + const TPtr Get(TArgs... args) const { + return GetValue(args...); + } + + const TPtr GetUnsafe(TArgs... args) const { + return GetValue(args...); + } + + void Clear() { + TWriteGuard w(Mutex); + Cache.Clear(); + } + + void Erase(TArgs... args) { + Key key = Callbacks.GetKey(args...); + if (!Contains(key)) { + return; + } + TWriteGuard w(Mutex); + typename TInternalCache::TIterator i = Cache.Find(key); + if (i == Cache.End()) { + return; + } + Cache.Erase(i); + } + + bool Contains(const Key& key) const { + TReadGuard r(Mutex); + auto iter = Cache.FindWithoutPromote(key); + return iter != Cache.End(); + } + + template + static const TPtr Get(TArgs... args) { + return TThreadSafeCacheSingleton::Get(args...); + } + + template + static const TPtr Erase(TArgs... args) { + return TThreadSafeCacheSingleton::Erase(args...); + } + + template + static void Clear() { + return TThreadSafeCacheSingleton::Clear(); + } + + size_t Size() const { + TReadGuard r(Mutex); + return Cache.Size(); + } + + size_t TotalSize() const { + TReadGuard r(Mutex); + return Cache.TotalSize(); + } + + size_t GetMaxSize() const { + TReadGuard w(Mutex); + return Cache.GetMaxSize(); + } + + void SetMaxSize(size_t newSize) { + TWriteGuard w(Mutex); + Cache.SetMaxSize(newSize); + } + + private: + template + const TPtr GetValue(TArgs... args) const { + Key key = Callbacks.GetKey(args...); + switch (GettersPromotionPolicy) { + case EGettersPromotionPolicy::Promoted: + break; + case EGettersPromotionPolicy::Unpromoted: { + TReadGuard r(Mutex); + typename TInternalCache::TIterator i = Cache.FindWithoutPromote(key); + if (i != Cache.End()) { + return i.Value(); + } + break; + } + } + TWriteGuard w(Mutex); + typename TInternalCache::TIterator i = Cache.Find(key); + if (i != Cache.End()) { + return i.Value(); + } + TPtr value = Callbacks.CreateObject(args...); + if (value || AllowNullValues) { + Cache.Insert(key, value); + } + return value; + } + + private: + using TInternalCache = TCache, TNoopDelete>; + + template + class TThreadSafeCacheSingleton { + public: + static const TPtr Get(TArgs... args) { + return Singleton()->Cache.Get(args...); + } + + static const TPtr Erase(TArgs... args) { + return Singleton()->Cache.Erase(args...); + } + + static void Clear() { + return Singleton()->Cache.Clear(); + } + + TThreadSafeCacheSingleton() + : Cache(Callbacks) + { + } + + private: + TCallbacks Callbacks; + typename TCallbacks::TOwner Cache; + }; + + private: + TRWMutex Mutex; + const ICallbacks& Callbacks; + mutable TInternalCache Cache; + }; + + struct TLWHelper { + template + struct TConstWeighter { + static int Weight(const TValue& /*value*/) { + return 0; + } + }; + + template + using TListType = TLWList>; + + template + using TCache = TThreadSafeCache; + }; + + struct TLRUHelper { + template + using TListType = TLRUList; + + template + using TCache = TThreadSafeCache; + }; + + struct TLFUHelper { + template + using TListType = TLFUList; + + template + using TCache = TThreadSafeCache; + }; + + template + struct TSizeProviderRemoveAtomic : TSizeProvider { + // TValue in this signature is TCache::TPtr, using this wrapper user don't need + // to handle TPtr (which is TAtomicSharedPtr) and can just accept TValue + // in custom size provider. See example in unittests + size_t operator()(const TValue& value) const { + // We can pass reference to value without synchronization, because TSizeProvider::operator() + // is always called from methods secured by a guard + return TSizeProvider::operator()(*value); + } + }; + + template