diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/libs/protobuf | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/libs/protobuf')
55 files changed, 3587 insertions, 0 deletions
diff --git a/contrib/libs/protobuf/.yandex_meta/__init__.py b/contrib/libs/protobuf/.yandex_meta/__init__.py new file mode 100644 index 0000000000..a61afd98f1 --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/__init__.py @@ -0,0 +1,274 @@ +import os +import os.path + +from devtools.yamaker import fileutil +from devtools.yamaker import pathutil +from devtools.yamaker.arcpath import ArcPath +from devtools.yamaker.modules import Linkable, Switch +from devtools.yamaker.project import CMakeNinjaNixProject + + +def make_full_path(src): + return os.path.join("src/google/protobuf", src) + + +RUNTIME_EXCESS_SOURCES = [ + "src/google/protobuf/compiler/importer.cc", + "src/google/protobuf/compiler/parser.cc", +] + +RUNTIME_YANDEX_SPECIFIC_SOURCES = [ + "src/google/protobuf/json_util.cc", + "src/google/protobuf/messagext.cc", +] + +# This stubs are deprecated, will removed after protobuf update +DEPRECATED_STUBS = [ + "src/google/protobuf/stubs/hash.h", + "src/google/protobuf/stubs/stl_util.h", + "src/google/protobuf/stubs/stringpiece.cc", + "src/google/protobuf/stubs/stringpiece.h", + "src/google/protobuf/stubs/strutil.cc", + "src/google/protobuf/stubs/strutil.h", + "src/google/protobuf/stubs/status.cc", + "src/google/protobuf/stubs/status.h", + "src/google/protobuf/stubs/substitute.cc", + "src/google/protobuf/stubs/substitute.h", + "src/google/protobuf/stubs/map_util.h", + "src/google/protobuf/stubs/structurally_valid.cc", + "src/google/protobuf/util/json_util.h", + "src/google/protobuf/json/old_json.cc", + "src/google/protobuf/json_util.cc", + "src/google/protobuf/json_util.h", +] + +DEPRECATED_SRC = [x for x in DEPRECATED_STUBS if x.endswith('.cc')] + +# Set of proto files coming with original google protobuf (excluding descriptor.proto, see below) +# WARN: upon changing this file, make sure to check protobuf_std counterpart. +RUNTIME_PROTO_FILES = [ + "src/google/protobuf/any.proto", + "src/google/protobuf/api.proto", + "src/google/protobuf/descriptor.proto", + "src/google/protobuf/duration.proto", + "src/google/protobuf/empty.proto", + "src/google/protobuf/field_mask.proto", + "src/google/protobuf/source_context.proto", + "src/google/protobuf/struct.proto", + "src/google/protobuf/timestamp.proto", + "src/google/protobuf/type.proto", + "src/google/protobuf/wrappers.proto", +] + +PROTOC_PROTO_FILES = [ + "src/google/protobuf/compiler/plugin.proto", +] + + +LIBPROTOC_DIR = "contrib/libs/protoc" +PYTHON_DIR = "contrib/python/protobuf/py3" + +POSSIBLE_STD_STRING_USAGE_PATTERNS = [ + # It can be referenced to as `::std::string` or `std::string` + r"::std::string", + r"\bstd::string\b", +] + + +def post_build(self): + # Replace std::string with TProtoStringType. + for pattern in POSSIBLE_STD_STRING_USAGE_PATTERNS: + fileutil.re_sub_dir( + self.dstdir, + pattern, + "TProtoStringType", + # Only apply replacements to C++ code + test=pathutil.is_preprocessable, + ) + + +def post_install(self): + with self.yamakes["."] as libprotobuf: + libprotobuf.PROVIDES = ["protobuf"] + + libprotobuf.SRCS.update(RUNTIME_YANDEX_SPECIFIC_SOURCES) + libprotobuf.SRCS.update(DEPRECATED_SRC) # This files should be removed after protobuf update + libprotobuf.NO_UTIL = False + + # Work around fixed_address_empty_string initialization on macOS. + gmu = "src/google/protobuf/generated_message_util.cc" + libprotobuf.SRCS.remove(gmu) + libprotobuf.SRCS.add(ArcPath(gmu, GLOBAL=True)) + + # These sources are parts of protoc, they should not be linked into runtime + for src in RUNTIME_EXCESS_SOURCES: + libprotobuf.SRCS.remove(src) + + libprotobuf.after( + "CFLAGS", + Switch( + OS_ANDROID=Linkable( + # Link with system android log library + # Android logging is used in stubs/common.cc + EXTRALIBS=["log"] + ) + ), + ) + + libprotobuf.after("SRCS", Linkable(FILES=RUNTIME_PROTO_FILES)) + libprotobuf.after( + "ORIGINAL_SOURCE", + """IF (OPENSOURCE_REPLACE_PROTOBUF AND EXPORT_CMAKE) + + OPENSOURCE_EXPORT_REPLACEMENT( + CMAKE Protobuf + CMAKE_TARGET protobuf::libprotobuf protobuf::libprotoc + CONAN protobuf/${OPENSOURCE_REPLACE_PROTOBUF} + CONAN_ADDITIONAL_SEMS + "&& conan_require_tool" protobuf/${OPENSOURCE_REPLACE_PROTOBUF} "&& conan-tool_requires" protobuf/${OPENSOURCE_REPLACE_PROTOBUF} + "&& conan_import \\"bin, protoc* -> ./bin\\" && conan-imports 'bin, protoc* -> ./bin' && vanilla_protobuf" + ) + +ELSE() + + ADDINCL( + GLOBAL contrib/libs/protobuf/src + GLOBAL FOR proto contrib/libs/protobuf/src + ) + +ENDIF() +""", + ) + + libprotobuf.ADDINCL = ["contrib/libs/protobuf/third_party/utf8_range"] + + libprotobuf.SRCS.add("third_party/utf8_range/utf8_validity.cc") + + libprotobuf.RECURSE = ["builtin_proto"] + + libprotobuf.PEERDIR.add("library/cpp/sanitizer/include") + + # Dont use full y_absl library + libprotobuf.PEERDIR = set([ + lib for lib in libprotobuf.PEERDIR + if 'abseil-cpp-tstring' not in lib + ]) + libprotobuf.PEERDIR.add("contrib/restricted/abseil-cpp-tstring/y_absl/status") + libprotobuf.PEERDIR.add("contrib/restricted/abseil-cpp-tstring/y_absl/log") + + del self.yamakes["src/google/protobuf/compiler"] + # merging src/google/protobuf/compiler/protoc library and + # src/google/protobuf/compiler binary into top-level binary + with self.yamakes.pop("src/google/protobuf/compiler/protoc") as libprotoc: + libprotoc.VERSION = self.version + libprotoc.ORIGINAL_SOURCE = self.source_url + libprotoc.PROVIDES = ["protoc"] + libprotoc.after("LICENSE", "LICENSE_TEXTS(.yandex_meta/licenses.list.txt)\n") + libprotoc.after( + "ORIGINAL_SOURCE", + """IF (OPENSOURCE_REPLACE_PROTOBUF AND EXPORT_CMAKE) + + OPENSOURCE_EXPORT_REPLACEMENT( + CMAKE Protobuf + CMAKE_TARGET protobuf::libprotobuf protobuf::libprotoc + CONAN protobuf/${OPENSOURCE_REPLACE_PROTOBUF} + CONAN_ADDITIONAL_SEMS + "&& conan_require_tool" protobuf/${OPENSOURCE_REPLACE_PROTOBUF} "&& conan-tool_requires" protobuf/${OPENSOURCE_REPLACE_PROTOBUF} + "&& conan_import \\"bin, protoc* -> ./bin\\" && conan-imports 'bin, protoc* -> ./bin' && vanilla_protobuf" + ) + +ELSE() + + ADDINCL( + GLOBAL contrib/libs/protoc/src + ) + +ENDIF() +""", + ) + + libprotoc.ADDINCL = ["contrib/libs/protobuf/third_party/utf8_range"] + + libprotoc.SRCS = {os.path.join("src/google/protobuf/compiler", src) for src in libprotoc.SRCS} + # Moving a couple of sources from runtime library to compiler (where they actually belong) + libprotoc.SRCS.update(RUNTIME_EXCESS_SOURCES) + + libprotoc.SRCDIR = None + + # Unbundle libprotobuf.la which confuses yamaker by being linked statically + libprotoc.PEERDIR = {self.arcdir} + + libprotoc_abs_dir = os.path.join(self.ctx.arc, LIBPROTOC_DIR) + + fileutil.copy( + os.path.join(self.dstdir, "src/google/protobuf/compiler"), + os.path.join(libprotoc_abs_dir, "src/google/protobuf"), + replace=True, + move=True, + ) + + fileutil.copy( + [os.path.join(self.dstdir, "LICENSE")], + libprotoc_abs_dir, + replace=True, + move=False, + ) + + for lang in ["csharp", "objectivec"]: + for root, _, files in os.walk(os.path.join(libprotoc_abs_dir, "src/google/protobuf/compiler", lang)): + for file in files: + if file.endswith('.h'): + with open(os.path.join(root, lang + '_' + file), 'w') as f: + f.write(f'#include "{file}"\n') + f.write('#include "names.h"') + + # generate temporal proxy for ydb + with open(os.path.join(libprotoc_abs_dir, "src/google/protobuf/compiler/cpp/cpp_helpers.h"), 'w') as f: + f.write('#include "helpers.h"') + + with open(f"{libprotoc_abs_dir}/ya.make", "wt") as ymake: + ymake.write(str(libprotoc)) + + with open(os.path.join(self.ctx.arc, self.arcdir, "src/google/protobuf/util/json_util.h"), 'w') as f: + f.write('#define USE_DEPRECATED_NAMESPACE 1\n#include "google/protobuf/json/json.h"') + + +protobuf = CMakeNinjaNixProject( + owners=["g:cpp-committee", "g:cpp-contrib"], + arcdir="contrib/libs/protobuf", + nixattr="protobuf", + license_analysis_extra_dirs=[ + LIBPROTOC_DIR, + ], + install_targets=[ + # Do not install protobuf lite, as nobody needs it + "protobuf", + # Specifying protoc will install both libprotoc and protoc executable + "protoc", + ], + unbundle_from={"abseil-cpp": "third_party/abseil-cpp"}, + put={"protobuf": "."}, + disable_includes=[ + "sys/isa_defs.h", + ], + keep_paths=[ + # ya.make generation for legacy PACKAGE at protobuf/python/ya.make is not configure by yamaker. + "python/ya.make", + # built-in protobufs need to be exposed via PROTO_LIBRARY. + # Needed at least for Python and for complete descriptors generation + "builtin_proto", + # yandex-specific files. Should be moved out of the project, if possible + "src/google/protobuf/messagext.*", + *DEPRECATED_STUBS, + ], + copy_sources=( + RUNTIME_PROTO_FILES + + PROTOC_PROTO_FILES + + [ + # java_names.h is required by contrib/libs/grpc-java + "src/google/protobuf/compiler/java/java_names.h", + ] + ), + post_build=post_build, + post_install=post_install, +) diff --git a/contrib/libs/protobuf/.yandex_meta/devtools.copyrights.report b/contrib/libs/protobuf/.yandex_meta/devtools.copyrights.report new file mode 100644 index 0000000000..7cde4b56cd --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/devtools.copyrights.report @@ -0,0 +1,287 @@ +# File format ($ symbol means the beginning of a line): +# +# $ # this message +# $ # ======================= +# $ # comments (all commentaries should starts with some number of spaces and # symbol) +# ${action} {license id} {license text hash} +# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make +# ${all_file_action} filename +# $ # user commentaries (many lines) +# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify) +# ${action} {license spdx} {license text hash} +# $BELONGS ./ya/make/file/relative/path/3/ya.make +# ${all_file_action} filename +# $ # user commentaries +# $ generated description +# $ ... +# +# You can modify action, all_file_action and add commentaries +# Available actions: +# keep - keep license in contrib and use in credits +# skip - skip license +# remove - remove all files with this license +# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file +# +# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory) +# We suppose that that files can contain some license info +# Available all file actions: +# FILE_IGNORE - ignore file (do nothing) +# FILE_INCLUDE - include all file data into licenses text file +# ======================= + +KEEP COPYRIGHT_SERVICE_LABEL 0cda88d047ce1cbd63afdf716f1ace43 +BELONGS ya.make + License text: + Copyright (c) 2019 Yibo Cai + Copyright 2022 Google LLC + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + third_party/utf8_range/LICENSE [3:4] + +KEEP COPYRIGHT_SERVICE_LABEL 6229b3029004c1905fe5e24a63be2311 +BELONGS ya.make + License text: + // Copyright 2023 Google Inc. All rights reserved. + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + src/google/protobuf/string_block.h [2:2] + +KEEP COPYRIGHT_SERVICE_LABEL 6518b015a67ef080ce14d2b770875d6a +BELONGS ya.make + License text: + // Copyright 2014 Google Inc. All rights reserved. + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + src/google/protobuf/stubs/map_util.h [2:2] + +KEEP COPYRIGHT_SERVICE_LABEL 7ddb2995f48012001146c0eb94d23367 +BELONGS ya.make + License text: + Copyright 2008 Google Inc. All rights reserved. + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + LICENSE [1:1] + src/google/protobuf/any.cc [2:2] + src/google/protobuf/any.h [2:2] + src/google/protobuf/any.proto [2:2] + src/google/protobuf/any_lite.cc [2:2] + src/google/protobuf/api.proto [2:2] + src/google/protobuf/arena.cc [2:2] + src/google/protobuf/arena.h [2:2] + src/google/protobuf/arena_align.cc [2:2] + src/google/protobuf/arena_align.h [2:2] + src/google/protobuf/arena_allocation_policy.h [2:2] + src/google/protobuf/arena_cleanup.h [2:2] + src/google/protobuf/arena_config.cc [2:2] + src/google/protobuf/arena_config.h [2:2] + src/google/protobuf/arenastring.cc [2:2] + src/google/protobuf/arenastring.h [2:2] + src/google/protobuf/arenaz_sampler.cc [2:2] + src/google/protobuf/arenaz_sampler.h [2:2] + src/google/protobuf/descriptor.cc [2:2] + src/google/protobuf/descriptor.h [2:2] + src/google/protobuf/descriptor.proto [2:2] + src/google/protobuf/descriptor_database.cc [2:2] + src/google/protobuf/descriptor_database.h [2:2] + src/google/protobuf/duration.proto [2:2] + src/google/protobuf/dynamic_message.cc [2:2] + src/google/protobuf/dynamic_message.h [2:2] + src/google/protobuf/empty.proto [2:2] + src/google/protobuf/endian.h [2:2] + src/google/protobuf/explicitly_constructed.h [2:2] + src/google/protobuf/extension_set.cc [2:2] + src/google/protobuf/extension_set.h [2:2] + src/google/protobuf/extension_set_heavy.cc [2:2] + src/google/protobuf/extension_set_inl.h [2:2] + src/google/protobuf/field_mask.proto [2:2] + src/google/protobuf/generated_enum_reflection.h [2:2] + src/google/protobuf/generated_enum_util.cc [2:2] + src/google/protobuf/generated_enum_util.h [2:2] + src/google/protobuf/generated_message_bases.cc [2:2] + src/google/protobuf/generated_message_bases.h [2:2] + src/google/protobuf/generated_message_reflection.cc [2:2] + src/google/protobuf/generated_message_reflection.h [2:2] + src/google/protobuf/generated_message_tctable_decl.h [2:2] + src/google/protobuf/generated_message_tctable_full.cc [2:2] + src/google/protobuf/generated_message_tctable_gen.cc [2:2] + src/google/protobuf/generated_message_tctable_gen.h [2:2] + src/google/protobuf/generated_message_tctable_impl.h [2:2] + src/google/protobuf/generated_message_tctable_lite.cc [2:2] + src/google/protobuf/generated_message_util.cc [2:2] + src/google/protobuf/generated_message_util.h [2:2] + src/google/protobuf/has_bits.h [2:2] + src/google/protobuf/implicit_weak_message.cc [2:2] + src/google/protobuf/implicit_weak_message.h [2:2] + src/google/protobuf/inlined_string_field.cc [2:2] + src/google/protobuf/inlined_string_field.h [2:2] + src/google/protobuf/io/coded_stream.cc [2:2] + src/google/protobuf/io/coded_stream.h [2:2] + src/google/protobuf/io/gzip_stream.cc [2:2] + src/google/protobuf/io/gzip_stream.h [2:2] + src/google/protobuf/io/io_win32.cc [2:2] + src/google/protobuf/io/io_win32.h [2:2] + src/google/protobuf/io/printer.cc [2:2] + src/google/protobuf/io/printer.h [2:2] + src/google/protobuf/io/strtod.cc [2:2] + src/google/protobuf/io/strtod.h [2:2] + src/google/protobuf/io/tokenizer.cc [2:2] + src/google/protobuf/io/tokenizer.h [2:2] + src/google/protobuf/io/zero_copy_sink.cc [2:2] + src/google/protobuf/io/zero_copy_sink.h [2:2] + src/google/protobuf/io/zero_copy_stream.cc [2:2] + src/google/protobuf/io/zero_copy_stream.h [2:2] + src/google/protobuf/io/zero_copy_stream_impl.cc [2:2] + src/google/protobuf/io/zero_copy_stream_impl.h [2:2] + src/google/protobuf/io/zero_copy_stream_impl_lite.cc [2:2] + src/google/protobuf/io/zero_copy_stream_impl_lite.h [2:2] + src/google/protobuf/json/internal/descriptor_traits.h [2:2] + src/google/protobuf/json/internal/lexer.cc [2:2] + src/google/protobuf/json/internal/lexer.h [2:2] + src/google/protobuf/json/internal/message_path.cc [2:2] + src/google/protobuf/json/internal/message_path.h [2:2] + src/google/protobuf/json/internal/parser.cc [2:2] + src/google/protobuf/json/internal/parser.h [2:2] + src/google/protobuf/json/internal/parser_traits.h [2:2] + src/google/protobuf/json/internal/unparser.cc [2:2] + src/google/protobuf/json/internal/unparser.h [2:2] + src/google/protobuf/json/internal/unparser_traits.h [2:2] + src/google/protobuf/json/internal/untyped_message.cc [2:2] + src/google/protobuf/json/internal/untyped_message.h [3:3] + src/google/protobuf/json/internal/writer.cc [2:2] + src/google/protobuf/json/internal/writer.h [2:2] + src/google/protobuf/json/internal/zero_copy_buffered_stream.cc [2:2] + src/google/protobuf/json/internal/zero_copy_buffered_stream.h [2:2] + src/google/protobuf/json/json.cc [2:2] + src/google/protobuf/json/json.h [2:2] + src/google/protobuf/json/old_json.cc [2:2] + src/google/protobuf/map.cc [2:2] + src/google/protobuf/map.h [2:2] + src/google/protobuf/map_entry.h [2:2] + src/google/protobuf/map_entry_lite.h [2:2] + src/google/protobuf/map_field.cc [2:2] + src/google/protobuf/map_field.h [2:2] + src/google/protobuf/map_field_inl.h [2:2] + src/google/protobuf/map_field_lite.h [2:2] + src/google/protobuf/map_type_handler.h [2:2] + src/google/protobuf/message.cc [2:2] + src/google/protobuf/message.h [2:2] + src/google/protobuf/message_lite.cc [2:2] + src/google/protobuf/message_lite.h [2:2] + src/google/protobuf/metadata_lite.h [2:2] + src/google/protobuf/parse_context.cc [2:2] + src/google/protobuf/parse_context.h [2:2] + src/google/protobuf/port.h [2:2] + src/google/protobuf/port_def.inc [3:3] + src/google/protobuf/port_undef.inc [3:3] + src/google/protobuf/reflection.h [2:2] + src/google/protobuf/reflection_internal.h [2:2] + src/google/protobuf/reflection_ops.cc [2:2] + src/google/protobuf/reflection_ops.h [2:2] + src/google/protobuf/repeated_field.cc [2:2] + src/google/protobuf/repeated_field.h [2:2] + src/google/protobuf/repeated_ptr_field.cc [2:2] + src/google/protobuf/repeated_ptr_field.h [2:2] + src/google/protobuf/service.cc [2:2] + src/google/protobuf/service.h [2:2] + src/google/protobuf/source_context.proto [2:2] + src/google/protobuf/struct.proto [2:2] + src/google/protobuf/stubs/callback.h [2:2] + src/google/protobuf/stubs/common.cc [2:2] + src/google/protobuf/stubs/common.h [2:2] + src/google/protobuf/stubs/hash.h [2:2] + src/google/protobuf/stubs/port.h [2:2] + src/google/protobuf/stubs/status.cc [2:2] + src/google/protobuf/stubs/status.h [2:2] + src/google/protobuf/stubs/status_macros.h [2:2] + src/google/protobuf/stubs/stl_util.h [2:2] + src/google/protobuf/stubs/stringpiece.cc [2:2] + src/google/protobuf/stubs/stringpiece.h [2:2] + src/google/protobuf/stubs/structurally_valid.cc [2:2] + src/google/protobuf/stubs/strutil.cc [2:2] + src/google/protobuf/stubs/strutil.h [2:2] + src/google/protobuf/stubs/substitute.cc [2:2] + src/google/protobuf/stubs/substitute.h [2:2] + src/google/protobuf/text_format.cc [2:2] + src/google/protobuf/text_format.h [2:2] + src/google/protobuf/timestamp.proto [2:2] + src/google/protobuf/type.proto [2:2] + src/google/protobuf/unknown_field_set.cc [2:2] + src/google/protobuf/unknown_field_set.h [2:2] + src/google/protobuf/util/delimited_message_util.cc [2:2] + src/google/protobuf/util/delimited_message_util.h [2:2] + src/google/protobuf/util/field_comparator.cc [2:2] + src/google/protobuf/util/field_comparator.h [2:2] + src/google/protobuf/util/field_mask_util.cc [2:2] + src/google/protobuf/util/field_mask_util.h [2:2] + src/google/protobuf/util/message_differencer.cc [2:2] + src/google/protobuf/util/message_differencer.h [2:2] + src/google/protobuf/util/time_util.cc [2:2] + src/google/protobuf/util/time_util.h [2:2] + src/google/protobuf/util/type_resolver.h [2:2] + src/google/protobuf/util/type_resolver_util.cc [2:2] + src/google/protobuf/util/type_resolver_util.h [2:2] + src/google/protobuf/wire_format.cc [2:2] + src/google/protobuf/wire_format.h [2:2] + src/google/protobuf/wire_format_lite.cc [2:2] + src/google/protobuf/wire_format_lite.h [2:2] + src/google/protobuf/wrappers.proto [2:2] + +KEEP COPYRIGHT_SERVICE_LABEL 97ff8757487be6d08b12d53768dd6984 +BELONGS ya.make + License text: + // Copyright 2012 Google Inc. All rights reserved. + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + src/google/protobuf/stubs/platform_macros.h [2:2] + +KEEP COPYRIGHT_SERVICE_LABEL a562064d974c30e7a4bc2db6f9a9a839 +BELONGS ya.make + License text: + // Copyright 2022 Google Inc. All rights reserved. + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + src/google/protobuf/serial_arena.h [2:2] + src/google/protobuf/thread_safe_arena.h [2:2] + +KEEP COPYRIGHT_SERVICE_LABEL b67954d56c1fd3e172b8af93180a9a4e +BELONGS ya.make + License text: + static bool IsLowerOrDigit(char c) { return IsLower(c) || IsDigit(c); } + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + src/google/protobuf/descriptor.cc [544:544] + +KEEP COPYRIGHT_SERVICE_LABEL e618dd164932f955bb8121f5f486e841 +BELONGS ya.make + License text: + Copyright (c) 2019 Yibo Cai + Copyright 2022 Google LLC + Scancode info: + Original SPDX id: COPYRIGHT_SERVICE_LABEL + Score : 100.00 + Match type : COPYRIGHT + Files with this license: + third_party/utf8_range/LICENSE [3:4] + third_party/utf8_range/utf8_validity.cc [1:1] + third_party/utf8_range/utf8_validity.h [1:1] diff --git a/contrib/libs/protobuf/.yandex_meta/devtools.licenses.report b/contrib/libs/protobuf/.yandex_meta/devtools.licenses.report new file mode 100644 index 0000000000..ede92e77fa --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/devtools.licenses.report @@ -0,0 +1,335 @@ +# File format ($ symbol means the beginning of a line): +# +# $ # this message +# $ # ======================= +# $ # comments (all commentaries should starts with some number of spaces and # symbol) +# ${action} {license spdx} {license text hash} +# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make +# ${all_file_action} filename +# $ # user commentaries (many lines) +# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify) +# ${action} {license spdx} {license text hash} +# $BELONGS ./ya/make/file/relative/path/3/ya.make +# ${all_file_action} filename +# $ # user commentaries +# $ generated description +# $ ... +# +# You can modify action, all_file_action and add commentaries +# Available actions: +# keep - keep license in contrib and use in credits +# skip - skip license +# remove - remove all files with this license +# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file +# +# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory) +# We suppose that that files can contain some license info +# Available all file actions: +# FILE_IGNORE - ignore file (do nothing) +# FILE_INCLUDE - include all file data into licenses text file +# ======================= + +SKIP CC-BY-4.0 0ec92fc648504d1069b11b64e44bfdc4 +BELONGS ya.make + License text: + Markus Kuhn [ˈmaʳkʊs kuːn] <http://www.cl.cam.ac.uk/~mgk25/> — 2002-07-25 CC BY + Scancode info: + Original SPDX id: CC-BY-4.0 + Score : 50.00 + Match type : REFERENCE + Links : http://creativecommons.org/licenses/by/4.0/, http://creativecommons.org/licenses/by/4.0/legalcode, https://spdx.org/licenses/CC-BY-4.0 + Files with this license: + third_party/utf8_range/UTF-8-demo.txt [5:5] + +KEEP MIT 399584035c417b91040964779555dfac +BELONGS ya.make + License text: + MIT License + Scancode info: + Original SPDX id: MIT + Score : 100.00 + Match type : REFERENCE + Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT + Files with this license: + third_party/utf8_range/LICENSE [1:1] + +KEEP MIT 4b22d8fd72d8f6c6211edffd2b6983d7 +BELONGS ya.make +FILE_INCLUDE LICENSE found in files: third_party/utf8_range/utf8_validity.cc at line 4, third_party/utf8_range/utf8_validity.h at line 4 +FILE_INCLUDE third_party/utf8_range/LICENSE found in files: third_party/utf8_range/utf8_validity.cc at line 4, third_party/utf8_range/utf8_validity.h at line 4 + License text: + // Use of this source code is governed by an MIT-style + // license that can be found in the LICENSE file or at + // https://opensource.org/licenses/MIT. + Scancode info: + Original SPDX id: MIT + Score : 100.00 + Match type : NOTICE + Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT + Files with this license: + third_party/utf8_range/utf8_validity.cc [3:5] + third_party/utf8_range/utf8_validity.h [3:5] + +KEEP MIT 54575e81a786e9aa7d98337ec2e1ebb0 +BELONGS ya.make + Note: matched license text is too long. Read it in the source files. + Scancode info: + Original SPDX id: MIT + Score : 100.00 + Match type : TEXT + Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT + Files with this license: + third_party/utf8_range/LICENSE [6:22] + +SKIP LicenseRef-scancode-generic-cla 5d780ffa423067f23c6a123ae33e7c18 +BELONGS ya.make + License text: + \## Contributor License Agreement + Scancode info: + Original SPDX id: LicenseRef-scancode-generic-cla + Score : 16.00 + Match type : NOTICE + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/generic-cla.LICENSE + Files with this license: + third_party/utf8_range/CONTRIBUTING.md [8:8] + +SKIP LicenseRef-scancode-proprietary-license 67e6ac0ff3543e750737c958f31bbc07 +BELONGS ya.make + License text: + // a reasonable default is used. The caller retains ownership of + // copying_stream unless SetOwnsCopyingStream(true) is called. + Scancode info: + Original SPDX id: LicenseRef-scancode-proprietary-license + Score : 4.94 + Match type : TEXT + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/proprietary-license.LICENSE + Files with this license: + src/google/protobuf/io/zero_copy_stream_impl_lite.h [218:219] + +KEEP BSD-3-Clause 6aa235708ac9f5dd8e5c6ac415fc5837 +BELONGS ya.make + Note: matched license text is too long. Read it in the source files. + Scancode info: + Original SPDX id: BSD-3-Clause + Score : 100.00 + Match type : TEXT + Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause + Files with this license: + src/google/protobuf/any.cc [5:29] + src/google/protobuf/any.h [5:29] + src/google/protobuf/any.proto [5:29] + src/google/protobuf/any_lite.cc [5:29] + src/google/protobuf/api.proto [5:29] + src/google/protobuf/arena.cc [5:29] + src/google/protobuf/arena.h [5:29] + src/google/protobuf/arena_align.cc [5:29] + src/google/protobuf/arena_align.h [5:29] + src/google/protobuf/arena_allocation_policy.h [5:29] + src/google/protobuf/arena_cleanup.h [5:29] + src/google/protobuf/arena_config.cc [5:29] + src/google/protobuf/arena_config.h [5:29] + src/google/protobuf/arenastring.cc [5:29] + src/google/protobuf/arenastring.h [5:29] + src/google/protobuf/arenaz_sampler.cc [5:29] + src/google/protobuf/arenaz_sampler.h [5:29] + src/google/protobuf/descriptor.cc [5:29] + src/google/protobuf/descriptor.h [5:29] + src/google/protobuf/descriptor.proto [5:29] + src/google/protobuf/descriptor_database.cc [5:29] + src/google/protobuf/descriptor_database.h [5:29] + src/google/protobuf/duration.proto [5:29] + src/google/protobuf/dynamic_message.cc [5:29] + src/google/protobuf/dynamic_message.h [5:29] + src/google/protobuf/empty.proto [5:29] + src/google/protobuf/endian.h [5:29] + src/google/protobuf/explicitly_constructed.h [5:29] + src/google/protobuf/extension_set.cc [5:29] + src/google/protobuf/extension_set.h [5:29] + src/google/protobuf/extension_set_heavy.cc [5:29] + src/google/protobuf/extension_set_inl.h [5:29] + src/google/protobuf/field_mask.proto [5:29] + src/google/protobuf/generated_enum_reflection.h [5:29] + src/google/protobuf/generated_enum_util.cc [5:29] + src/google/protobuf/generated_enum_util.h [5:29] + src/google/protobuf/generated_message_bases.cc [5:29] + src/google/protobuf/generated_message_bases.h [5:29] + src/google/protobuf/generated_message_reflection.cc [5:29] + src/google/protobuf/generated_message_reflection.h [5:29] + src/google/protobuf/generated_message_tctable_decl.h [5:29] + src/google/protobuf/generated_message_tctable_full.cc [5:29] + src/google/protobuf/generated_message_tctable_gen.cc [5:29] + src/google/protobuf/generated_message_tctable_gen.h [5:29] + src/google/protobuf/generated_message_tctable_impl.h [5:29] + src/google/protobuf/generated_message_tctable_lite.cc [5:29] + src/google/protobuf/generated_message_util.cc [5:29] + src/google/protobuf/generated_message_util.h [5:29] + src/google/protobuf/has_bits.h [5:29] + src/google/protobuf/implicit_weak_message.cc [5:29] + src/google/protobuf/implicit_weak_message.h [5:29] + src/google/protobuf/inlined_string_field.cc [5:29] + src/google/protobuf/inlined_string_field.h [5:29] + src/google/protobuf/io/coded_stream.cc [5:29] + src/google/protobuf/io/coded_stream.h [5:29] + src/google/protobuf/io/gzip_stream.cc [5:29] + src/google/protobuf/io/gzip_stream.h [5:29] + src/google/protobuf/io/io_win32.cc [5:29] + src/google/protobuf/io/io_win32.h [5:29] + src/google/protobuf/io/printer.cc [5:29] + src/google/protobuf/io/printer.h [5:29] + src/google/protobuf/io/strtod.cc [5:29] + src/google/protobuf/io/strtod.h [5:29] + src/google/protobuf/io/tokenizer.cc [5:29] + src/google/protobuf/io/tokenizer.h [5:29] + src/google/protobuf/io/zero_copy_sink.cc [5:29] + src/google/protobuf/io/zero_copy_sink.h [5:29] + src/google/protobuf/io/zero_copy_stream.cc [5:29] + src/google/protobuf/io/zero_copy_stream.h [5:29] + src/google/protobuf/io/zero_copy_stream_impl.cc [5:29] + src/google/protobuf/io/zero_copy_stream_impl.h [5:29] + src/google/protobuf/io/zero_copy_stream_impl_lite.cc [5:29] + src/google/protobuf/io/zero_copy_stream_impl_lite.h [5:29] + src/google/protobuf/json/internal/descriptor_traits.h [5:29] + src/google/protobuf/json/internal/lexer.cc [5:29] + src/google/protobuf/json/internal/lexer.h [5:29] + src/google/protobuf/json/internal/message_path.cc [5:29] + src/google/protobuf/json/internal/message_path.h [5:29] + src/google/protobuf/json/internal/parser.cc [5:29] + src/google/protobuf/json/internal/parser.h [5:29] + src/google/protobuf/json/internal/parser_traits.h [5:29] + src/google/protobuf/json/internal/unparser.cc [5:29] + src/google/protobuf/json/internal/unparser.h [5:29] + src/google/protobuf/json/internal/unparser_traits.h [5:29] + src/google/protobuf/json/internal/untyped_message.cc [5:29] + src/google/protobuf/json/internal/untyped_message.h [6:30] + src/google/protobuf/json/internal/writer.cc [5:29] + src/google/protobuf/json/internal/writer.h [5:29] + src/google/protobuf/json/internal/zero_copy_buffered_stream.cc [5:29] + src/google/protobuf/json/internal/zero_copy_buffered_stream.h [5:29] + src/google/protobuf/json/json.cc [5:29] + src/google/protobuf/json/json.h [5:29] + src/google/protobuf/json/old_json.cc [5:29] + src/google/protobuf/map.cc [5:29] + src/google/protobuf/map.h [5:29] + src/google/protobuf/map_entry.h [5:29] + src/google/protobuf/map_entry_lite.h [5:29] + src/google/protobuf/map_field.cc [5:29] + src/google/protobuf/map_field.h [5:29] + src/google/protobuf/map_field_inl.h [5:29] + src/google/protobuf/map_field_lite.h [5:29] + src/google/protobuf/map_type_handler.h [5:29] + src/google/protobuf/message.cc [5:29] + src/google/protobuf/message.h [5:29] + src/google/protobuf/message_lite.cc [5:29] + src/google/protobuf/message_lite.h [5:29] + src/google/protobuf/metadata_lite.h [5:29] + src/google/protobuf/parse_context.cc [5:29] + src/google/protobuf/parse_context.h [5:29] + src/google/protobuf/port.h [5:29] + src/google/protobuf/port_def.inc [6:30] + src/google/protobuf/port_undef.inc [6:30] + src/google/protobuf/reflection.h [5:29] + src/google/protobuf/reflection_internal.h [5:29] + src/google/protobuf/reflection_ops.cc [5:29] + src/google/protobuf/reflection_ops.h [5:29] + src/google/protobuf/repeated_field.cc [5:29] + src/google/protobuf/repeated_field.h [5:29] + src/google/protobuf/repeated_ptr_field.cc [5:29] + src/google/protobuf/repeated_ptr_field.h [5:29] + src/google/protobuf/serial_arena.h [5:29] + src/google/protobuf/service.cc [5:29] + src/google/protobuf/service.h [5:29] + src/google/protobuf/source_context.proto [5:29] + src/google/protobuf/string_block.h [5:29] + src/google/protobuf/struct.proto [5:29] + src/google/protobuf/stubs/callback.h [5:29] + src/google/protobuf/stubs/common.cc [5:29] + src/google/protobuf/stubs/common.h [5:29] + src/google/protobuf/stubs/hash.h [5:29] + src/google/protobuf/stubs/map_util.h [5:29] + src/google/protobuf/stubs/platform_macros.h [5:29] + src/google/protobuf/stubs/port.h [5:29] + src/google/protobuf/stubs/status.cc [5:29] + src/google/protobuf/stubs/status.h [5:29] + src/google/protobuf/stubs/status_macros.h [5:29] + src/google/protobuf/stubs/stl_util.h [5:29] + src/google/protobuf/stubs/stringpiece.cc [5:29] + src/google/protobuf/stubs/stringpiece.h [5:29] + src/google/protobuf/stubs/structurally_valid.cc [5:29] + src/google/protobuf/stubs/strutil.cc [5:29] + src/google/protobuf/stubs/strutil.h [5:29] + src/google/protobuf/stubs/substitute.cc [5:29] + src/google/protobuf/stubs/substitute.h [5:29] + src/google/protobuf/text_format.cc [5:29] + src/google/protobuf/text_format.h [5:29] + src/google/protobuf/thread_safe_arena.h [5:29] + src/google/protobuf/timestamp.proto [5:29] + src/google/protobuf/type.proto [5:29] + src/google/protobuf/unknown_field_set.cc [5:29] + src/google/protobuf/unknown_field_set.h [5:29] + src/google/protobuf/util/delimited_message_util.cc [5:29] + src/google/protobuf/util/delimited_message_util.h [5:29] + src/google/protobuf/util/field_comparator.cc [5:29] + src/google/protobuf/util/field_comparator.h [5:29] + src/google/protobuf/util/field_mask_util.cc [5:29] + src/google/protobuf/util/field_mask_util.h [5:29] + src/google/protobuf/util/message_differencer.cc [5:29] + src/google/protobuf/util/message_differencer.h [5:29] + src/google/protobuf/util/time_util.cc [5:29] + src/google/protobuf/util/time_util.h [5:29] + src/google/protobuf/util/type_resolver.h [5:29] + src/google/protobuf/util/type_resolver_util.cc [5:29] + src/google/protobuf/util/type_resolver_util.h [5:29] + src/google/protobuf/wire_format.cc [5:29] + src/google/protobuf/wire_format.h [5:29] + src/google/protobuf/wire_format_lite.cc [5:29] + src/google/protobuf/wire_format_lite.h [5:29] + src/google/protobuf/wrappers.proto [5:29] + +KEEP Protobuf-License 77b55cb8215e726b6ae7c1cf484bc45f +BELONGS ya.make + Note: matched license text is too long. Read it in the source files. + Scancode info: + Original SPDX id: LicenseRef-scancode-protobuf + Score : 100.00 + Match type : TEXT + Links : http://protobuf.googlecode.com/svn/trunk/COPYING.txt, https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/protobuf.LICENSE + Files with this license: + LICENSE [3:32] + +SKIP LicenseRef-scancode-generic-cla beb3339ebeb4487c0ec15f216cc26cb2 +BELONGS ya.make + License text: + \### Contributor License Agreements + Scancode info: + Original SPDX id: LicenseRef-scancode-generic-cla + Score : 80.00 + Match type : NOTICE + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/generic-cla.LICENSE + Files with this license: + CONTRIBUTING.md [35:35] + +SKIP LicenseRef-scancode-generic-cla d629c1791f1024cda2ec24fa16773bcd +BELONGS ya.make + License text: + Contributions to this project must be accompanied by a Contributor License + Agreement (CLA). You (or your employer) retain the copyright to your + Scancode info: + Original SPDX id: LicenseRef-scancode-generic-cla + Score : 22.00 + Match type : NOTICE + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/generic-cla.LICENSE + Files with this license: + third_party/utf8_range/CONTRIBUTING.md [10:11] + +SKIP LicenseRef-scancode-generic-cla d72fcd21b18e44b666a94e6225ed43eb +BELONGS ya.make + License text: + Contributions to this project must be accompanied by a Contributor License + Agreement. You (or your employer) retain the copyright to your contribution, + Scancode info: + Original SPDX id: LicenseRef-scancode-generic-cla + Score : 16.00 + Match type : NOTICE + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/generic-cla.LICENSE + Files with this license: + CONTRIBUTING.md [37:38] diff --git a/contrib/libs/protobuf/.yandex_meta/licenses.list.txt b/contrib/libs/protobuf/.yandex_meta/licenses.list.txt new file mode 100644 index 0000000000..3e71f500ac --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/licenses.list.txt @@ -0,0 +1,177 @@ +====================BSD-3-Clause==================== +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT +// OWNER 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. + + +====================COPYRIGHT==================== + static bool IsLowerOrDigit(char c) { return IsLower(c) || IsDigit(c); } + + +====================COPYRIGHT==================== +// Copyright 2012 Google Inc. All rights reserved. + + +====================COPYRIGHT==================== +// Copyright 2014 Google Inc. All rights reserved. + + +====================COPYRIGHT==================== +// Copyright 2022 Google Inc. All rights reserved. + + +====================COPYRIGHT==================== +// Copyright 2023 Google Inc. All rights reserved. + + +====================COPYRIGHT==================== +Copyright (c) 2019 Yibo Cai +Copyright 2022 Google LLC + + +====================COPYRIGHT==================== +Copyright 2008 Google Inc. All rights reserved. + + +====================File: LICENSE==================== +Copyright 2008 Google 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: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * 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. + * Neither the name of Google Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT +OWNER 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. + +Code generated by the Protocol Buffer compiler is owned by the owner +of the input file used when generating it. This code is not +standalone and requires a support library to be linked with it. This +support library is itself covered by the above license. + + +====================File: third_party/utf8_range/LICENSE==================== +MIT License + +Copyright (c) 2019 Yibo Cai +Copyright 2022 Google LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +====================MIT==================== +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + + +====================MIT==================== +MIT License + + +====================MIT==================== +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +====================Protobuf-License==================== +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * 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. + * Neither the name of Google Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT +OWNER 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. + +Code generated by the Protocol Buffer compiler is owned by the owner +of the input file used when generating it. This code is not +standalone and requires a support library to be linked with it. This +support library is itself covered by the above license.
\ No newline at end of file diff --git a/contrib/libs/protobuf/.yandex_meta/override.nix b/contrib/libs/protobuf/.yandex_meta/override.nix new file mode 100644 index 0000000000..72712ffb99 --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/override.nix @@ -0,0 +1,22 @@ +pkgs: attrs: with pkgs; with attrs; rec { + version = "3.22.5"; + passthru.version = version; + + src = fetchFromGitHub { + owner = "protocolbuffers"; + repo = "protobuf"; + rev = "v${version}"; + hash = "sha256-NMEij1eFg9bMVlNSOg1WJbXK0teeSVev9UUNxiC1AC0="; + + fetchSubmodules = true; + }; + + patches = [ + ./unversion-protoc.patch + ]; + cmakeFlags = [ + "-Dprotobuf_BUILD_SHARED_LIBS=OFF" + "-DBUILD_SHARED_LIBS=OFF" + ]; +} + diff --git a/contrib/libs/protobuf/.yandex_meta/unversion-protoc.patch b/contrib/libs/protobuf/.yandex_meta/unversion-protoc.patch new file mode 100644 index 0000000000..2f87fcd8d1 --- /dev/null +++ b/contrib/libs/protobuf/.yandex_meta/unversion-protoc.patch @@ -0,0 +1,14 @@ +Partially revert changes made in +https://github.com/protocolbuffers/protobuf/pull/4579 + +diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake +index 385a7a3f3..eec022224 100644 +--- a/cmake/protoc.cmake ++++ b/cmake/protoc.cmake +@@ -9,6 +9,3 @@ target_link_libraries(protoc + ${protobuf_ABSL_USED_TARGETS} + ) + add_executable(protobuf::protoc ALIAS protoc) +- +-set_target_properties(protoc PROPERTIES +- VERSION ${protobuf_VERSION}) diff --git a/contrib/libs/protobuf/patches/add-arcadia-stream-support.patch b/contrib/libs/protobuf/patches/add-arcadia-stream-support.patch new file mode 100644 index 0000000000..fcc31fe0f9 --- /dev/null +++ b/contrib/libs/protobuf/patches/add-arcadia-stream-support.patch @@ -0,0 +1,94 @@ +--- a/src/google/protobuf/message.cc (index) ++++ b/src/google/protobuf/message.cc (working tree) +@@ -146,6 +146,52 @@ uint8* Message::_InternalSerialize(uint8* target, + return WireFormat::_InternalSerialize(*this, target, stream); + } + ++// Yandex-specific ++void Message::PrintJSON(IOutputStream& out) const { ++ out << "(Something went wrong: no PrintJSON() override provided - are you using a non-styleguided .pb.h?)"; ++} ++ ++bool Message::ParseFromArcadiaStream(IInputStream* input) { ++ bool res = false; ++ io::TInputStreamProxy proxy(input); ++ { ++ io::CopyingInputStreamAdaptor stream(&proxy); ++ res = ParseFromZeroCopyStream(&stream); ++ } ++ return res && !proxy.HasError(); ++} ++ ++bool Message::ParsePartialFromArcadiaStream(IInputStream* input) { ++ bool res = false; ++ io::TInputStreamProxy proxy(input); ++ { ++ io::CopyingInputStreamAdaptor stream(&proxy); ++ res = ParsePartialFromZeroCopyStream(&stream); ++ } ++ return res && !proxy.HasError(); ++} ++ ++bool Message::SerializeToArcadiaStream(IOutputStream* output) const { ++ bool res = false; ++ io::TOutputStreamProxy proxy(output); ++ { ++ io::CopyingOutputStreamAdaptor stream(&proxy); ++ res = SerializeToZeroCopyStream(&stream); ++ } ++ return res && !proxy.HasError(); ++} ++ ++bool Message::SerializePartialToArcadiaStream(IOutputStream* output) const { ++ bool res = false; ++ io::TOutputStreamProxy proxy(output); ++ { ++ io::CopyingOutputStreamAdaptor stream(&proxy); ++ res = SerializePartialToZeroCopyStream(&stream); ++ } ++ return res && !proxy.HasError(); ++} ++// End of Yandex-specific ++ + size_t Message::ByteSizeLong() const { + size_t size = WireFormat::ByteSize(*this); + SetCachedSize(internal::ToCachedSize(size)); +--- a/src/google/protobuf/message.h (index) ++++ b/src/google/protobuf/message.h (working tree) +@@ -126,6 +126,8 @@ + #include "google/protobuf/generated_message_reflection.h" + #include "google/protobuf/generated_message_tctable_decl.h" + #include "google/protobuf/generated_message_util.h" ++#include <google/protobuf/json_util.h> ++#include <google/protobuf/messagext.h> + #include "google/protobuf/map.h" // TODO(b/211442718): cleanup + #include "google/protobuf/message_lite.h" + #include "google/protobuf/port.h" +@@ -341,6 +341,27 @@ class PROTOBUF_EXPORT Message : public MessageLite { + uint8_t* _InternalSerialize(uint8_t* target, + io::EpsCopyOutputStream* stream) const override; + ++ // Yandex-specific ++ bool ParseFromArcadiaStream(IInputStream* input); ++ bool ParsePartialFromArcadiaStream(IInputStream* input); ++ bool SerializeToArcadiaStream(IOutputStream* output) const; ++ bool SerializePartialToArcadiaStream(IOutputStream* output) const; ++ ++ virtual void PrintJSON(IOutputStream&) const; ++ ++ io::TAsJSON<Message> AsJSON() const { ++ return io::TAsJSON<Message>(*this); ++ } ++ ++ internal::TAsBinary AsBinary() const { ++ return internal::TAsBinary{*this}; ++ } ++ ++ internal::TAsStreamSeq AsStreamSeq() const { ++ return internal::TAsStreamSeq{*this}; ++ } ++ // End of Yandex-specific ++ + private: + // This is called only by the default implementation of ByteSize(), to + // update the cached size. If you override ByteSize(), you do not need diff --git a/contrib/libs/protobuf/patches/add-error-methods-not-private.patch b/contrib/libs/protobuf/patches/add-error-methods-not-private.patch new file mode 100644 index 0000000000..29fc82638a --- /dev/null +++ b/contrib/libs/protobuf/patches/add-error-methods-not-private.patch @@ -0,0 +1,20 @@ +--- contrib/libs/protobuf/src/google/protobuf/descriptor.h (d41e0f52b204831b82c746275d9339deba1980b3) ++++ contrib/libs/protobuf/src/google/protobuf/descriptor.h (224e5c6eb476648794a67b47aa67ced218b4043c) +@@ -1952,7 +1952,6 @@ class PROTOBUF_EXPORT DescriptorPool { + PROTOBUF_IGNORE_DEPRECATION_STOP + } + +- private: + // These should never be called directly, but if a legacy class overrides + // them they'll get routed to by the Record* methods. + DUMMY_DEPRECATED("Use RecordError") +--- contrib/libs/protobuf/src/google/protobuf/io/tokenizer.h (d41e0f52b204831b82c746275d9339deba1980b3) ++++ contrib/libs/protobuf/src/google/protobuf/io/tokenizer.h (224e5c6eb476648794a67b47aa67ced218b4043c) +@@ -96,7 +96,6 @@ class PROTOBUF_EXPORT ErrorCollector { + PROTOBUF_IGNORE_DEPRECATION_STOP + } + +- private: + // These should never be called directly, but if a legacy class overrides + // them they'll get routed to by the Record* methods. + DUMMY_DEPRECATED("Use RecordError") diff --git a/contrib/libs/protobuf/patches/add-namespace-nprotobuf.patch b/contrib/libs/protobuf/patches/add-namespace-nprotobuf.patch new file mode 100644 index 0000000000..eb2dbea1a0 --- /dev/null +++ b/contrib/libs/protobuf/patches/add-namespace-nprotobuf.patch @@ -0,0 +1,14 @@ +--- a/src/google/protobuf/stubs/common.h (index) ++++ b/src/google/protobuf/stubs/common.h (working tree) +@@ -127,6 +127,11 @@ void StrongReference(const T& var) { + } // namespace protobuf + } // namespace google + ++namespace NProtoBuf { ++ using namespace google; ++ using namespace google::protobuf; ++} ++ + #include "google/protobuf/port_undef.inc" + + #endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/contrib/libs/protobuf/patches/add-string-using.patch b/contrib/libs/protobuf/patches/add-string-using.patch new file mode 100644 index 0000000000..b56b8c88af --- /dev/null +++ b/contrib/libs/protobuf/patches/add-string-using.patch @@ -0,0 +1,14 @@ +--- contrib/libs/protobuf/src/google/protobuf/stubs/common.h (index) ++++ contrib/libs/protobuf/src/google/protobuf/stubs/common.h (working tree) +@@ -124,6 +124,11 @@ void StrongReference(const T& var) { + } + + } // namespace internal ++ ++// This is at the end of the file instead of the beginning to work around a bug ++// in some versions of MSVC. ++using string = TProtoStringType; ++ + } // namespace protobuf + } // namespace google + diff --git a/contrib/libs/protobuf/patches/back-utf8-check-function.patch b/contrib/libs/protobuf/patches/back-utf8-check-function.patch new file mode 100644 index 0000000000..bd49bdfb8b --- /dev/null +++ b/contrib/libs/protobuf/patches/back-utf8-check-function.patch @@ -0,0 +1,11 @@ +--- contrib/libs/protobuf/src/google/protobuf/stubs/common.h (224e5c6eb476648794a67b47aa67ced218b4043c) ++++ contrib/libs/protobuf/src/google/protobuf/stubs/common.h (4a96e633c1c4d449c2c2adfe068664805ccccfda) +@@ -147,6 +147,8 @@ PROTOBUF_EXPORT void ShutdownProtobufLibrary(); + + namespace internal { + ++PROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); ++ + // Strongly references the given variable such that the linker will be forced + // to pull in this variable's translation unit. + template <typename T> diff --git a/contrib/libs/protobuf/patches/check-json-name-before-deserialization.patch b/contrib/libs/protobuf/patches/check-json-name-before-deserialization.patch new file mode 100644 index 0000000000..3799924ded --- /dev/null +++ b/contrib/libs/protobuf/patches/check-json-name-before-deserialization.patch @@ -0,0 +1,33 @@ +--- contrib/libs/protobuf/src/google/protobuf/json/internal/descriptor_traits.h (2babb01d30e285a96044041b98053d9edbb48b2a) ++++ contrib/libs/protobuf/src/google/protobuf/json/internal/descriptor_traits.h (aa368d72b2d33c8c4857d03624b10b97d2161d61) +@@ -232,6 +232,9 @@ struct Proto2Descriptor { + static absl::string_view FieldJsonName(Field f) { + return f->has_json_name() ? f->json_name() : f->camelcase_name(); + } ++ static bool HasJsonName(Field f) { ++ return f->has_json_name(); ++ } + static absl::string_view FieldFullName(Field f) { return f->full_name(); } + + static absl::string_view FieldTypeName(Field f) { +@@ -399,6 +402,9 @@ struct Proto3Type { + static absl::string_view FieldJsonName(Field f) { + return f->proto().json_name(); + } ++ static bool HasJsonName(Field f) { ++ return true; ++ } + static absl::string_view FieldFullName(Field f) { return f->proto().name(); } + + static absl::string_view FieldTypeName(Field f) { +--- contrib/libs/protobuf/src/google/protobuf/json/internal/unparser.cc (2babb01d30e285a96044041b98053d9edbb48b2a) ++++ contrib/libs/protobuf/src/google/protobuf/json/internal/unparser.cc (aa368d72b2d33c8c4857d03624b10b97d2161d61) +@@ -399,7 +399,7 @@ absl::Status WriteField(JsonWriter& writer, const Msg<Traits>& msg, + // with an uppercase letter, and the Json name does not, we uppercase it. + absl::string_view original_name = Traits::FieldName(field); + absl::string_view json_name = Traits::FieldJsonName(field); +- if (writer.options().allow_legacy_syntax && ++ if (writer.options().allow_legacy_syntax && !Traits::HasJsonName(field) && + absl::ascii_isupper(original_name[0]) && + !absl::ascii_isupper(json_name[0])) { + writer.Write(MakeQuoted(absl::ascii_toupper(original_name[0]), diff --git a/contrib/libs/protobuf/patches/default-comparator-not-final.patch b/contrib/libs/protobuf/patches/default-comparator-not-final.patch new file mode 100644 index 0000000000..7154a924d7 --- /dev/null +++ b/contrib/libs/protobuf/patches/default-comparator-not-final.patch @@ -0,0 +1,17 @@ +commit 90119e80c547f12b1455c27b10223912cce276ce +author: nechda +date: 2024-08-08T14:02:37+03:00 + + [PROTOBUF] DefaultFieldComparator not final class anymore + +--- contrib/libs/protobuf/src/google/protobuf/util/field_comparator.h (03293607825fc752066f258b5641bb694ce9bc61) ++++ contrib/libs/protobuf/src/google/protobuf/util/field_comparator.h (90119e80c547f12b1455c27b10223912cce276ce) +@@ -258,7 +258,7 @@ class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator { + }; + + // Default field comparison: use the basic implementation of FieldComparator. +-class PROTOBUF_EXPORT DefaultFieldComparator final ++class PROTOBUF_EXPORT DefaultFieldComparator + : public SimpleFieldComparator { + public: + ComparisonResult Compare(const Message& message_1, const Message& message_2, diff --git a/contrib/libs/protobuf/patches/deprecated.patch b/contrib/libs/protobuf/patches/deprecated.patch new file mode 100644 index 0000000000..25d2c6f238 --- /dev/null +++ b/contrib/libs/protobuf/patches/deprecated.patch @@ -0,0 +1,29 @@ +--- a/src/google/protobuf/port_def.inc ++++ b/src/google/protobuf/port_def.inc +@@ -375,26 +375,13 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and + #if defined(PROTOBUF_DEPRECATED_MSG) + #error PROTOBUF_DEPRECATED_MSG was previously defined + #endif +-#if __has_attribute(deprecated) || defined(__GNUC__) +-# define PROTOBUF_DEPRECATED __attribute__((deprecated)) +-# define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) +-#elif defined(_MSC_VER) +-# define PROTOBUF_DEPRECATED __declspec(deprecated) +-# define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) +-#else + # define PROTOBUF_DEPRECATED + # define PROTOBUF_DEPRECATED_MSG(msg) +-#endif + + #if defined(PROTOBUF_DEPRECATED_ENUM) + #error PROTOBUF_DEPRECATED_ENUM was previously defined + #endif +-#if defined(__clang__) || defined(__GNUC__) +-// https://gcc.gnu.org/gcc-6/changes.html +-# define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated)) +-#else + # define PROTOBUF_DEPRECATED_ENUM +-#endif + + #if defined(__clang__) + #define PROTOBUF_IGNORE_DEPRECATION_START
\ No newline at end of file diff --git a/contrib/libs/protobuf/patches/disable-deprecated-enum-enum-conversion.patch b/contrib/libs/protobuf/patches/disable-deprecated-enum-enum-conversion.patch new file mode 100644 index 0000000000..b255e8e07f --- /dev/null +++ b/contrib/libs/protobuf/patches/disable-deprecated-enum-enum-conversion.patch @@ -0,0 +1,17 @@ +commit af38e0d9473a2b9fcf94ea1dfc7b68818a3e657d +author: nechda +date: 2024-08-08T14:03:30+03:00 + + [PROTOBUF] Dont emit erro deprecated-enum-enum-conversion + +--- contrib/libs/protobuf/src/google/protobuf/port_def.inc (7f7b074042eca175373d29cc3fb0f81287851b42) ++++ contrib/libs/protobuf/src/google/protobuf/port_def.inc (af38e0d9473a2b9fcf94ea1dfc7b68818a3e657d) +@@ -975,7 +975,7 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and + #pragma clang diagnostic ignored "-Wshorten-64-to-32" + // Turn on -Wdeprecated-enum-enum-conversion. This deprecation comes in C++20 + // via http://wg21.link/p1120r0. +-#pragma clang diagnostic error "-Wdeprecated-enum-enum-conversion" ++// #pragma clang diagnostic error "-Wdeprecated-enum-enum-conversion" + // This error has been generally flaky, but we need to disable it specifically + // to fix https://github.com/protocolbuffers/protobuf/issues/12313 + #pragma clang diagnostic ignored "-Wunused-parameter" diff --git a/contrib/libs/protobuf/patches/disable-utf8-validation-at-release.patch b/contrib/libs/protobuf/patches/disable-utf8-validation-at-release.patch new file mode 100644 index 0000000000..67b399b669 --- /dev/null +++ b/contrib/libs/protobuf/patches/disable-utf8-validation-at-release.patch @@ -0,0 +1,23 @@ +--- a/src/google/protobuf/wire_format_lite.cc ++++ b/src/google/protobuf/wire_format_lite.cc +@@ -604,6 +604,7 @@ + void PrintUTF8ErrorLog(absl::string_view message_name, + absl::string_view field_name, const char* operation_str, + bool emit_stacktrace) { ++ #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + TProtoStringType stacktrace; + (void)emit_stacktrace; // Parameter is used by Google-internal code. + std::string quoted_field_name = ""; +@@ -624,6 +625,12 @@ + "send raw bytes. ", + stacktrace); + ABSL_LOG(ERROR) << error_message; ++ #else ++ (void)message_name; ++ (void)field_name; ++ (void)emit_stacktrace; ++ (void)operation_str; ++ #endif + } + + bool WireFormatLite::VerifyUtf8String(const char* data, int size, Operation op, diff --git a/contrib/libs/protobuf/patches/disable-utf8-validation.patch b/contrib/libs/protobuf/patches/disable-utf8-validation.patch new file mode 100644 index 0000000000..454b0f2785 --- /dev/null +++ b/contrib/libs/protobuf/patches/disable-utf8-validation.patch @@ -0,0 +1,6 @@ +--- a/src/google/protobuf/wire_format_lite.h (index) ++++ b/src/google/protobuf/wire_format_lite.h (working tree) +@@ -46,3 +46,0 @@ +-#ifndef NDEBUG +-#define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED +-#endif diff --git a/contrib/libs/protobuf/patches/dont-annotate-arena.patch b/contrib/libs/protobuf/patches/dont-annotate-arena.patch new file mode 100644 index 0000000000..d57031d2b8 --- /dev/null +++ b/contrib/libs/protobuf/patches/dont-annotate-arena.patch @@ -0,0 +1,10 @@ +--- a/src/google/protobuf/repeated_field.h ++++ b/src/google/protobuf/repeated_field.h +@@ -389,6 +389,7 @@ + // filled from previous memory), and called with (current_size, total_size) + // right before (previously annotated) memory is released. + void AnnotateSize(int old_size, int new_size) const { ++ return; + if (old_size != new_size) { + ABSL_ANNOTATE_CONTIGUOUS_CONTAINER( + unsafe_elements(), unsafe_elements() + total_size_, diff --git a/contrib/libs/protobuf/patches/dont-use-string-view.patch b/contrib/libs/protobuf/patches/dont-use-string-view.patch new file mode 100644 index 0000000000..084341c464 --- /dev/null +++ b/contrib/libs/protobuf/patches/dont-use-string-view.patch @@ -0,0 +1,56 @@ +commit 4a6dd4d9aeb3e3f9c033d092c86d5be63ca8cba9 +author: nechda +date: 2024-08-08T14:02:13+03:00 + + [PROTOBUF] Dont use string_view + +--- contrib/libs/protobuf/src/google/protobuf/arenastring.cc (e2819444222a1e9154b9c7b701eff6427206db7c) ++++ contrib/libs/protobuf/src/google/protobuf/arenastring.cc (4a6dd4d9aeb3e3f9c033d092c86d5be63ca8cba9) +@@ -115,7 +115,7 @@ TaggedStringPtr CreateArenaString(Arena& arena, absl::string_view s) { + + } // namespace + +-void ArenaStringPtr::Set(absl::string_view value, Arena* arena) { ++void ArenaStringPtr::Set(const TProtoStringType& value, Arena* arena) { + ScopedCheckPtrInvariants check(&tagged_ptr_); + if (IsDefault()) { + // If we're not on an arena, skip straight to a true string to avoid +--- contrib/libs/protobuf/src/google/protobuf/arenastring.h (e2819444222a1e9154b9c7b701eff6427206db7c) ++++ contrib/libs/protobuf/src/google/protobuf/arenastring.h (4a6dd4d9aeb3e3f9c033d092c86d5be63ca8cba9) +@@ -259,7 +259,7 @@ struct PROTOBUF_EXPORT ArenaStringPtr { + // instance known to not carry any heap allocated value. + inline void InitAllocated(TProtoStringType* str, Arena* arena); + +- void Set(absl::string_view value, Arena* arena); ++ void Set(const TProtoStringType& value, Arena* arena); + void Set(TProtoStringType&& value, Arena* arena); + template <typename... OverloadDisambiguator> + void Set(const TProtoStringType& value, Arena* arena); +@@ -410,15 +410,15 @@ inline void ArenaStringPtr::InitAllocated(TProtoStringType* str, Arena* arena) { + } + + inline void ArenaStringPtr::Set(const char* s, Arena* arena) { +- Set(absl::string_view{s}, arena); ++ Set(TProtoStringType{s}, arena); + } + + inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) { +- Set(absl::string_view{s, n}, arena); ++ Set(TProtoStringType(s, s + n), arena); + } + + inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) { +- Set(value, arena); ++ Set(TProtoStringType(value.data(), value.size()), arena); + } + + template <> +@@ -439,7 +439,7 @@ inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) { + } + + inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) { +- Set(absl::string_view{static_cast<const char*>(p), n}, arena); ++ Set(TProtoStringType(static_cast<const char*>(p), static_cast<const char*>(p) + n), arena); + } + + // Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs. diff --git a/contrib/libs/protobuf/patches/dot-generate-string-view-setters.patch b/contrib/libs/protobuf/patches/dot-generate-string-view-setters.patch new file mode 100644 index 0000000000..88ec297018 --- /dev/null +++ b/contrib/libs/protobuf/patches/dot-generate-string-view-setters.patch @@ -0,0 +1,21 @@ +--- contrib/libs/protobuf/src/google/protobuf/arenastring.h (d40b078e35f492f4ad417c8dd4a0103d4e577049) ++++ contrib/libs/protobuf/src/google/protobuf/arenastring.h (2babb01d30e285a96044041b98053d9edbb48b2a) +@@ -266,7 +266,6 @@ struct PROTOBUF_EXPORT ArenaStringPtr { + void Set(const char* s, Arena* arena); + void Set(const char* s, size_t n, Arena* arena); + +- void SetBytes(absl::string_view value, Arena* arena); + void SetBytes(TProtoStringType&& value, Arena* arena); + template <typename... OverloadDisambiguator> + void SetBytes(const TProtoStringType& value, Arena* arena); +@@ -417,10 +416,6 @@ inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) { + Set(TProtoStringType(s, s + n), arena); + } + +-inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) { +- Set(TProtoStringType(value.data(), value.size()), arena); +-} +- + template <> + PROTOBUF_EXPORT void ArenaStringPtr::Set(const TProtoStringType& value, + Arena* arena); diff --git a/contrib/libs/protobuf/patches/fix-layout.patch b/contrib/libs/protobuf/patches/fix-layout.patch new file mode 100644 index 0000000000..3df3926b28 --- /dev/null +++ b/contrib/libs/protobuf/patches/fix-layout.patch @@ -0,0 +1,10 @@ +--- a/src/google/protobuf/arena.cc (index) ++++ b/src/google/protobuf/arena.cc (working tree) +@@ -39,6 +39,7 @@ + #include <typeinfo> + + #include "absl/base/attributes.h" ++#include "absl/container/internal/btree.h" + #include "absl/synchronization/mutex.h" + #include "google/protobuf/arena_allocation_policy.h" + #include "google/protobuf/arenaz_sampler.h" diff --git a/contrib/libs/protobuf/patches/future-piece-c33967fcbc838e1a36e8ad7665d1b73177716e9d.patch b/contrib/libs/protobuf/patches/future-piece-c33967fcbc838e1a36e8ad7665d1b73177716e9d.patch new file mode 100644 index 0000000000..29f4d9e075 --- /dev/null +++ b/contrib/libs/protobuf/patches/future-piece-c33967fcbc838e1a36e8ad7665d1b73177716e9d.patch @@ -0,0 +1,110 @@ +From c33967fcbc838e1a36e8ad7665d1b73177716e9d Mon Sep 17 00:00:00 2001 +From: Protobuf Team Bot <protobuf-github-bot@google.com> +Date: Mon, 20 Nov 2023 04:18:49 -0800 +Subject: [PATCH] Add iterator_concept support. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This allows for better code generation in C++20 for algorithms that take advantage of random access vs contiguous data. + +``` +name old INSTRUCTIONS/op new INSTRUCTIONS/op delta +BM_RepeatedField_Sort 5.74k ± 0% 5.74k ± 0% -0.13% (p=0.000 n=179+183) +BM_RepeatedField_ToVector 693 ± 0% 693 ± 0% ~ (p=0.153 n=93+91) +BM_RepeatedPtrField_SortIndirect 562 ± 0% 559 ± 0% -0.53% (p=0.000 n=92+92) +``` + +PiperOrigin-RevId: 583983215 +--- + src/google/protobuf/BUILD.bazel | 1 + + src/google/protobuf/repeated_field.h | 18 +++-- + .../protobuf/repeated_field_unittest.cc | 69 +++++++++++++++++++ + src/google/protobuf/repeated_ptr_field.h | 26 +++++-- + 4 files changed, 103 insertions(+), 11 deletions(-) + +diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h +index a3f77153289b..5351846558e6 100644 +--- a/src/google/protobuf/repeated_field.h ++++ b/src/google/protobuf/repeated_field.h +@@ -1035,14 +1035,18 @@ namespace internal { + // the compiler isn't allowed to inline them. + template <typename Element> + class RepeatedIterator { ++ private: ++ using traits = ++ std::iterator_traits<typename std::remove_const<Element>::type*>; ++ + public: +- using iterator_category = std::random_access_iterator_tag; +- // Note: remove_const is necessary for std::partial_sum, which uses value_type +- // to determine the summation variable type. +- using value_type = typename std::remove_const<Element>::type; +- using difference_type = std::ptrdiff_t; ++ // Note: value_type is never cv-qualified. ++ using value_type = typename traits::value_type; ++ using difference_type = typename traits::difference_type; + using pointer = Element*; + using reference = Element&; ++ using iterator_category = typename traits::iterator_category; ++ using iterator_concept = typename IteratorConceptSupport<traits>::tag; + + constexpr RepeatedIterator() noexcept : it_(nullptr) {} + +@@ -1142,10 +1146,10 @@ class RepeatedIterator { + + // Allow construction from RepeatedField. + friend class RepeatedField<value_type>; +- explicit RepeatedIterator(Element* it) noexcept : it_(it) {} ++ explicit RepeatedIterator(pointer it) noexcept : it_(it) {} + + // The internal iterator. +- Element* it_; ++ pointer it_; + }; + + // A back inserter for RepeatedField objects. +diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h +index 64cdd1890e3c..7a57dfee134c 100644 +@@ -1852,6 +1853,17 @@ class RepeatedPtrIterator { + void* const* it_; + }; + ++template <typename Traits, typename = void> ++struct IteratorConceptSupport { ++ using tag = typename Traits::iterator_category; ++}; ++ ++template <typename Traits> ++struct IteratorConceptSupport<Traits, ++ std::void_t<typename Traits::iterator_concept>> { ++ using tag = typename Traits::iterator_concept; ++}; ++ + // Provides an iterator that operates on pointers to the underlying objects + // rather than the objects themselves as RepeatedPtrIterator does. + // Consider using this when working with stl algorithms that change +@@ -1861,13 +1873,19 @@ class RepeatedPtrIterator { + // iterator, or "const void* const" for a constant iterator. + template <typename Element, typename VoidPtr> + class RepeatedPtrOverPtrsIterator { ++ private: ++ using traits = ++ std::iterator_traits<typename std::remove_const<Element>::type*>; ++ + public: +- using iterator = RepeatedPtrOverPtrsIterator<Element, VoidPtr>; +- using iterator_category = std::random_access_iterator_tag; +- using value_type = typename std::remove_const<Element>::type; +- using difference_type = std::ptrdiff_t; ++ using value_type = typename traits::value_type; ++ using difference_type = typename traits::difference_type; + using pointer = Element*; + using reference = Element&; ++ using iterator_category = typename traits::iterator_category; ++ using iterator_concept = typename IteratorConceptSupport<traits>::tag; ++ ++ using iterator = RepeatedPtrOverPtrsIterator<Element, VoidPtr>; + + RepeatedPtrOverPtrsIterator() : it_(nullptr) {} + explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
\ No newline at end of file diff --git a/contrib/libs/protobuf/patches/include-util.patch b/contrib/libs/protobuf/patches/include-util.patch new file mode 100644 index 0000000000..e9d179bf44 --- /dev/null +++ b/contrib/libs/protobuf/patches/include-util.patch @@ -0,0 +1,13 @@ +--- a/src/google/protobuf/stubs/port.h (index) ++++ b/src/google/protobuf/stubs/port.h (working tree) +@@ -31,6 +31,10 @@ + #ifndef GOOGLE_PROTOBUF_STUBS_PORT_H_ + #define GOOGLE_PROTOBUF_STUBS_PORT_H_ + ++#include <util/generic/string.h> ++#include <util/stream/input.h> ++#include <util/stream/output.h> ++#include <util/system/types.h> + #include <assert.h> + #include <stdlib.h> + #include <string.h> diff --git a/contrib/libs/protobuf/patches/invalid-iterators.patch b/contrib/libs/protobuf/patches/invalid-iterators.patch new file mode 100644 index 0000000000..8c2898e681 --- /dev/null +++ b/contrib/libs/protobuf/patches/invalid-iterators.patch @@ -0,0 +1,11 @@ +--- contrib/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.cc (index) ++++ contrib/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.cc (working tree) +@@ -431,7 +431,7 @@ std::vector<uint8_t> GenerateFieldNames( + ++count; + } + // The message name is stored at the beginning of the string +- TProtoStringType message_name = descriptor->full_name(); ++ std::string message_name = descriptor->full_name(); + if (message_name.size() > kMaxNameLength) { + static constexpr int kNameHalfLength = (kMaxNameLength - 3) / 2; + message_name = y_absl::StrCat( diff --git a/contrib/libs/protobuf/patches/issue5869-unfinal-fields.patch b/contrib/libs/protobuf/patches/issue5869-unfinal-fields.patch new file mode 100644 index 0000000000..2b6966eb01 --- /dev/null +++ b/contrib/libs/protobuf/patches/issue5869-unfinal-fields.patch @@ -0,0 +1,15 @@ +--- a/src/google/protobuf/arena.h (index) ++++ b/src/google/protobuf/arena.h (working tree) +@@ -242,1 +242,1 @@ struct ArenaOptions { +-class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { ++class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena { +--- a/src/google/protobuf/repeated_field.h (index) ++++ b/src/google/protobuf/repeated_field.h (working tree) +@@ -163,1 +163,1 @@ PROTO_MEMSWAP_DEF_SIZE(uint64, (1u << 31)) +-class RepeatedField final { ++class RepeatedField { +--- a/src/google/protobuf/repeated_ptr_field.h (index) ++++ b/src/google/protobuf/repeated_ptr_field.h (working tree) +@@ -521,1 +521,1 @@ class StringTypeHandler { +-class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { ++class RepeatedPtrField : private internal::RepeatedPtrFieldBase { diff --git a/contrib/libs/protobuf/patches/lower-upper.patch b/contrib/libs/protobuf/patches/lower-upper.patch new file mode 100644 index 0000000000..2f6473bad4 --- /dev/null +++ b/contrib/libs/protobuf/patches/lower-upper.patch @@ -0,0 +1,41 @@ +--- a/src/google/protobuf/compiler/php/php_generator.cc ++++ b/src/google/protobuf/compiler/php/php_generator.cc +@@ -143,7 +143,7 @@ TProtoStringType ConstantNamePrefix(absl::string_view classname) { + bool is_reserved = false; + + TProtoStringType lower(classname); +- std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); ++ lower.to_lower(); + + is_reserved = IsReservedName(lower); + +@@ -1414,7 +1414,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, + + // Write legacy file for backwards compatibility with "readonly" keywword + TProtoStringType lower = en->name(); +- std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); ++ lower.to_lower(); + if (lower == "readonly") { + printer.Print( + "// Adding a class alias for backwards compatibility with the \"readonly\" keyword.\n"); +@@ -1541,7 +1541,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, + + // Write legacy file for backwards compatibility with "readonly" keywword + TProtoStringType lower = message->name(); +- std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); ++ lower.to_lower(); + if (lower == "readonly") { + printer.Print( + "// Adding a class alias for backwards compatibility with the \"readonly\" keyword.\n"); + +--- a/src/google/protobuf/compiler/php/names.cc ++++ b/src/google/protobuf/compiler/php/names.cc +@@ -63,7 +63,7 @@ namespace php { + + bool IsReservedName(absl::string_view name) { + TProtoStringType lower(name); +- std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); ++ lower.to_lower(); + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + return true; diff --git a/contrib/libs/protobuf/patches/must-use-result.patch b/contrib/libs/protobuf/patches/must-use-result.patch new file mode 100644 index 0000000000..5ce471ad10 --- /dev/null +++ b/contrib/libs/protobuf/patches/must-use-result.patch @@ -0,0 +1,11 @@ +--- a/src/google/protobuf/stubs/common.h ++++ b/src/google/protobuf/stubs/common.h +@@ -45,6 +45,8 @@ + #include "google/protobuf/stubs/platform_macros.h" + #include "google/protobuf/stubs/port.h" + ++#define Y_PROTOBUF_SUPPRESS_NODISCARD [[maybe_unused]] bool Y_GENERATE_UNIQUE_ID(pb_checker)= ++ + #if defined(__APPLE__) + #include <TargetConditionals.h> // for TARGET_OS_IPHONE + #endif diff --git a/contrib/libs/protobuf/patches/old-json-alias.patch b/contrib/libs/protobuf/patches/old-json-alias.patch new file mode 100644 index 0000000000..52e0645589 --- /dev/null +++ b/contrib/libs/protobuf/patches/old-json-alias.patch @@ -0,0 +1,15 @@ +--- contrib/libs/protobuf/src/google/protobuf/json/json.h (109a04575819756fff3dc3e089008c9b1e971f85) ++++ contrib/libs/protobuf/src/google/protobuf/json/json.h (9dbbd3dce374a64a46474b4ba78bceb44689f396) +@@ -87,6 +87,12 @@ struct PrintOptions { + preserve_proto_field_names(false) {} + }; + ++#ifdef USE_DEPRECATED_NAMESPACE ++using JsonParseOptions = ParseOptions; ++using JsonPrintOptions = PrintOptions; ++using JsonOptions = PrintOptions; ++#endif ++ + // Converts from protobuf message to JSON and appends it to |output|. This is a + // simple wrapper of BinaryToJsonString(). It will use the DescriptorPool of the + // passed-in message to resolve Any types. diff --git a/contrib/libs/protobuf/patches/or_throw_methods.patch b/contrib/libs/protobuf/patches/or_throw_methods.patch new file mode 100644 index 0000000000..68ba6099b0 --- /dev/null +++ b/contrib/libs/protobuf/patches/or_throw_methods.patch @@ -0,0 +1,117 @@ +--- a/src/google/protobuf/message_lite.cc ++++ b/src/google/protobuf/message_lite.cc +@@ -514,6 +514,33 @@ TProtoStringType MessageLite::SerializePartialAsString() const { + return output; + } + ++#if PROTOBUF_USE_EXCEPTIONS && defined(__cpp_lib_string_view) ++void MessageLite::ParseFromStringOrThrow(std::string_view s) { ++ const bool isOk = ParseFromArray(s.data(), s.size()); ++ if (!isOk) { ++ throw FatalException("message_lite.cc", __LINE__, "Failed to parse protobuf message " + GetTypeName()); ++ } ++} ++#endif ++ ++#if PROTOBUF_USE_EXCEPTIONS ++TProtoStringType NProtoBuf::MessageLite::SerializeAsStringOrThrow() const { ++ TProtoStringType s; ++ if (!IsInitialized()) { ++ //NOTE: SerializeToString (called inside SerializeAsString too) does not perform this check in release build ++ // so SerializeToString in release build return false only if result size is greater than 2gb ++ // but in debug build not properly inited message (without required filds) will lead to an exception ++ // different control flow in debug and build release look like a bug ++ throw FatalException("message_lite.cc", __LINE__, "Some required fileds are not set in message " + GetTypeName()); ++ } ++ const bool isOk = SerializeToString(&s); ++ if (!isOk) { ++ throw FatalException("message_lite.cc", __LINE__, "Failed to serialize protobuf message " + GetTypeName()); ++ } ++ return s; ++} ++#endif ++ + + namespace internal { + +--- a/src/google/protobuf/message_lite.h ++++ b/src/google/protobuf/message_lite.h +@@ -469,6 +469,14 @@ class PROTOBUF_EXPORT MessageLite { + return false; + } + ++ #if PROTOBUF_USE_EXCEPTIONS && defined(__cpp_lib_string_view) ++ PROTOBUF_ATTRIBUTE_REINITIALIZES void ParseFromStringOrThrow(std::string_view s) noexcept(false); ++ #endif ++ ++ #if PROTOBUF_USE_EXCEPTIONS ++ TProtoStringType SerializeAsStringOrThrow() const noexcept(false); ++ #endif ++ + private: + friend class FastReflectionMessageMutator; + friend class FastReflectionStringSetter; + +--- a/src/google/protobuf/stubs/common.cc (a305e8c438c21585e001abb5ada0122f6e1fc694) ++++ a/src/google/protobuf/stubs/common.cc (109a04575819756fff3dc3e089008c9b1e971f85) +@@ -159,6 +159,14 @@ arc_ui32 ghtonl(arc_ui32 x) { + return result; + } + ++#if PROTOBUF_USE_EXCEPTIONS ++FatalException::~FatalException() throw() {} ++ ++const char* FatalException::what() const throw() { ++ return message_.c_str(); ++} ++#endif ++ + } // namespace protobuf + } // namespace google + +--- a/src/google/protobuf/stubs/common.h (a305e8c438c21585e001abb5ada0122f6e1fc694) ++++ a/src/google/protobuf/stubs/common.h (109a04575819756fff3dc3e089008c9b1e971f85) +@@ -45,6 +45,16 @@ + #include "google/protobuf/stubs/platform_macros.h" + #include "google/protobuf/stubs/port.h" + ++#ifndef PROTOBUF_USE_EXCEPTIONS ++#if defined(_MSC_VER) && defined(_CPPUNWIND) ++ #define PROTOBUF_USE_EXCEPTIONS 1 ++#elif defined(__EXCEPTIONS) ++ #define PROTOBUF_USE_EXCEPTIONS 1 ++#else ++ #define PROTOBUF_USE_EXCEPTIONS 0 ++#endif ++#endif ++ + #define Y_PROTOBUF_SUPPRESS_NODISCARD [[maybe_unused]] bool Y_GENERATE_UNIQUE_ID(pb_checker)= + + #if defined(__APPLE__) +@@ -101,6 +111,26 @@ ProtocVersionString(int version); // NOLINT(runtime/string) + + } // namespace internal + ++#if PROTOBUF_USE_EXCEPTIONS ++class FatalException : public std::exception { ++ public: ++ FatalException(const char* filename, int line, const TProtoStringType& message) ++ : filename_(filename), line_(line), message_(message) {} ++ virtual ~FatalException() throw(); ++ ++ const char* what() const throw() override; ++ ++ const char* filename() const { return filename_; } ++ int line() const { return line_; } ++ const TProtoStringType& message() const { return message_; } ++ ++ private: ++ const char* filename_; ++ const int line_; ++ const TProtoStringType message_; ++}; ++#endif ++ + // Place this macro in your main() function (or somewhere before you attempt + // to use the protobuf library) to verify that the version you link against + // matches the headers you compiled against. If a version mismatch is diff --git a/contrib/libs/protobuf/patches/protoc-deprecated-method-becomes-public.patch b/contrib/libs/protobuf/patches/protoc-deprecated-method-becomes-public.patch new file mode 100644 index 0000000000..8cab8c51b6 --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-deprecated-method-becomes-public.patch @@ -0,0 +1,10 @@ +--- a/src/google/protobuf/compiler/importer.h (0dd6d02cb89a06c67e29040284d9239dfe0024b7) ++++ b/src/google/protobuf/compiler/importer.h (192810303a994f7cbd6bf596a3d56393bfefee6c) +@@ -216,7 +216,6 @@ class PROTOBUF_EXPORT MultiFileErrorCollector { + PROTOBUF_IGNORE_DEPRECATION_STOP + } + +- private: + // These should never be called directly, but if a legacy class overrides + // them they'll get routed to by the Record* methods. + Y_ABSL_DEPRECATED("Use RecordError") diff --git a/contrib/libs/protobuf/patches/protoc-disable-syntax-warning.patch b/contrib/libs/protobuf/patches/protoc-disable-syntax-warning.patch new file mode 100644 index 0000000000..ca8ab1df9c --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-disable-syntax-warning.patch @@ -0,0 +1,14 @@ +--- a/src/google/protobuf/compiler/parser.cc (index) ++++ b/src/google/protobuf/compiler/parser.cc (working tree) +@@ -670,11 +670,6 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) { + file->set_syntax(syntax_identifier_); + } + } else if (!stop_after_syntax_identifier_) { +- ABSL_LOG(WARNING) << "No syntax specified for the proto file: " +- << file->name() +- << ". Please use 'syntax = \"proto2\";' " +- << "or 'syntax = \"proto3\";' to specify a syntax " +- << "version. (Defaulted to proto2 syntax.)"; + syntax_identifier_ = "proto2"; + } +
\ No newline at end of file diff --git a/contrib/libs/protobuf/patches/protoc-dont-generate-setters-with-string-view.patch b/contrib/libs/protobuf/patches/protoc-dont-generate-setters-with-string-view.patch new file mode 100644 index 0000000000..f2e020253a --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-dont-generate-setters-with-string-view.patch @@ -0,0 +1,40 @@ +--- a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc (192810303a994f7cbd6bf596a3d56393bfefee6c) ++++ b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc (2b6f1fdeb6f4d5c82840dbe69e4f0d3149c8fe5a) +@@ -781,13 +781,11 @@ void RepeatedString::GenerateAccessorDeclarations(io::Printer* p) const { + $DEPRECATED$ void $set_name$(int index, TProtoStringType&& value); + $DEPRECATED$ void $set_name$(int index, const char* value); + $DEPRECATED$ void $set_name$(int index, const $byte$* value, std::size_t size); +- $DEPRECATED$ void $set_name$(int index, absl::string_view value); + $DEPRECATED$ TProtoStringType* $add_name$(); + $DEPRECATED$ void $add_name$(const TProtoStringType& value); + $DEPRECATED$ void $add_name$(TProtoStringType&& value); + $DEPRECATED$ void $add_name$(const char* value); + $DEPRECATED$ void $add_name$(const $byte$* value, std::size_t size); +- $DEPRECATED$ void $add_name$(absl::string_view value); + $DEPRECATED$ const $pb$::RepeatedPtrField<TProtoStringType>& $name$() const; + $DEPRECATED$ $pb$::RepeatedPtrField<TProtoStringType>* $mutable_name$(); + +@@ -852,11 +850,6 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { + $annotate_set$; + // @@protoc_insertion_point(field_set_pointer:$pkg.Msg.field$) + } +- inline void $Msg$::set_$name$(int index, absl::string_view value) { +- $field_$.Mutable(index)->assign(value.data(), value.size()); +- $annotate_set$; +- // @@protoc_insertion_point(field_set_string_piece:$pkg.Msg.field$) +- } + inline TProtoStringType* $Msg$::_internal_add_$name$() { return $field_$.Add(); } + inline void $Msg$::add_$name$(const TProtoStringType& value) { + $field_$.Add()->assign(value); +@@ -879,11 +872,6 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { + $annotate_add$; + // @@protoc_insertion_point(field_add_pointer:$pkg.Msg.field$) + } +- inline void $Msg$::add_$name$(absl::string_view value) { +- $field_$.Add()->assign(value.data(), value.size()); +- $annotate_add$; +- // @@protoc_insertion_point(field_add_string_piece:$pkg.Msg.field$) +- } + inline const ::$proto_ns$::RepeatedPtrField<TProtoStringType>& + $Msg$::$name$() const { + $annotate_list$; diff --git a/contrib/libs/protobuf/patches/protoc-dont-use-string-view-in-io.patch b/contrib/libs/protobuf/patches/protoc-dont-use-string-view-in-io.patch new file mode 100644 index 0000000000..c25d5dc18a --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-dont-use-string-view-in-io.patch @@ -0,0 +1,31 @@ +--- a/src/google/protobuf/compiler/importer.cc (d9b2a82a272102f9099f5bc0cb767279d3e89e3a) ++++ b/src/google/protobuf/compiler/importer.cc (0dd6d02cb89a06c67e29040284d9239dfe0024b7) +@@ -442,7 +442,7 @@ bool DiskSourceTree::VirtualFileToDiskFile(absl::string_view virtual_file, + return stream != nullptr; + } + +-io::ZeroCopyInputStream* DiskSourceTree::Open(absl::string_view filename) { ++io::ZeroCopyInputStream* DiskSourceTree::Open(const TProtoStringType& filename) { + return OpenVirtualFile(filename, nullptr); + } + +--- a/src/google/protobuf/compiler/importer.h (d9b2a82a272102f9099f5bc0cb767279d3e89e3a) ++++ b/src/google/protobuf/compiler/importer.h (0dd6d02cb89a06c67e29040284d9239dfe0024b7) +@@ -245,7 +245,7 @@ class PROTOBUF_EXPORT SourceTree { + // found. The caller takes ownership of the returned object. The filename + // must be a path relative to the root of the source tree and must not + // contain "." or ".." components. +- virtual io::ZeroCopyInputStream* Open(absl::string_view filename) = 0; ++ virtual io::ZeroCopyInputStream* Open(const TProtoStringType& filename) = 0; + + // If Open() returns NULL, calling this method immediately will return an + // description of the error. +@@ -322,7 +322,7 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { + TProtoStringType* disk_file); + + // implements SourceTree ------------------------------------------- +- io::ZeroCopyInputStream* Open(absl::string_view filename) override; ++ io::ZeroCopyInputStream* Open(const TProtoStringType& filename) override; + + TProtoStringType GetLastErrorMessage() override; + diff --git a/contrib/libs/protobuf/patches/protoc-event-support.patch b/contrib/libs/protobuf/patches/protoc-event-support.patch new file mode 100644 index 0000000000..58bd2b1c6e --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-event-support.patch @@ -0,0 +1,22 @@ +--- a/src/google/protobuf/compiler/python/helpers.cc (62b83ba8ff1149a180456030d46ca0881711b0e5) ++++ b/src/google/protobuf/compiler/python/helpers.cc (94b865765aa38dc5e4ac99e0051d228ebc9d2a80) +@@ -50,9 +50,18 @@ namespace protobuf { + namespace compiler { + namespace python { + ++TProtoStringType FixEv(TProtoStringType filename) { ++ constexpr auto kSuffixLen = 3; ++ if (filename.EndsWith(".ev")) { ++ return filename.substr(0, filename.length() - kSuffixLen) + "_ev.proto"; ++ } ++ return filename; ++} ++ + // Returns the Python module name expected for a given .proto filename. + TProtoStringType ModuleName(absl::string_view filename) { +- TProtoStringType basename = StripProto(filename); ++ TProtoStringType str(std::string{filename}); ++ TProtoStringType basename = StripProto(FixEv(str)); + absl::StrReplaceAll({{"-", "_"}, {"/", "."}}, &basename); + return absl::StrCat(basename, "_pb2"); + } diff --git a/contrib/libs/protobuf/patches/protoc-implicit-insert.patch b/contrib/libs/protobuf/patches/protoc-implicit-insert.patch new file mode 100644 index 0000000000..d9eaed1019 --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-implicit-insert.patch @@ -0,0 +1,11 @@ +--- a/src/google/protobuf/compiler/csharp/names.cc (index) ++++ b/src/google/protobuf/compiler/csharp/names.cc (working tree) +@@ -210,7 +210,7 @@ TProtoStringType UnderscoresToCamelCase(y_absl::string_view input, + if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') + && input.size() > 0 && input[0] == '_') + { +- result.insert(0, 1, '_'); ++ result.insert(static_cast<size_t>(0), 1, '_'); + } + return result; + } diff --git a/contrib/libs/protobuf/patches/protoc-input-output-file.patch b/contrib/libs/protobuf/patches/protoc-input-output-file.patch new file mode 100644 index 0000000000..6bbced6ee5 --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-input-output-file.patch @@ -0,0 +1,124 @@ +--- a/src/google/protobuf/compiler/command_line_interface.cc ++++ b/src/google/protobuf/compiler/command_line_interface.cc +@@ -1579,6 +1579,13 @@ CommandLineInterface::ParseArgumentStatus CommandLineInterface::ParseArguments( + << std::endl; + return PARSE_ARGUMENT_FAIL; + } ++ if (mode_ != MODE_DECODE && mode_ != MODE_ENCODE && ++ (!encode_decode_input_.empty() || !encode_decode_output_.empty())) { ++ std::cerr << "--encode-decode-input and --encode-decode-output are used " ++ << "only together with --encode or --decode modes." ++ << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } + if (!dependency_out_name_.empty() && input_files_.size() > 1) { + std::cerr + << "Can only process one input file when using --dependency_out=FILE." +@@ -1889,6 +1896,35 @@ CommandLineInterface::InterpretArgument(const TProtoStringType& name, + + codec_type_ = value; + ++ } else if (name == "--encode-decode-input") { ++ if (!encode_decode_input_.empty()) { ++ std::cerr << name << " may only be passed once." << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } ++ if (value.empty()) { ++ std::cerr << name << " requires a non-empty value." << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } ++ if (access(value.c_str(), F_OK) < 0) { ++ std::cerr << value << ": encode/decode input file does not exist." ++ << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } ++ ++ encode_decode_input_ = value; ++ ++ } else if (name == "--encode-decode-output") { ++ if (!encode_decode_output_.empty()) { ++ std::cerr << name << " may only be passed once." << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } ++ if (value.empty()) { ++ std::cerr << name << " requires a non-empty value." << std::endl; ++ return PARSE_ARGUMENT_FAIL; ++ } ++ ++ encode_decode_output_ = value; ++ + } else if (name == "--deterministic_output") { + deterministic_output_ = true; + +@@ -2035,6 +2071,10 @@ Parse PROTO_FILES and generate output based on the options given: + pairs in text format to standard output. No + PROTO_FILES should be given when using this + flag. ++ --encode-decode-input=FILE Read text/binary message from FILE instead of ++ reading it from standard input. ++ --encode-decode-output=FILE Write text/binary message to FILE instead of ++ writing it to standard output. + --descriptor_set_in=FILES Specifies a delimited list of FILES + each containing a FileDescriptorSet (a + protocol buffer defined in descriptor.proto). +@@ -2352,16 +2392,40 @@ bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { + DynamicMessageFactory dynamic_factory(pool); + std::unique_ptr<Message> message(dynamic_factory.GetPrototype(type)->New()); + ++ int in_fd = STDIN_FILENO; ++ if (!encode_decode_input_.empty()) { ++ do { ++ in_fd = open(encode_decode_input_.c_str(), O_RDONLY | O_BINARY); ++ } while (in_fd < 0 && errno == EINTR); ++ if (in_fd < 0) { ++ int error = errno; ++ std::cerr << encode_decode_input_ << ": " << strerror(error) << std::endl; ++ return false; ++ } ++ } ++ ++ int out_fd = STDOUT_FILENO; ++ if (!encode_decode_output_.empty()) { ++ do { ++ out_fd = open(encode_decode_output_.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); ++ } while (out_fd < 0 && errno == EINTR); ++ if (out_fd < 0) { ++ int error = errno; ++ std::cerr << encode_decode_output_ << ": " << strerror(error) << std::endl;; ++ return false; ++ } ++ } ++ + if (mode_ == MODE_ENCODE) { +- SetFdToTextMode(STDIN_FILENO); +- SetFdToBinaryMode(STDOUT_FILENO); ++ SetFdToTextMode(in_fd); ++ SetFdToBinaryMode(out_fd); + } else { +- SetFdToBinaryMode(STDIN_FILENO); +- SetFdToTextMode(STDOUT_FILENO); ++ SetFdToBinaryMode(in_fd); ++ SetFdToTextMode(out_fd); + } + +- io::FileInputStream in(STDIN_FILENO); +- io::FileOutputStream out(STDOUT_FILENO); ++ io::FileInputStream in(in_fd); ++ io::FileOutputStream out(out_fd); + + if (mode_ == MODE_ENCODE) { + // Input is text. +--- a/src/google/protobuf/compiler/command_line_interface.h ++++ b/src/google/protobuf/compiler/command_line_interface.h +@@ -383,6 +383,11 @@ class PROTOC_EXPORT CommandLineInterface { + + Mode mode_ = MODE_COMPILE; + ++ // For encode end decode modes only: read from input and write to output ++ // instead of stdin and stdout. ++ TProtoStringType encode_decode_input_; ++ TProtoStringType encode_decode_output_; ++ + enum PrintMode { + PRINT_NONE, // Not in MODE_PRINT + PRINT_FREE_FIELDS, // --print_free_fields diff --git a/contrib/libs/protobuf/patches/protoc-raw-string-literals.patch b/contrib/libs/protobuf/patches/protoc-raw-string-literals.patch new file mode 100644 index 0000000000..7747667825 --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-raw-string-literals.patch @@ -0,0 +1,63 @@ +--- a/src/google/protobuf/compiler/cpp/file.cc (index) ++++ b/src/google/protobuf/compiler/cpp/file.cc (working tree) +@@ -188,9 +188,9 @@ void FileGenerator::GenerateMacroUndefs(io::Printer* p) { + } + + p->Emit({{"name", TProtoStringType(name)}}, R"( +- #ifdef $name$ +- #undef $name$ +- #endif // $name$ ++ #)" "ifdef" R"( $name$ ++ #)" "undef" R"( $name$ ++ #)" "endif" R"( // $name$ + )"); + } + } +@@ -285,7 +285,7 @@ void FileGenerator::GenerateProtoHeader(io::Printer* p, + } + if (IsBootstrapProto(options_, file_)) { + p->Emit({{"name", StripProto(file_->name())}}, R"cc( +- // IWYU pragma: private, include "$name$.proto.h" ++ // IWYU pragma: private, include "$name$.pb.h" + )cc"); + } + +@@ -297,7 +297,7 @@ void FileGenerator::GenerateProtoHeader(io::Printer* p, + for (int i = 0; i < file_->public_dependency_count(); ++i) { + const FileDescriptor* dep = file_->public_dependency(i); + p->Emit({{"name", StripProto(dep->name())}}, R"( +- #include "$name$.proto.h" ++ #)" R"(include "$name$.pb.h" + )"); + } + }}, +@@ -443,7 +443,7 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* p) { + // Generated by the protocol buffer compiler. DO NOT EDIT! + // source: $filename$ + +- #include $h_include$ ++ #)" "include" R"( $h_include$ + + #include <algorithm> + )"); +@@ -485,7 +485,7 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* p) { + GetBootstrapBasename(options_, basename, &basename); + } + p->Emit({{"name", basename}}, R"( +- #include "$name$.proto.h" ++ #)" R"(include "$name$.pb.h" + )"); + } + } +@@ -1390,9 +1390,8 @@ void FileGenerator::GenerateDependencyIncludes(io::Printer* p) { + + p->Emit( + {{"name", CreateHeaderInclude(absl::StrCat(basename, ".pb.h"), dep)}}, +- R"( +- #include $name$ +- )"); ++ "#" "include" "$name$\n" ++ ); + } + } + diff --git a/contrib/libs/protobuf/patches/protoc-use-tsting.patch b/contrib/libs/protobuf/patches/protoc-use-tsting.patch new file mode 100644 index 0000000000..94b1478a96 --- /dev/null +++ b/contrib/libs/protobuf/patches/protoc-use-tsting.patch @@ -0,0 +1,69 @@ +--- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc (index) ++++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc (working tree) +@@ -44,6 +44,10 @@ + #include "google/protobuf/generated_message_tctable_impl.h" + #include "google/protobuf/wire_format.h" + ++#include "util/generic/string.h" ++ ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + namespace compiler { +@@ -894,7 +898,7 @@ void ParseFunctionGenerator::GenerateFieldNames(Formatter& format) { + + // Then print each name in a line of its own + for (; sizes < sizes_end; p += *sizes++) { +- if (*sizes != 0) format("\"$1$\"\n", TProtoStringType(p, p + *sizes)); ++ if (*sizes != 0) format("\"$1$\"\n", TProtoStringType((const char*)p, (const char*)p + *sizes)); + } + } + +--- a/src/google/protobuf/compiler/csharp/names.h (index) ++++ b/src/google/protobuf/compiler/csharp/names.h (working tree) +@@ -39,10 +39,13 @@ + #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ + + #include <string> ++#include "util/generic/string.h" + + #include "absl/strings/string_view.h" + #include "google/protobuf/port_def.inc" + ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + +--- a/src/google/protobuf/compiler/java/options.h (index) ++++ b/src/google/protobuf/compiler/java/options.h (working tree) +@@ -32,9 +32,12 @@ + #define GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ + + #include <string> ++#include "util/generic/string.h" + + #include "google/protobuf/port_def.inc" + ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + namespace compiler { +--- a/src/google/protobuf/compiler/objectivec/text_format_decode_data.h (index) ++++ b/src/google/protobuf/compiler/objectivec/text_format_decode_data.h (working tree) +@@ -35,9 +35,13 @@ + #include <utility> + #include <vector> + ++#include "util/generic/string.h" ++ + // Must be included last + #include "google/protobuf/port_def.inc" + ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + namespace compiler { diff --git a/contrib/libs/protobuf/patches/support-quoted-path-and-required-filds.patch b/contrib/libs/protobuf/patches/support-quoted-path-and-required-filds.patch new file mode 100644 index 0000000000..14ab0f1f17 --- /dev/null +++ b/contrib/libs/protobuf/patches/support-quoted-path-and-required-filds.patch @@ -0,0 +1,42 @@ +--- a/src/google/protobuf/json/internal/parser.cc ++++ b/src/google/protobuf/json/internal/parser.cc +@@ -972,13 +972,29 @@ + // Assume approximately six-letter words, so add one extra space for an + // underscore for every six bytes. + snake_path.reserve(path.size() * 7 / 6); ++ // Port from protobuf 21.x ++ bool is_quoted = false; ++ bool is_escaping = false; + for (char c : path) { ++ // Outputs quoted string as-is. ++ if (is_quoted) { ++ snake_path.push_back(c); ++ if (is_escaping) { ++ is_escaping = false; ++ } else if (c == '\\') { ++ is_escaping = true; ++ } else if (c == '\"') { ++ is_quoted = false; ++ } ++ continue; ++ } + if (absl::ascii_isdigit(c) || absl::ascii_islower(c) || c == '.') { + snake_path.push_back(c); + } else if (absl::ascii_isupper(c)) { + snake_path.push_back('_'); + snake_path.push_back(absl::ascii_tolower(c)); + } else if (lex.options().allow_legacy_syntax) { ++ is_quoted = c == '\"'; + snake_path.push_back(c); + } else { + return str->loc.Invalid("unexpected character in FieldMask"); +@@ -1314,6 +1330,9 @@ + s = absl::InvalidArgumentError( + "extraneous characters after end of JSON object"); + } ++ if (s.ok() && !message->IsInitialized()) { ++ s = absl::InvalidArgumentError("Not all fileds are sets"); ++ } + + PROTOBUF_DLOG(INFO) << "json2/status: " << s; + PROTOBUF_DLOG(INFO) << "json2/output: " << message->DebugString(); diff --git a/contrib/libs/protobuf/patches/switch-enum-warnings-disable.patch b/contrib/libs/protobuf/patches/switch-enum-warnings-disable.patch new file mode 100644 index 0000000000..539ad0546d --- /dev/null +++ b/contrib/libs/protobuf/patches/switch-enum-warnings-disable.patch @@ -0,0 +1,10 @@ +--- contrib/libs/protobuf/src/google/protobuf/port_def.inc (af38e0d9473a2b9fcf94ea1dfc7b68818a3e657d) ++++ contrib/libs/protobuf/src/google/protobuf/port_def.inc (61c97633ad4150fc3855f71a23e0b8d90f4c4f42) +@@ -997,6 +997,7 @@ + // This error has been generally flaky, but we need to disable it specifically + // to fix https://github.com/protocolbuffers/protobuf/issues/12313 + #pragma clang diagnostic ignored "-Wunused-parameter" ++#pragma clang diagnostic ignored "-Wswitch-enum" + #endif + #ifdef __GNUC__ + #pragma GCC diagnostic push diff --git a/contrib/libs/protobuf/patches/unaccepted-pr8881-repeated-truncate.patch b/contrib/libs/protobuf/patches/unaccepted-pr8881-repeated-truncate.patch new file mode 100644 index 0000000000..48c7f4cda6 --- /dev/null +++ b/contrib/libs/protobuf/patches/unaccepted-pr8881-repeated-truncate.patch @@ -0,0 +1,29 @@ +--- a/src/google/protobuf/repeated_ptr_field.h (index) ++++ b/src/google/protobuf/repeated_ptr_field.h (working tree) +@@ -335,6 +335,15 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { + + void Reserve(int new_size); // implemented in the cc file + ++ template<typename TypeHandler> ++ void Truncate(int new_size) { ++ GOOGLE_DCHECK_LE(new_size, current_size_); ++ for (int i = new_size; i < current_size_; i++) { ++ TypeHandler::Clear(cast<TypeHandler>(rep_->elements[i])); ++ } ++ current_size_ = new_size; ++ } ++ + template <typename TypeHandler> + static inline typename TypeHandler::Type* copy( + typename TypeHandler::Type* value) { +@@ -907,6 +916,10 @@ class RepeatedPtrField : private internal::RepeatedPtrFieldBase { + // array is grown, it will always be at least doubled in size. + void Reserve(int new_size); + ++ void Truncate(int new_size) { ++ return RepeatedPtrFieldBase::Truncate<TypeHandler>(new_size); ++ } ++ + int Capacity() const; + + // Gets the underlying array. This pointer is possibly invalidated by diff --git a/contrib/libs/protobuf/patches/unaccepted-pr9977-cxx20-keywords.patch b/contrib/libs/protobuf/patches/unaccepted-pr9977-cxx20-keywords.patch new file mode 100644 index 0000000000..ad049c17c2 --- /dev/null +++ b/contrib/libs/protobuf/patches/unaccepted-pr9977-cxx20-keywords.patch @@ -0,0 +1,36 @@ +From 43f60b1d59c458749fc947b3c5ddbb36b234d5af Mon Sep 17 00:00:00 2001 +From: Keith Smiley <keithbsmiley@gmail.com> +Date: Mon, 16 May 2022 10:25:38 -0700 +Subject: [PATCH] Add new C++ 20 keywords + +Discovered in https://github.com/envoyproxy/envoy/issues/21010 +--- + src/google/protobuf/compiler/cpp/helpers.cc | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc +index 4b7c5c9d91..e17cc9c66c 100644 +--- a/src/google/protobuf/compiler/cpp/helpers.cc ++++ b/src/google/protobuf/compiler/cpp/helpers.cc +@@ -93,9 +93,12 @@ static const char* const kKeywordList[] = { // + "char", + "class", + "compl", ++ "concept", + "const", +- "constexpr", + "const_cast", ++ "consteval", ++ "constexpr", ++ "constinit", + "continue", + "decltype", + "default", +@@ -132,6 +135,7 @@ static const char* const kKeywordList[] = { // + "public", + "register", + "reinterpret_cast", ++ "requires", + "return", + "short", + "signed", diff --git a/contrib/libs/protobuf/patches/unanonymize-error-message.patch b/contrib/libs/protobuf/patches/unanonymize-error-message.patch new file mode 100644 index 0000000000..e7583d3d74 --- /dev/null +++ b/contrib/libs/protobuf/patches/unanonymize-error-message.patch @@ -0,0 +1,20 @@ +--- a/src/google/protobuf/message_lite.cc (index) ++++ b/src/google/protobuf/message_lite.cc (working tree) +@@ -98,6 +98,8 @@ void ByteSizeConsistencyError(size_t byte_size_before_serialization, + ABSL_LOG(FATAL) << "This shouldn't be called if all the sizes are equal."; + } + ++} // anonymous namespace ++ + TProtoStringType InitializationErrorMessage(absl::string_view action, + const MessageLite& message) { + return absl::StrCat("Can't ", action, " message of type \"", +@@ -106,6 +108,8 @@ TProtoStringType InitializationErrorMessage(absl::string_view action, + message.InitializationErrorString()); + } + ++namespace { ++ + inline absl::string_view as_string_view(const void* data, int size) { + return absl::string_view(static_cast<const char*>(data), size); + } diff --git a/contrib/libs/protobuf/patches/undef-external-macro.patch b/contrib/libs/protobuf/patches/undef-external-macro.patch new file mode 100644 index 0000000000..9897150dd9 --- /dev/null +++ b/contrib/libs/protobuf/patches/undef-external-macro.patch @@ -0,0 +1,20 @@ +--- contrib/libs/protobuf/src/google/protobuf/port_def.inc (61c97633ad4150fc3855f71a23e0b8d90f4c4f42) ++++ contrib/libs/protobuf/src/google/protobuf/port_def.inc (305db98d5191470c880de9745e55b395d24b997b) +@@ -383,6 +383,17 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and + #endif + # define PROTOBUF_DEPRECATED_ENUM + ++// External libs can define New macro, but absl will broke... ++#ifdef New ++#undef New ++#endif ++#ifdef Poison ++#undef Poison ++#endif ++#ifdef rename ++#undef rename ++#endif ++ + #if defined(__clang__) + #define PROTOBUF_IGNORE_DEPRECATION_START \ + _Pragma("clang diagnostic push") \ diff --git a/contrib/libs/protobuf/patches/unfinal-messages.patch b/contrib/libs/protobuf/patches/unfinal-messages.patch new file mode 100644 index 0000000000..35d1325ee7 --- /dev/null +++ b/contrib/libs/protobuf/patches/unfinal-messages.patch @@ -0,0 +1,11 @@ +--- a/src/google/protobuf/compiler/cpp/message.cc (index) ++++ b/src/google/protobuf/compiler/cpp/message.cc (working tree) +@@ -1151,7 +1151,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { + HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"; + auto v = p->WithVars(std::move(vars)); + format( +- "class $classname$ final : public " ++ "class $classname$ : public " + "::$proto_ns$::internal::MapEntry$lite$<$classname$, \n" + " $key_cpp$, $val_cpp$,\n" + " ::$proto_ns$::internal::WireFormatLite::$key_wire_type$,\n diff --git a/contrib/libs/protobuf/patches/using-string.patch b/contrib/libs/protobuf/patches/using-string.patch new file mode 100644 index 0000000000..c8af0d0915 --- /dev/null +++ b/contrib/libs/protobuf/patches/using-string.patch @@ -0,0 +1,255 @@ +--- a/src/google/protobuf/stubs/port.h (index) ++++ b/src/google/protobuf/stubs/port.h (working tree) +@@ -119,6 +119,8 @@ + #error "Protobuf requires at least C++11." + #endif + ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + +--- a/src/google/protobuf/map_field.h (index) ++++ b/src/google/protobuf/map_field.h (working tree) +@@ -36,6 +36,7 @@ + #include <type_traits> + + #include "google/protobuf/arena.h" ++#include <google/protobuf/stubs/port.h> + #include "google/protobuf/port.h" + #include "absl/synchronization/mutex.h" + #include "google/protobuf/descriptor.h" +--- a/src/google/protobuf/generated_message_util.cc (index) ++++ b/src/google/protobuf/generated_message_util.cc (working tree) +@@ -62,7 +62,7 @@ void DestroyMessage(const void* message) { + static_cast<const MessageLite*>(message)->~MessageLite(); + } + void DestroyString(const void* s) { +- static_cast<const TProtoStringType*>(s)->~basic_string(); ++ static_cast<const TProtoStringType*>(s)->~TBasicString(); + } + + PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + +--- a/src/google/protobuf/util/type_resolver_util.h (index) ++++ b/src/google/protobuf/util/type_resolver_util.h (working tree) +@@ -35,6 +35,8 @@ + + #include "absl/strings/string_view.h" + ++#include <google/protobuf/stubs/port.h> ++ + // Must be included last. + #include "google/protobuf/port_def.inc" + +--- a/src/google/protobuf/compiler/cpp/options.h (index) ++++ b/src/google/protobuf/compiler/cpp/options.h (working tree) +@@ -37,6 +37,8 @@ + + #include "absl/container/flat_hash_set.h" + ++#include <google/protobuf/stubs/port.h> ++ + namespace google { + namespace protobuf { + namespace compiler { +--- a/src/google/protobuf/compiler/command_line_interface.cc ++++ b/src/google/protobuf/compiler/command_line_interface.cc +@@ -1174,10 +1174,10 @@ bool CommandLineInterface::ExpandArgumentFile(const string& file, + if (!file_stream.is_open()) { + return false; + } +- TProtoStringType argument; ++ std::string argument; + // We don't support any kind of shell expansion right now. + while (std::getline(file_stream, argument)) { +- arguments->push_back(argument); ++ arguments->emplace_back(argument); + } + return true; + } +--- a/src/google/protobuf/compiler/plugin.h (index) ++++ b/src/google/protobuf/compiler/plugin.h (working tree) +@@ -63,6 +63,7 @@ + #define GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ + + #include <string> ++#include <google/protobuf/stubs/port.h> + + // Must be included last. + #include <google/protobuf/port_def.inc> +--- a/src/google/protobuf/compiler/objectivec/helpers.cc ++++ b/src/google/protobuf/compiler/objectivec/helpers.cc +@@ -43,6 +43,7 @@ + #include "google/protobuf/compiler/objectivec/names.h" + #include "google/protobuf/io/strtod.h" + #include "google/protobuf/stubs/common.h" ++#include <google/protobuf/stubs/port.h> + + // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some + // error cases, so it seems to be ok to use as a back door for errors. +--- a/src/google/protobuf/compiler/php/php_generator.cc ++++ b/src/google/protobuf/compiler/php/php_generator.cc +@@ -49,6 +49,9 @@ + #include "google/protobuf/descriptor.pb.h" + #include "google/protobuf/io/printer.h" + #include "google/protobuf/io/zero_copy_stream.h" ++#include <google/protobuf/stubs/port.h> ++ ++#include <util/string/cast.h> + + constexpr absl::string_view kDescriptorFile = + "google/protobuf/descriptor.proto"; +@@ -289,7 +292,7 @@ TProtoStringType GeneratedMetadataFileName(const FileDescriptor* file, + file->options().php_metadata_namespace(); + if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") { + absl::StrAppend(&result, php_metadata_namespace); +- std::replace(result.begin(), result.end(), '\\', '/'); ++ std::replace(result.begin(), result.vend(), '\\', '/'); + if (result.at(result.size() - 1) != '/') { + absl::StrAppend(&result, "/"); + } +--- a/src/google/protobuf/compiler/ruby/ruby_generator.cc ++++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc +@@ -64,7 +64,7 @@ template<class numeric_type> + TProtoStringType NumberToString(numeric_type value) { + std::ostringstream os; + os << value; +- return os.str(); ++ return TProtoStringType{os.str()}; + } + + TProtoStringType GetRequireName(const TProtoStringType& proto_file) { +@@ -163,7 +163,7 @@ TProtoStringType DefaultValueForField(const FieldDescriptor* field) { + os << "\".force_encoding(\"ASCII-8BIT\")"; + } + +- return os.str(); ++ return TProtoStringType{os.str()}; + } + default: assert(false); return ""; + } +--- a/src/google/protobuf/compiler/php/php_generator.cc ++++ b/src/google/protobuf/compiler/php/php_generator.cc +@@ -433,7 +434,7 @@ TProtoStringType GeneratedServiceFileName(const ServiceDescriptor* service, + TProtoStringType IntToString(int32 value) { + std::ostringstream os; + os << value; +- return os.str(); ++ return TProtoStringType{os.str()}; + } + + TProtoStringType LabelForField(const FieldDescriptor* field) { +@@ -1919,7 +1920,7 @@ void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) { + " strlen(\"$name$\"), $num$);\n", + "c_name", c_name, + "name", value->name(), +- "num", std::to_string(value->number())); ++ "num", ToString(value->number())); + } + + printer->Print( +@@ -2140,7 +2141,7 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& files, + "filename", file->name(), + "c_name", c_name, + "metadata_c_name", metadata_c_name, +- "size", std::to_string(serialized.size())); ++ "size", ToString(serialized.size())); + + for (size_t i = 0; i < serialized.size();) { + for (size_t j = 0; j < 25 && i < serialized.size(); ++i, ++j) { +--- a/src/google/protobuf/io/io_win32.cc (index) ++++ b/src/google/protobuf/io/io_win32.cc (working tree) +@@ -77,7 +77,7 @@ namespace io { + namespace win32 { + namespace { + +-using TProtoStringType; ++using string = TProtoStringType; + using std::wstring; + + template <typename char_type> +--- a/src/google/protobuf/io/io_win32.h ++++ b/src/google/protobuf/io/io_win32.h +@@ -52,6 +52,7 @@ + #include <functional> + #include <string> + ++#include <google/protobuf/stubs/port.h> + #include "google/protobuf/port.h" + + // Must be included last. + +diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +index 16dd7b9..371234a 100644 +--- a/src/google/protobuf/compiler/objectivec/generator.cc ++++ b/src/google/protobuf/compiler/objectivec/generator.cc +@@ -183,9 +183,9 @@ bool ObjectiveCGenerator::GenerateAll( + if (getenv("GPB_OBJC_SKIP_IMPLS_FILE") != NULL) { + std::ifstream skip_file(getenv("GPB_OBJC_SKIP_IMPLS_FILE")); + if (skip_file.is_open()) { +- TProtoStringType line; ++ std::string line; + while (std::getline(skip_file, line)) { +- skip_impls.insert(line); ++ skip_impls.insert(line.c_str()); + } + } else { + *error = "error: Failed to open GPB_OBJC_SKIP_IMPLS_FILE file"; + +--- a/src/google/protobuf/arenaz_sampler.h ++++ b/src/google/protobuf/arenaz_sampler.h +@@ -37,6 +37,7 @@ + #include <cstdint> + #include <utility> + ++#include <google/protobuf/stubs/port.h> + + // Must be included last. + #include "google/protobuf/port_def.inc" +--- a/src/google/protobuf/io/printer.h (index) ++++ b/src/google/protobuf/io/printer.h (working tree) +@@ -50,6 +50,7 @@ + #include "absl/functional/function_ref.h" + #include "absl/log/absl_check.h" + #include "absl/meta/type_traits.h" ++#include "absl/strings/str_cat.h" + #include "absl/strings/str_format.h" + #include "absl/strings/string_view.h" + #include "absl/types/optional.h" +--- a/src/google/protobuf/io/strtod.h (index) ++++ b/src/google/protobuf/io/strtod.h (working tree) +@@ -35,11 +35,13 @@ + #ifndef GOOGLE_PROTOBUF_IO_STRTOD_H__ + #define GOOGLE_PROTOBUF_IO_STRTOD_H__ + +-#include <string> ++#include <util/generic/string.h> + + // Must be included last. + #include "google/protobuf/port_def.inc" + ++using TProtoStringType = TString; ++ + namespace google { + namespace protobuf { + namespace io { +--- a/src/google/protobuf/port.h (index) ++++ b/src/google/protobuf/port.h (working tree) +@@ -40,7 +40,7 @@ + #include <cstddef> + #include <cstdint> + #include <new> +-#include <string> ++#include <util/generic/string.h> + #include <type_traits> + + #if PROTOBUF_RTTI +@@ -55,6 +55,7 @@ + // must be last + #include "google/protobuf/port_def.inc" + ++using TProtoStringType = TString; + + namespace google { + namespace protobuf { diff --git a/contrib/libs/protobuf/patches/wrapper-for-old-json-lib.patch b/contrib/libs/protobuf/patches/wrapper-for-old-json-lib.patch new file mode 100644 index 0000000000..ccd78056da --- /dev/null +++ b/contrib/libs/protobuf/patches/wrapper-for-old-json-lib.patch @@ -0,0 +1,14 @@ +--- contrib/libs/protobuf/src/google/protobuf/json/json.h (94b865765aa38dc5e4ac99e0051d228ebc9d2a80) ++++ contrib/libs/protobuf/src/google/protobuf/json/json.h (a305e8c438c21585e001abb5ada0122f6e1fc694) +@@ -45,7 +45,11 @@ + + namespace google { + namespace protobuf { ++#ifdef USE_DEPRECATED_NAMESPACE ++namespace util { ++#else + namespace json { ++#endif + struct ParseOptions { + // Whether to ignore unknown JSON fields during parsing + bool ignore_unknown_fields = false; diff --git a/contrib/libs/protobuf/patches/ydb-plugin-on-one-line-attrs.patch b/contrib/libs/protobuf/patches/ydb-plugin-on-one-line-attrs.patch new file mode 100644 index 0000000000..d93ca54200 --- /dev/null +++ b/contrib/libs/protobuf/patches/ydb-plugin-on-one-line-attrs.patch @@ -0,0 +1,22 @@ +--- a/src/google/protobuf/compiler/cpp/file.cc (0493be282efcece0bb95a5f970ede895072fe7f8) ++++ b/src/google/protobuf/compiler/cpp/file.cc (0ee9b261e62e35e2fa69209db9c8787ac99ad867) +@@ -556,8 +556,7 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx, io::Printer* p) { + }; + }; + +- PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT +- PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const $type$ $name$; ++ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const $type$ $name$; + )cc"); + } + +@@ -579,8 +578,7 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx, io::Printer* p) { + }; + }; + +- PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT +- PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $type$ $name$; ++ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $type$ $name$; + )cc"); + + for (int i = 0; i < generator->descriptor()->field_count(); ++i) { diff --git a/contrib/libs/protobuf/patches/z_01_relax_text_format.patch b/contrib/libs/protobuf/patches/z_01_relax_text_format.patch new file mode 100644 index 0000000000..5bc23f9ff4 --- /dev/null +++ b/contrib/libs/protobuf/patches/z_01_relax_text_format.patch @@ -0,0 +1,70 @@ +--- a/src/google/protobuf/map.h (index) ++++ b/src/google/protobuf/map.h (working tree) +@@ -51,7 +51,8 @@ + #endif // defined(__cpp_lib_string_view) + + #if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__) +-#include <mach/mach_time.h> ++#define GOOGLE_PROTOBUF_NO_RDTSC 1 ++//#include <mach/mach_time.h> + #endif + + #include <google/protobuf/stubs/common.h> +--- a/src/google/protobuf/text_format.cc (index) ++++ b/src/google/protobuf/text_format.cc (working tree) +@@ -550,13 +550,19 @@ + // start with "{" or "<" which indicates the beginning of a message body. + // If there is no ":" or there is a "{" or "<" after ":", this field has + // to be a message or the input is ill-formed. ++ bool skip; + if (TryConsumeBeforeWhitespace(":")) { + TryConsumeWhitespace(); + if (!LookingAt("{") && !LookingAt("<")) { +- return SkipFieldValue(); ++ skip = SkipFieldValue(); ++ } else { ++ skip = SkipFieldMessage(); + } ++ } else { ++ skip = SkipFieldMessage(); + } +- return SkipFieldMessage(); ++ TryConsume(";") || TryConsume(","); ++ return skip; + } + + if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) { +--- a/src/google/protobuf/compiler/cpp/helpers.cc ++++ b/src/google/protobuf/compiler/cpp/helpers.cc +@@ -200,7 +200,7 @@ const absl::flat_hash_set<absl::string_view>& Keywords() { + } + + TProtoStringType IntTypeName(const Options& options, absl::string_view type) { +- return absl::StrCat("::", type, "_t"); ++ return absl::StrCat("::NProtoBuf::", type); + } + + +--- a/src/google/protobuf/io/tokenizer.cc (index) ++++ b/src/google/protobuf/io/tokenizer.cc (working tree) +@@ -704,13 +704,13 @@ bool Tokenizer::Next() { + ConsumeString('\''); + current_.type = TYPE_STRING; + } else { +- // Check if the high order bit is set. +- if (current_char_ & 0x80) { +- error_collector_->RecordError( +- line_, column_, +- absl::StrFormat("Interpreting non ascii codepoint %d.", +- static_cast<unsigned char>(current_char_))); +- } ++ // The tokenizer is used to parse tomita grammars with non-ascii utf8 chars ++ // if (current_char_ & 0x80) { ++ // error_collector_->AddError( ++ // line_, column_, ++ // StringPrintf("Interpreting non ascii codepoint %d.", ++ // static_cast<unsigned char>(current_char_))); ++ // } + NextChar(); + current_.type = TYPE_SYMBOL; + } diff --git a/contrib/libs/protobuf/patches/z_02_must_use_result.sh b/contrib/libs/protobuf/patches/z_02_must_use_result.sh new file mode 100644 index 0000000000..1dfb5f9fae --- /dev/null +++ b/contrib/libs/protobuf/patches/z_02_must_use_result.sh @@ -0,0 +1,5 @@ +sed -e 's|bool Parse|PROTOBUF_MUST_USE_RESULT bool Parse|' \ + -e 's|bool Merge|PROTOBUF_MUST_USE_RESULT bool Merge|' \ + -e 's|bool Serialize|PROTOBUF_MUST_USE_RESULT bool Serialize|' \ + -e 's|bool Append|PROTOBUF_MUST_USE_RESULT bool Append|' \ + -i src/google/protobuf/message_lite.h diff --git a/contrib/libs/protobuf/patches/z_03_must_use_result.patch b/contrib/libs/protobuf/patches/z_03_must_use_result.patch new file mode 100644 index 0000000000..96690d9a92 --- /dev/null +++ b/contrib/libs/protobuf/patches/z_03_must_use_result.patch @@ -0,0 +1,15 @@ +--- contrib/libs/protobuf/src/google/protobuf/message_lite.h (index) ++++ contrib/libs/protobuf/src/google/protobuf/message_lite.h (working tree) +@@ -39,6 +39,12 @@ + #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ + #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ + ++#if defined(_MSC_VER) ++#define PROTOBUF_MUST_USE_RESULT ++#else ++#define PROTOBUF_MUST_USE_RESULT __attribute__((warn_unused_result)) ++#endif ++ + #include <climits> + #include <iosfwd> + #include <string> diff --git a/contrib/libs/protobuf/patches/z_04_tailcall.sh b/contrib/libs/protobuf/patches/z_04_tailcall.sh new file mode 100644 index 0000000000..d855237160 --- /dev/null +++ b/contrib/libs/protobuf/patches/z_04_tailcall.sh @@ -0,0 +1,11 @@ +set -xue + +cat << EOF >> src/google/protobuf/port_def.inc + +#if defined(__clang__) && defined(_WIN32) +#undef PROTOBUF_MUSTTAIL +#undef PROTOBUF_TAILCALL +#define PROTOBUF_MUSTTAIL +#define PROTOBUF_TAILCALL false +#endif +EOF diff --git a/contrib/libs/protobuf/patches/z_05_use_ref_count.patch b/contrib/libs/protobuf/patches/z_05_use_ref_count.patch new file mode 100644 index 0000000000..391af0669c --- /dev/null +++ b/contrib/libs/protobuf/patches/z_05_use_ref_count.patch @@ -0,0 +1,14 @@ +--- contrib/libs/protobuf/src/google/protobuf/arenastring.cc (5de6c47c971aa5c751f17043b8ddf45bcc6daee0) ++++ contrib/libs/protobuf/src/google/protobuf/arenastring.cc (c7e1b2fc457f6c68ed50780be734651758d4f548) +@@ -96,9 +96,9 @@ class ScopedCheckPtrInvariants { + #endif // NDEBUG || !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL + + // Creates a heap allocated TProtoStringType value. +-inline TaggedStringPtr CreateString(absl::string_view value) { ++inline TaggedStringPtr CreateString(const TProtoStringType& value) { + TaggedStringPtr res; +- res.SetAllocated(new TProtoStringType(value.data(), value.length())); ++ res.SetAllocated(new TProtoStringType(value)); + return res; + } + diff --git a/contrib/libs/protobuf/patches/z_99_use-arcadia-int-types.sh b/contrib/libs/protobuf/patches/z_99_use-arcadia-int-types.sh new file mode 100644 index 0000000000..66f7ddf515 --- /dev/null +++ b/contrib/libs/protobuf/patches/z_99_use-arcadia-int-types.sh @@ -0,0 +1,43 @@ +cat << EOF > fix.py +import sys + +def fix_line(l): + l = l.replace('~basic_string()', '~TBasicString()') + + if 'ByteCount' in l and 'int64_t' in l and 'const' in l: + return l + + if 'GetSupportedFeatures' in l and 'const' in l and 'uint64_t' in l: + return l + + l = l.replace('std::uint64_t', 'arc_ui64').replace('std::int64_t', 'arc_i64') + l = l.replace('std::uint32_t', 'arc_ui32').replace('std::int32_t', 'arc_i32') + l = l.replace('uint64_t', 'arc_ui64').replace('int64_t', 'arc_i64') + l = l.replace('uint32_t', 'arc_ui32').replace('int32_t', 'arc_i32') + + l = l.replace('"third_party/absl/', '"y_absl/') + l = l.replace('"absl/', '"y_absl/') + l = l.replace('absl::', 'y_absl::') + l = l.replace('ABSL_', 'Y_ABSL_') + l = l.replace('ts_unchecked_read', 'y_ts_unchecked_read') + l = l.replace('TS_UNCHECKED_READ', 'Y_TS_UNCHECKED_READ') + l = l.replace('GOOGLE_DCHECK(', 'Y_ABSL_DCHECK(') + l = l.replace('GOOGLE_DCHECK_LE(', 'Y_ABSL_DCHECK_LE(') + + if 'Y_ABSL_DEPRECATED' in l: l = '' + + return l + +print('\n'.join(fix_line(x) for x in sys.stdin.read().split('\n')).strip()) +EOF + +( + find . -type f -name '*.cc' + find . -type f -name '*.h' + find . -type f -name '*.inc' +) | while read l; do + cat ${l} | python3 ./fix.py > _ + mv _ ${l} +done + +rm fix.py diff --git a/contrib/libs/protobuf/src/google/protobuf/stubs/map_util.h b/contrib/libs/protobuf/src/google/protobuf/stubs/map_util.h new file mode 100644 index 0000000000..24e098ad1b --- /dev/null +++ b/contrib/libs/protobuf/src/google/protobuf/stubs/map_util.h @@ -0,0 +1,769 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2014 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT +// OWNER 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. + +// from google3/util/gtl/map_util.h +// Author: Anton Carver + +#ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ +#define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ + +#include <stddef.h> +#include <iterator> +#include <string> +#include <utility> +#include <vector> + +#include <google/protobuf/stubs/common.h> + +namespace google { +namespace protobuf { +namespace internal { +// Local implementation of RemoveConst to avoid including base/type_traits.h. +template <class T> struct RemoveConst { typedef T type; }; +template <class T> struct RemoveConst<const T> : RemoveConst<T> {}; +} // namespace internal + +// +// Find*() +// + +// Returns a const reference to the value associated with the given key if it +// exists. Crashes otherwise. +// +// This is intended as a replacement for operator[] as an rvalue (for reading) +// when the key is guaranteed to exist. +// +// operator[] for lookup is discouraged for several reasons: +// * It has a side-effect of inserting missing keys +// * It is not thread-safe (even when it is not inserting, it can still +// choose to resize the underlying storage) +// * It invalidates iterators (when it chooses to resize) +// * It default constructs a value object even if it doesn't need to +// +// This version assumes the key is printable, and includes it in the fatal log +// message. +template <class Collection> +const typename Collection::value_type::second_type& +FindOrDie(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; + return it->second; +} + +// Same as above, but returns a non-const reference. +template <class Collection> +typename Collection::value_type::second_type& +FindOrDie(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; + return it->second; +} + +// Same as FindOrDie above, but doesn't log the key on failure. +template <class Collection> +const typename Collection::value_type::second_type& +FindOrDieNoPrint(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found"; + return it->second; +} + +// Same as above, but returns a non-const reference. +template <class Collection> +typename Collection::value_type::second_type& +FindOrDieNoPrint(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found"; + return it->second; +} + +// Returns a const reference to the value associated with the given key if it +// exists, otherwise returns a const reference to the provided default value. +// +// WARNING: If a temporary object is passed as the default "value," +// this function will return a reference to that temporary object, +// which will be destroyed at the end of the statement. A common +// example: if you have a map with string values, and you pass a char* +// as the default "value," either use the returned value immediately +// or store it in a string (not string&). +// Details: http://go/findwithdefault +template <class Collection> +const typename Collection::value_type::second_type& +FindWithDefault(const Collection& collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return value; + } + return it->second; +} + +// Returns a pointer to the const value associated with the given key if it +// exists, or nullptr otherwise. +template <class Collection> +const typename Collection::value_type::second_type* +FindOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return &it->second; +} + +// Same as above but returns a pointer to the non-const value. +template <class Collection> +typename Collection::value_type::second_type* +FindOrNull(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return &it->second; +} + +// Returns the pointer value associated with the given key. If none is found, +// nullptr is returned. The function is designed to be used with a map of keys to +// pointers. +// +// This function does not distinguish between a missing key and a key mapped +// to nullptr. +template <class Collection> +typename Collection::value_type::second_type +FindPtrOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return typename Collection::value_type::second_type(); + } + return it->second; +} + +// Same as above, except takes non-const reference to collection. +// +// This function is needed for containers that propagate constness to the +// pointee, such as boost::ptr_map. +template <class Collection> +typename Collection::value_type::second_type +FindPtrOrNull(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + if (it == collection.end()) { + return typename Collection::value_type::second_type(); + } + return it->second; +} + +// Finds the pointer value associated with the given key in a map whose values +// are linked_ptrs. Returns nullptr if key is not found. +template <class Collection> +typename Collection::value_type::second_type::element_type* +FindLinkedPtrOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + // Since linked_ptr::get() is a const member returning a non const, + // we do not need a version of this function taking a non const collection. + return it->second.get(); +} + +// Same as above, but dies if the key is not found. +template <class Collection> +typename Collection::value_type::second_type::element_type& +FindLinkedPtrOrDie(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "key not found: " << key; + // Since linked_ptr::operator*() is a const member returning a non const, + // we do not need a version of this function taking a non const collection. + return *it->second; +} + +// Finds the value associated with the given key and copies it to *value (if not +// nullptr). Returns false if the key was not found, true otherwise. +template <class Collection, class Key, class Value> +bool FindCopy(const Collection& collection, + const Key& key, + Value* const value) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return false; + } + if (value) { + *value = it->second; + } + return true; +} + +// +// Contains*() +// + +// Returns true if and only if the given collection contains the given key. +template <class Collection, class Key> +bool ContainsKey(const Collection& collection, const Key& key) { + return collection.find(key) != collection.end(); +} + +// Returns true if and only if the given collection contains the given key-value +// pair. +template <class Collection, class Key, class Value> +bool ContainsKeyValuePair(const Collection& collection, + const Key& key, + const Value& value) { + typedef typename Collection::const_iterator const_iterator; + std::pair<const_iterator, const_iterator> range = collection.equal_range(key); + for (const_iterator it = range.first; it != range.second; ++it) { + if (it->second == value) { + return true; + } + } + return false; +} + +// +// Insert*() +// + +// Inserts the given key-value pair into the collection. Returns true if and +// only if the key from the given pair didn't previously exist. Otherwise, the +// value in the map is replaced with the value from the given pair. +template <class Collection> +bool InsertOrUpdate(Collection* const collection, + const typename Collection::value_type& vt) { + std::pair<typename Collection::iterator, bool> ret = collection->insert(vt); + if (!ret.second) { + // update + ret.first->second = vt.second; + return false; + } + return true; +} + +// Same as above, except that the key and value are passed separately. +template <class Collection> +bool InsertOrUpdate(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return InsertOrUpdate( + collection, typename Collection::value_type(key, value)); +} + +// Inserts/updates all the key-value pairs from the range defined by the +// iterators "first" and "last" into the given collection. +template <class Collection, class InputIterator> +void InsertOrUpdateMany(Collection* const collection, + InputIterator first, InputIterator last) { + for (; first != last; ++first) { + InsertOrUpdate(collection, *first); + } +} + +// Change the value associated with a particular key in a map or hash_map +// of the form map<Key, Value*> which owns the objects pointed to by the +// value pointers. If there was an existing value for the key, it is deleted. +// True indicates an insert took place, false indicates an update + delete. +template <class Collection> +bool InsertAndDeleteExisting( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, value)); + if (!ret.second) { + delete ret.first->second; + ret.first->second = value; + return false; + } + return true; +} + +// Inserts the given key and value into the given collection if and only if the +// given key did NOT already exist in the collection. If the key previously +// existed in the collection, the value is not changed. Returns true if the +// key-value pair was inserted; returns false if the key was already present. +template <class Collection> +bool InsertIfNotPresent(Collection* const collection, + const typename Collection::value_type& vt) { + return collection->insert(vt).second; +} + +// Same as above except the key and value are passed separately. +template <class Collection> +bool InsertIfNotPresent( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return InsertIfNotPresent( + collection, typename Collection::value_type(key, value)); +} + +// Same as above except dies if the key already exists in the collection. +template <class Collection> +void InsertOrDie(Collection* const collection, + const typename Collection::value_type& value) { + GOOGLE_CHECK(InsertIfNotPresent(collection, value)) + << "duplicate value: " << value; +} + +// Same as above except doesn't log the value on error. +template <class Collection> +void InsertOrDieNoPrint(Collection* const collection, + const typename Collection::value_type& value) { + GOOGLE_CHECK(InsertIfNotPresent(collection, value)) << "duplicate value."; +} + +// Inserts the key-value pair into the collection. Dies if key was already +// present. +template <class Collection> +void InsertOrDie(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) + << "duplicate key: " << key; +} + +// Same as above except doesn't log the key on error. +template <class Collection> +void InsertOrDieNoPrint( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) << "duplicate key."; +} + +// Inserts a new key and default-initialized value. Dies if the key was already +// present. Returns a reference to the value. Example usage: +// +// map<int, SomeProto> m; +// SomeProto& proto = InsertKeyOrDie(&m, 3); +// proto.set_field("foo"); +template <class Collection> +typename Collection::value_type::second_type& InsertKeyOrDie( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type value_type; + std::pair<typename Collection::iterator, bool> res = + collection->insert(value_type(key, typename value_type::second_type())); + GOOGLE_CHECK(res.second) << "duplicate key: " << key; + return res.first->second; +} + +// +// Lookup*() +// + +// Looks up a given key and value pair in a collection and inserts the key-value +// pair if it's not already present. Returns a reference to the value associated +// with the key. +template <class Collection> +typename Collection::value_type::second_type& +LookupOrInsert(Collection* const collection, + const typename Collection::value_type& vt) { + return collection->insert(vt).first->second; +} + +// Same as above except the key-value are passed separately. +template <class Collection> +typename Collection::value_type::second_type& +LookupOrInsert(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return LookupOrInsert( + collection, typename Collection::value_type(key, value)); +} + +// Counts the number of equivalent elements in the given "sequence", and stores +// the results in "count_map" with element as the key and count as the value. +// +// Example: +// vector<string> v = {"a", "b", "c", "a", "b"}; +// map<string, int> m; +// AddTokenCounts(v, 1, &m); +// assert(m["a"] == 2); +// assert(m["b"] == 2); +// assert(m["c"] == 1); +template <typename Sequence, typename Collection> +void AddTokenCounts( + const Sequence& sequence, + const typename Collection::value_type::second_type& increment, + Collection* const count_map) { + for (typename Sequence::const_iterator it = sequence.begin(); + it != sequence.end(); ++it) { + typename Collection::value_type::second_type& value = + LookupOrInsert(count_map, *it, + typename Collection::value_type::second_type()); + value += increment; + } +} + +// Returns a reference to the value associated with key. If not found, a value +// is default constructed on the heap and added to the map. +// +// This function is useful for containers of the form map<Key, Value*>, where +// inserting a new key, value pair involves constructing a new heap-allocated +// Value, and storing a pointer to that in the collection. +template <class Collection> +typename Collection::value_type::second_type& +LookupOrInsertNew(Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename std::iterator_traits< + typename Collection::value_type::second_type>::value_type Element; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type( + key, + static_cast<typename Collection::value_type::second_type>(nullptr))); + if (ret.second) { + ret.first->second = new Element(); + } + return ret.first->second; +} + +// Same as above but constructs the value using the single-argument constructor +// and the given "arg". +template <class Collection, class Arg> +typename Collection::value_type::second_type& +LookupOrInsertNew(Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename std::iterator_traits< + typename Collection::value_type::second_type>::value_type Element; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type( + key, + static_cast<typename Collection::value_type::second_type>(nullptr))); + if (ret.second) { + ret.first->second = new Element(arg); + } + return ret.first->second; +} + +// Lookup of linked/shared pointers is used in two scenarios: +// +// Use LookupOrInsertNewLinkedPtr if the container owns the elements. +// In this case it is fine working with the raw pointer as long as it is +// guaranteed that no other thread can delete/update an accessed element. +// A mutex will need to lock the container operation as well as the use +// of the returned elements. Finding an element may be performed using +// FindLinkedPtr*(). +// +// Use LookupOrInsertNewSharedPtr if the container does not own the elements +// for their whole lifetime. This is typically the case when a reader allows +// parallel updates to the container. In this case a Mutex only needs to lock +// container operations, but all element operations must be performed on the +// shared pointer. Finding an element must be performed using FindPtr*() and +// cannot be done with FindLinkedPtr*() even though it compiles. + +// Lookup a key in a map or hash_map whose values are linked_ptrs. If it is +// missing, set collection[key].reset(new Value::element_type) and return that. +// Value::element_type must be default constructable. +template <class Collection> +typename Collection::value_type::second_type::element_type* +LookupOrInsertNewLinkedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type::second_type Value; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, Value())); + if (ret.second) { + ret.first->second.reset(new typename Value::element_type); + } + return ret.first->second.get(); +} + +// A variant of LookupOrInsertNewLinkedPtr where the value is constructed using +// a single-parameter constructor. Note: the constructor argument is computed +// even if it will not be used, so only values cheap to compute should be passed +// here. On the other hand it does not matter how expensive the construction of +// the actual stored value is, as that only occurs if necessary. +template <class Collection, class Arg> +typename Collection::value_type::second_type::element_type* +LookupOrInsertNewLinkedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename Collection::value_type::second_type Value; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, Value())); + if (ret.second) { + ret.first->second.reset(new typename Value::element_type(arg)); + } + return ret.first->second.get(); +} + +// Lookup a key in a map or hash_map whose values are shared_ptrs. If it is +// missing, set collection[key].reset(new Value::element_type). Unlike +// LookupOrInsertNewLinkedPtr, this function returns the shared_ptr instead of +// the raw pointer. Value::element_type must be default constructable. +template <class Collection> +typename Collection::value_type::second_type& +LookupOrInsertNewSharedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type::second_type SharedPtr; + typedef typename Collection::value_type::second_type::element_type Element; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, SharedPtr())); + if (ret.second) { + ret.first->second.reset(new Element()); + } + return ret.first->second; +} + +// A variant of LookupOrInsertNewSharedPtr where the value is constructed using +// a single-parameter constructor. Note: the constructor argument is computed +// even if it will not be used, so only values cheap to compute should be passed +// here. On the other hand it does not matter how expensive the construction of +// the actual stored value is, as that only occurs if necessary. +template <class Collection, class Arg> +typename Collection::value_type::second_type& +LookupOrInsertNewSharedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename Collection::value_type::second_type SharedPtr; + typedef typename Collection::value_type::second_type::element_type Element; + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, SharedPtr())); + if (ret.second) { + ret.first->second.reset(new Element(arg)); + } + return ret.first->second; +} + +// +// Misc Utility Functions +// + +// Updates the value associated with the given key. If the key was not already +// present, then the key-value pair are inserted and "previous" is unchanged. If +// the key was already present, the value is updated and "*previous" will +// contain a copy of the old value. +// +// InsertOrReturnExisting has complementary behavior that returns the +// address of an already existing value, rather than updating it. +template <class Collection> +bool UpdateReturnCopy(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value, + typename Collection::value_type::second_type* previous) { + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, value)); + if (!ret.second) { + // update + if (previous) { + *previous = ret.first->second; + } + ret.first->second = value; + return true; + } + return false; +} + +// Same as above except that the key and value are passed as a pair. +template <class Collection> +bool UpdateReturnCopy(Collection* const collection, + const typename Collection::value_type& vt, + typename Collection::value_type::second_type* previous) { + std::pair<typename Collection::iterator, bool> ret = collection->insert(vt); + if (!ret.second) { + // update + if (previous) { + *previous = ret.first->second; + } + ret.first->second = vt.second; + return true; + } + return false; +} + +// Tries to insert the given key-value pair into the collection. Returns nullptr if +// the insert succeeds. Otherwise, returns a pointer to the existing value. +// +// This complements UpdateReturnCopy in that it allows to update only after +// verifying the old value and still insert quickly without having to look up +// twice. Unlike UpdateReturnCopy this also does not come with the issue of an +// undefined previous* in case new data was inserted. +template <class Collection> +typename Collection::value_type::second_type* InsertOrReturnExisting( + Collection* const collection, const typename Collection::value_type& vt) { + std::pair<typename Collection::iterator, bool> ret = collection->insert(vt); + if (ret.second) { + return nullptr; // Inserted, no existing previous value. + } else { + return &ret.first->second; // Return address of already existing value. + } +} + +// Same as above, except for explicit key and data. +template <class Collection> +typename Collection::value_type::second_type* InsertOrReturnExisting( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + return InsertOrReturnExisting(collection, + typename Collection::value_type(key, data)); +} + +// Erases the collection item identified by the given key, and returns the value +// associated with that key. It is assumed that the value (i.e., the +// mapped_type) is a pointer. Returns nullptr if the key was not found in the +// collection. +// +// Examples: +// map<string, MyType*> my_map; +// +// One line cleanup: +// delete EraseKeyReturnValuePtr(&my_map, "abc"); +// +// Use returned value: +// std::unique_ptr<MyType> value_ptr( +// EraseKeyReturnValuePtr(&my_map, "abc")); +// if (value_ptr.get()) +// value_ptr->DoSomething(); +// +template <class Collection> +typename Collection::value_type::second_type EraseKeyReturnValuePtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection->find(key); + if (it == collection->end()) { + return nullptr; + } + typename Collection::value_type::second_type v = it->second; + collection->erase(it); + return v; +} + +// Inserts all the keys from map_container into key_container, which must +// support insert(MapContainer::key_type). +// +// Note: any initial contents of the key_container are not cleared. +template <class MapContainer, class KeyContainer> +void InsertKeysFromMap(const MapContainer& map_container, + KeyContainer* key_container) { + GOOGLE_CHECK(key_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->insert(it->first); + } +} + +// Appends all the keys from map_container into key_container, which must +// support push_back(MapContainer::key_type). +// +// Note: any initial contents of the key_container are not cleared. +template <class MapContainer, class KeyContainer> +void AppendKeysFromMap(const MapContainer& map_container, + KeyContainer* key_container) { + GOOGLE_CHECK(key_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->push_back(it->first); + } +} + +// A more specialized overload of AppendKeysFromMap to optimize reallocations +// for the common case in which we're appending keys to a vector and hence can +// (and sometimes should) call reserve() first. +// +// (It would be possible to play SFINAE games to call reserve() for any +// container that supports it, but this seems to get us 99% of what we need +// without the complexity of a SFINAE-based solution.) +template <class MapContainer, class KeyType> +void AppendKeysFromMap(const MapContainer& map_container, + std::vector<KeyType>* key_container) { + GOOGLE_CHECK(key_container != nullptr); + // We now have the opportunity to call reserve(). Calling reserve() every + // time is a bad idea for some use cases: libstdc++'s implementation of + // vector<>::reserve() resizes the vector's backing store to exactly the + // given size (unless it's already at least that big). Because of this, + // the use case that involves appending a lot of small maps (total size + // N) one by one to a vector would be O(N^2). But never calling reserve() + // loses the opportunity to improve the use case of adding from a large + // map to an empty vector (this improves performance by up to 33%). A + // number of heuristics are possible; see the discussion in + // cl/34081696. Here we use the simplest one. + if (key_container->empty()) { + key_container->reserve(map_container.size()); + } + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->push_back(it->first); + } +} + +// Inserts all the values from map_container into value_container, which must +// support push_back(MapContainer::mapped_type). +// +// Note: any initial contents of the value_container are not cleared. +template <class MapContainer, class ValueContainer> +void AppendValuesFromMap(const MapContainer& map_container, + ValueContainer* value_container) { + GOOGLE_CHECK(value_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + value_container->push_back(it->second); + } +} + +// A more specialized overload of AppendValuesFromMap to optimize reallocations +// for the common case in which we're appending values to a vector and hence +// can (and sometimes should) call reserve() first. +// +// (It would be possible to play SFINAE games to call reserve() for any +// container that supports it, but this seems to get us 99% of what we need +// without the complexity of a SFINAE-based solution.) +template <class MapContainer, class ValueType> +void AppendValuesFromMap(const MapContainer& map_container, + std::vector<ValueType>* value_container) { + GOOGLE_CHECK(value_container != nullptr); + // See AppendKeysFromMap for why this is done. + if (value_container->empty()) { + value_container->reserve(map_container.size()); + } + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + value_container->push_back(it->second); + } +} + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ |