diff options
author | thegeorg <thegeorg@yandex-team.com> | 2023-09-06 12:00:15 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2023-09-06 12:35:38 +0300 |
commit | 23225dd61414039ed8f923ca08c96efecc8894eb (patch) | |
tree | c35c77c85c0bca5f54ba4ceb397f442d9adfdf97 /contrib/libs/flatbuffers/include | |
parent | ee92fee2d806dd933291766e2f42948c481b6398 (diff) | |
download | ydb-23225dd61414039ed8f923ca08c96efecc8894eb.tar.gz |
Update contrib/libs/flatbuffers to 23.5.26
Diffstat (limited to 'contrib/libs/flatbuffers/include')
12 files changed, 73 insertions, 171 deletions
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/base.h b/contrib/libs/flatbuffers/include/flatbuffers/base.h index a416bc1b38..506fd545d1 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/base.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/base.h @@ -141,7 +141,7 @@ #define FLATBUFFERS_VERSION_MAJOR 23 #define FLATBUFFERS_VERSION_MINOR 5 -#define FLATBUFFERS_VERSION_REVISION 9 +#define FLATBUFFERS_VERSION_REVISION 26 #define FLATBUFFERS_STRING_EXPAND(X) #X #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) namespace flatbuffers { @@ -279,14 +279,14 @@ namespace flatbuffers { #endif // !FLATBUFFERS_LOCALE_INDEPENDENT // Suppress Undefined Behavior Sanitizer (recoverable only). Usage: -// - __suppress_ubsan__("undefined") -// - __suppress_ubsan__("signed-integer-overflow") +// - FLATBUFFERS_SUPPRESS_UBSAN("undefined") +// - FLATBUFFERS_SUPPRESS_UBSAN("signed-integer-overflow") #if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7)) - #define __suppress_ubsan__(type) __attribute__((no_sanitize(type))) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize(type))) #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) - #define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined)) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize_undefined)) #else - #define __suppress_ubsan__(type) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) #endif // This is constexpr function used for checking compile-time constants. @@ -424,7 +424,7 @@ template<typename T> T EndianScalar(T t) { template<typename T> // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__suppress_ubsan__("alignment") +FLATBUFFERS_SUPPRESS_UBSAN("alignment") T ReadScalar(const void *p) { return EndianScalar(*reinterpret_cast<const T *>(p)); } @@ -438,13 +438,13 @@ T ReadScalar(const void *p) { template<typename T> // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__suppress_ubsan__("alignment") +FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, T t) { *reinterpret_cast<T *>(p) = EndianScalar(t); } template<typename T> struct Offset; -template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) { +template<typename T> FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, Offset<T> t) { *reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o); } @@ -455,7 +455,7 @@ template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, O // Computes how many bytes you'd have to pad to be able to write an // "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in // memory). -__suppress_ubsan__("unsigned-integer-overflow") +FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) { return ((~buf_size) + 1) & (scalar_size - 1); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h b/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h index 2c05b7e247..de6ed6ff75 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h @@ -23,6 +23,10 @@ namespace flatbuffers { +struct CodeGenOptions { + std::string output_path; +}; + // A code generator interface for producing converting flatbuffer schema into // code. class CodeGenerator { @@ -44,9 +48,20 @@ class CodeGenerator { virtual Status GenerateCode(const Parser &parser, const std::string &path, const std::string &filename) = 0; + // Generate code from the provided `parser` and place it in the output. + virtual Status GenerateCodeString(const Parser &parser, + const std::string &filename, + std::string &output) { + (void)parser; + (void)filename; + (void)output; + return Status::NOT_IMPLEMENTED; + } + // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0; + virtual Status GenerateCode(const uint8_t *buffer, int64_t length, + const CodeGenOptions &options) = 0; virtual Status GenerateMakeRule(const Parser &parser, const std::string &path, const std::string &filename, diff --git a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h index 0407690616..fa5eb4c1ec 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h @@ -229,6 +229,10 @@ class TypedFloatConstantGenerator : public FloatConstantGenerator { const std::string neg_inf_number_; }; +std::string JavaCSharpMakeRule(const bool java, const Parser &parser, + const std::string &path, + const std::string &file_name); + } // namespace flatbuffers #endif // FLATBUFFERS_CODE_GENERATORS_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h index 4bb2a7222a..f97daa4046 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h @@ -722,9 +722,8 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { /// @param[in] len The number of elements to serialize. /// @return Returns a typed `TOffset` into the serialized data indicating /// where the vector is stored. - template<template<typename...> class OffsetT = Offset, - template<typename...> class VectorT = Vector, - int &...ExplicitArgumentBarrier, typename T> + template<typename T, template<typename...> class OffsetT = Offset, + template<typename...> class VectorT = Vector> OffsetT<VectorT<T>> CreateVector(const T *v, size_t len) { // The type of the length field in the vector. typedef typename VectorT<T>::size_type LenT; @@ -793,7 +792,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { template<template<typename...> class VectorT = Vector64, int &...ExplicitArgumentBarrier, typename T> Offset64<VectorT<T>> CreateVector64(const std::vector<T> &v) { - return CreateVector<Offset64, VectorT>(data(v), v.size()); + return CreateVector<T, Offset64, VectorT>(data(v), v.size()); } // vector<bool> may be implemented using a bit-set, so we can't access it as @@ -1302,11 +1301,6 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { // This will remain 0 if no 64-bit offset types are added to the buffer. size_t length_of_64_bit_region_; - // When true, 64-bit offsets can still be added to the builder. When false, - // only 32-bit offsets can be added, and attempts to add a 64-bit offset will - // raise an assertion. This is typically a compile-time error in ordering the - // serialization of 64-bit offset fields not at the tail of the buffer. - // Ensure objects are not nested. bool nested; @@ -1417,8 +1411,8 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { // Hack to `FlatBufferBuilder` mean `FlatBufferBuilder<false>` or // `FlatBufferBuilder<>`, where the template < > syntax is required. -typedef FlatBufferBuilderImpl<false> FlatBufferBuilder; -typedef FlatBufferBuilderImpl<true> FlatBufferBuilder64; +using FlatBufferBuilder = FlatBufferBuilderImpl<false>; +using FlatBufferBuilder64 = FlatBufferBuilderImpl<true>; // These are external due to GCC not allowing them in the class. // See: https://stackoverflow.com/q/8061456/868247 diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h index acf1e2c0ea..952ea3bcdf 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h @@ -81,6 +81,17 @@ inline SizeT GetPrefixedSize(const uint8_t *buf) { return ReadScalar<SizeT>(buf); } +// Gets the total length of the buffer given a sized prefixed FlatBuffer. +// +// This includes the size of the prefix as well as the buffer: +// +// [size prefix][flatbuffer] +// |---------length--------| +template<typename SizeT = uoffset_t> +inline SizeT GetSizePrefixedBufferLength(const uint8_t *const buf) { + return ReadScalar<SizeT>(buf) + sizeof(SizeT); +} + // Base class for native objects (FlatBuffer data de-serialized into native // C++ data structures). // Contains no functionality, purely documentative. diff --git a/contrib/libs/flatbuffers/include/flatbuffers/idl.h b/contrib/libs/flatbuffers/include/flatbuffers/idl.h index 1c07254ac3..f65f18a9ab 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/idl.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/idl.h @@ -723,7 +723,7 @@ struct IDLOptions { kRust = 1 << 14, kKotlin = 1 << 15, kSwift = 1 << 16, - kCppYandexMapsIter = 1 << 17, + kCppYandexMapsIter = 1 << 19, kNim = 1 << 17, kProto = 1 << 18, kMAX @@ -1152,6 +1152,7 @@ class Parser : public ParserState { bool SupportsOptionalScalars() const; bool SupportsDefaultVectorsAndStrings() const; bool Supports64BitOffsets() const; + bool SupportsUnionUnderlyingType() const; Namespace *UniqueNamespace(Namespace *ns); FLATBUFFERS_CHECKED_ERROR RecurseError(); @@ -1211,100 +1212,17 @@ class Parser : public ParserState { // if it is less than 0, no linefeeds will be generated either. // See idl_gen_text.cpp. // strict_json adds "quotes" around field names if true. -// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8 -// byte arrays in String values), returns false. -extern const char *GenerateTextFromTable(const Parser &parser, const void *table, - const std::string &tablename, - std::string *text); -extern const char *GenerateText(const Parser &parser, const void *flatbuffer, - std::string *text); -extern const char *GenerateTextFile(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Json schema to string -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, std::string *json); - -// Generate binary files from a given FlatBuffer, and a given Parser -// object that has been populated with the corresponding schema. -// See code_generators.cpp. -extern bool GenerateBinary(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a C++ header from the definitions in the Parser object. -// See idl_gen_cpp. -extern bool GenerateCPP(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate C# files from the definitions in the Parser object. -// See idl_gen_csharp.cpp. -extern bool GenerateCSharp(const Parser &parser, const std::string &path, - const std::string &file_name); - -extern bool GenerateDart(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Java files from the definitions in the Parser object. -// See idl_gen_java.cpp. -extern bool GenerateJava(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate JavaScript or TypeScript code from the definitions in the Parser -// object. See idl_gen_js. -extern bool GenerateTS(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Go files from the definitions in the Parser object. -// See idl_gen_go.cpp. -extern bool GenerateGo(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Php code from the definitions in the Parser object. -// See idl_gen_php. -extern bool GeneratePhp(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Python files from the definitions in the Parser object. -// See idl_gen_python.cpp. -extern bool GeneratePython(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Lobster files from the definitions in the Parser object. -// See idl_gen_lobster.cpp. -extern bool GenerateLobster(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Lua files from the definitions in the Parser object. -// See idl_gen_lua.cpp. -extern bool GenerateLua(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Rust files from the definitions in the Parser object. -// See idl_gen_rust.cpp. -extern bool GenerateRust(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Json schema file -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, const std::string &path, +// These functions return nullptr on success, or an error string, +// which may happen if the flatbuffer cannot be encoded in JSON (e.g., +// it contains non-UTF-8 byte arrays in String values). +extern const char *GenTextFromTable(const Parser &parser, const void *table, + const std::string &tablename, + std::string *text); +extern const char *GenText(const Parser &parser, const void *flatbuffer, + std::string *text); +extern const char *GenTextFile(const Parser &parser, const std::string &path, const std::string &file_name); -extern bool GenerateKotlin(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Swift classes. -// See idl_gen_swift.cpp -extern bool GenerateSwift(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a schema file from the internal representation, useful after -// parsing a .proto schema. -extern std::string GenerateFBS(const Parser &parser, - const std::string &file_name, bool no_log); -extern bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name, bool no_log); - // Generate a C++ header for reading with templated file iterator from // the definitions in the Parser object. // See idl_gen_cpp_yandex_maps_iter.cpp. @@ -1314,43 +1232,6 @@ extern bool GenerateCPPYandexMapsIter(const Parser &parser, const std::string &path, const std::string &file_name); -// Generate a make rule for the generated TypeScript code. -// See idl_gen_ts.cpp. -extern std::string TSMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated C++ header. -// See idl_gen_cpp.cpp. -extern std::string CPPMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Dart code -// see idl_gen_dart.cpp -extern std::string DartMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Rust code. -// See idl_gen_rust.cpp. -extern std::string RustMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for generated Java or C# files. -// See code_generators.cpp. -extern std::string CSharpMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); -extern std::string JavaMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated text (JSON) files. -// See idl_gen_text.cpp. -extern std::string TextMakeRule(const Parser &parser, const std::string &path, - const std::string &file_names); - -// Generate a make rule for the generated binary files. -// See code_generators.cpp. -extern std::string BinaryMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - // Generate GRPC Cpp interfaces. // See idl_gen_grpc.cpp. bool GenerateCppGRPC(const Parser &parser, const std::string &path, @@ -1378,9 +1259,6 @@ extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, extern bool GenerateTSGRPC(const Parser &parser, const std::string &path, const std::string &file_name); - -extern bool GenerateRustModuleRootFile(const Parser &parser, - const std::string &path); } // namespace flatbuffers #endif // FLATBUFFERS_IDL_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h index 067222d9dc..4690434db6 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h @@ -10,7 +10,7 @@ // generated, otherwise it may not be compatible. static_assert(FLATBUFFERS_VERSION_MAJOR == 23 && FLATBUFFERS_VERSION_MINOR == 5 && - FLATBUFFERS_VERSION_REVISION == 9, + FLATBUFFERS_VERSION_REVISION == 26, "Non-compatible flatbuffers version included"); namespace reflection { diff --git a/contrib/libs/flatbuffers/include/flatbuffers/table.h b/contrib/libs/flatbuffers/include/flatbuffers/table.h index 9ceafaa143..c5d548c21e 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/table.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/table.h @@ -153,7 +153,7 @@ class Table { return verifier.Check(field_offset != 0) && verifier.VerifyOffset<OffsetT>(data_, field_offset); } - + bool VerifyOffset64(const Verifier &verifier, voffset_t field) const { return VerifyOffset<uoffset64_t>(verifier, field); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/util.h b/contrib/libs/flatbuffers/include/flatbuffers/util.h index 03f61834c0..c781b7e233 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/util.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/util.h @@ -257,7 +257,7 @@ inline void strtoval_impl(double *val, const char *str, char **endptr) { } // UBSAN: double to float is safe if numeric_limits<float>::is_iec559 is true. -__suppress_ubsan__("float-cast-overflow") +FLATBUFFERS_SUPPRESS_UBSAN("float-cast-overflow") inline void strtoval_impl(float *val, const char *str, char **endptr) { *val = __strtof_impl(str, endptr); } @@ -623,7 +623,7 @@ inline bool EscapeString(const char *s, size_t length, std::string *_text, // we previously checked for non-UTF-8, so we shouldn't reach // here. // - // 2) We reached here by someone calling GenerateText() + // 2) We reached here by someone calling GenText() // on a previously-serialized flatbuffer. The data might have // non-UTF-8 Strings, or might be corrupt. // diff --git a/contrib/libs/flatbuffers/include/flatbuffers/vector.h b/contrib/libs/flatbuffers/include/flatbuffers/vector.h index 848e6c0b25..eb67922230 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/vector.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/vector.h @@ -147,12 +147,10 @@ struct VectorReverseIterator : public std::reverse_iterator<Iterator> { // Vector::data() assumes the vector elements start after the length field. template<typename T, typename SizeT = uoffset_t> class Vector { public: - typedef VectorIterator<T, - typename IndirectHelper<T>::mutable_return_type, + typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type, uint8_t *, SizeT> iterator; - typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type, - SizeT> + typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type, SizeT> const_iterator; typedef VectorReverseIterator<iterator> reverse_iterator; typedef VectorReverseIterator<const_iterator> const_reverse_iterator; @@ -171,8 +169,7 @@ template<typename T, typename SizeT = uoffset_t> class Vector { typedef SizeT size_type; typedef typename IndirectHelper<T>::return_type return_type; - typedef typename IndirectHelper<T>::mutable_return_type - mutable_return_type; + typedef typename IndirectHelper<T>::mutable_return_type mutable_return_type; typedef return_type value_type; return_type Get(SizeT i) const { diff --git a/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h b/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h index 7fd2551cfc..2055ce9c7f 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h @@ -17,9 +17,8 @@ #ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_ #define FLATBUFFERS_VECTOR_DOWNWARD_H_ -#include <cstdint> - #include <algorithm> +#include <cstdint> #include "base.h" #include "default_allocator.h" @@ -167,7 +166,9 @@ template<typename SizeT = uoffset_t> class vector_downward { inline SizeT size() const { return size_; } // The size of the buffer part of the vector that is currently unused. - SizeT unused_buffer_size() const { return static_cast<SizeT>(cur_ - scratch_); } + SizeT unused_buffer_size() const { + return static_cast<SizeT>(cur_ - scratch_); + } // The size of the scratch part of the vector. SizeT scratch_size() const { return static_cast<SizeT>(scratch_ - buf_); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/verifier.h b/contrib/libs/flatbuffers/include/flatbuffers/verifier.h index 86dbcb4eac..3386408465 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/verifier.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/verifier.h @@ -177,8 +177,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS { return true; } - __suppress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart( - const uint8_t *const table) { + FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") + bool VerifyTableStart(const uint8_t *const table) { // Check the vtable offset. const auto tableo = static_cast<size_t>(table - buf_); if (!Verify<soffset_t>(tableo)) return false; @@ -246,7 +246,9 @@ class Verifier FLATBUFFERS_FINAL_CLASS { template<typename T, typename SizeT = uoffset_t> bool VerifySizePrefixedBuffer(const char *const identifier) { return Verify<SizeT>(0U) && - Check(ReadScalar<SizeT>(buf_) == size_ - sizeof(SizeT)) && + // Ensure the prefixed size is within the bounds of the provided + // length. + Check(ReadScalar<SizeT>(buf_) + sizeof(SizeT) <= size_) && VerifyBufferFromStart<T>(identifier, sizeof(SizeT)); } |