diff --git a/3rdparty/flatbuffers/README.md b/3rdparty/flatbuffers/README.md index 4ea040adc6..bbd293d782 100644 --- a/3rdparty/flatbuffers/README.md +++ b/3rdparty/flatbuffers/README.md @@ -1 +1 @@ -Origin: https://github.com/google/flatbuffers/tree/v23.5.9 +Origin: https://github.com/google/flatbuffers/tree/v25.9.23 diff --git a/3rdparty/flatbuffers/include/flatbuffers/allocator.h b/3rdparty/flatbuffers/include/flatbuffers/allocator.h index 30427190b6..d451818568 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/allocator.h +++ b/3rdparty/flatbuffers/include/flatbuffers/allocator.h @@ -28,21 +28,21 @@ class Allocator { virtual ~Allocator() {} // Allocate `size` bytes of memory. - virtual uint8_t *allocate(size_t size) = 0; + virtual uint8_t* allocate(size_t size) = 0; // Deallocate `size` bytes of memory at `p` allocated by this allocator. - virtual void deallocate(uint8_t *p, size_t size) = 0; + virtual void deallocate(uint8_t* p, size_t size) = 0; // Reallocate `new_size` bytes of memory, replacing the old region of size // `old_size` at `p`. In contrast to a normal realloc, this grows downwards, // and is intended specifcally for `vector_downward` use. // `in_use_back` and `in_use_front` indicate how much of `old_size` is // actually in use at each end, and needs to be copied. - virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, + virtual uint8_t* reallocate_downward(uint8_t* old_p, size_t old_size, size_t new_size, size_t in_use_back, size_t in_use_front) { FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows - uint8_t *new_p = allocate(new_size); + uint8_t* new_p = allocate(new_size); memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, in_use_front); deallocate(old_p, old_size); @@ -54,7 +54,7 @@ class Allocator { // to `new_p` of `new_size`. Only memory of size `in_use_front` and // `in_use_back` will be copied from the front and back of the old memory // allocation. - void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p, + void memcpy_downward(uint8_t* old_p, size_t old_size, uint8_t* new_p, size_t new_size, size_t in_use_back, size_t in_use_front) { memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back, diff --git a/3rdparty/flatbuffers/include/flatbuffers/array.h b/3rdparty/flatbuffers/include/flatbuffers/array.h index f4bfbf054c..914f479aab 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/array.h +++ b/3rdparty/flatbuffers/include/flatbuffers/array.h @@ -27,17 +27,15 @@ namespace flatbuffers { // This is used as a helper type for accessing arrays. -template class Array { +template +class Array { // Array can carry only POD data types (scalars or structs). typedef typename flatbuffers::bool_constant::value> scalar_tag; - typedef - typename flatbuffers::conditional::type - IndirectHelperType; public: typedef uint16_t size_type; - typedef typename IndirectHelper::return_type return_type; + typedef typename IndirectHelper::return_type return_type; typedef VectorConstIterator const_iterator; typedef VectorReverseIterator const_reverse_iterator; @@ -50,7 +48,7 @@ template class Array { return_type Get(uoffset_t i) const { FLATBUFFERS_ASSERT(i < size()); - return IndirectHelper::Read(Data(), i); + return IndirectHelper::Read(Data(), i); } return_type operator[](uoffset_t i) const { return Get(i); } @@ -58,7 +56,8 @@ template class Array { // If this is a Vector of enums, T will be its storage type, not the enum // type. This function makes it convenient to retrieve value with enum // type E. - template E GetEnum(uoffset_t i) const { + template + E GetEnum(uoffset_t i) const { return static_cast(Get(i)); } @@ -83,28 +82,28 @@ template class Array { // operation. For primitive types use @p Mutate directly. // @warning Assignments and reads to/from the dereferenced pointer are not // automatically converted to the correct endianness. - typename flatbuffers::conditional::type + typename flatbuffers::conditional::type GetMutablePointer(uoffset_t i) const { FLATBUFFERS_ASSERT(i < size()); - return const_cast(&data()[i]); + return const_cast(&data()[i]); } // Change elements if you have a non-const pointer to this object. - void Mutate(uoffset_t i, const T &val) { MutateImpl(scalar_tag(), i, val); } + void Mutate(uoffset_t i, const T& val) { MutateImpl(scalar_tag(), i, val); } // The raw data in little endian format. Use with care. - const uint8_t *Data() const { return data_; } + const uint8_t* Data() const { return data_; } - uint8_t *Data() { return data_; } + uint8_t* Data() { return data_; } // Similarly, but typed, much like std::vector::data - const T *data() const { return reinterpret_cast(Data()); } - T *data() { return reinterpret_cast(Data()); } + const T* data() const { return reinterpret_cast(Data()); } + T* data() { return reinterpret_cast(Data()); } // Copy data from a span with endian conversion. // If this Array and the span overlap, the behavior is undefined. void CopyFromSpan(flatbuffers::span src) { - const auto p1 = reinterpret_cast(src.data()); + const auto p1 = reinterpret_cast(src.data()); const auto p2 = Data(); FLATBUFFERS_ASSERT(!(p1 >= p2 && p1 < (p2 + length)) && !(p2 >= p1 && p2 < (p1 + length))); @@ -114,12 +113,12 @@ template class Array { } protected: - void MutateImpl(flatbuffers::true_type, uoffset_t i, const T &val) { + void MutateImpl(flatbuffers::true_type, uoffset_t i, const T& val) { FLATBUFFERS_ASSERT(i < size()); WriteScalar(data() + i, val); } - void MutateImpl(flatbuffers::false_type, uoffset_t i, const T &val) { + void MutateImpl(flatbuffers::false_type, uoffset_t i, const T& val) { *(GetMutablePointer(i)) = val; } @@ -134,7 +133,9 @@ template class Array { // Copy data from flatbuffers::span with endian conversion. void CopyFromSpanImpl(flatbuffers::false_type, flatbuffers::span src) { - for (size_type k = 0; k < length; k++) { Mutate(k, src[k]); } + for (size_type k = 0; k < length; k++) { + Mutate(k, src[k]); + } } // This class is only used to access pre-existing data. Don't ever @@ -153,21 +154,21 @@ template class Array { private: // This class is a pointer. Copying will therefore create an invalid object. // Private and unimplemented copy constructor. - Array(const Array &); - Array &operator=(const Array &); + Array(const Array&); + Array& operator=(const Array&); }; // Specialization for Array[struct] with access using Offset pointer. // This specialization used by idl_gen_text.cpp. -template class OffsetT> +template class OffsetT> class Array, length> { static_assert(flatbuffers::is_same::value, "unexpected type T"); public: - typedef const void *return_type; + typedef const void* return_type; typedef uint16_t size_type; - const uint8_t *Data() const { return data_; } + const uint8_t* Data() const { return data_; } // Make idl_gen_text.cpp::PrintContainer happy. return_type operator[](uoffset_t) const { @@ -178,14 +179,14 @@ class Array, length> { private: // This class is only used to access pre-existing data. Array(); - Array(const Array &); - Array &operator=(const Array &); + Array(const Array&); + Array& operator=(const Array&); uint8_t data_[1]; }; -template -FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span make_span(Array &arr) +template +FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span make_span(Array& arr) FLATBUFFERS_NOEXCEPT { static_assert( Array::is_span_observable, @@ -193,26 +194,26 @@ FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span make_span(Array &arr) return span(arr.data(), N); } -template +template FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span make_span( - const Array &arr) FLATBUFFERS_NOEXCEPT { + const Array& arr) FLATBUFFERS_NOEXCEPT { static_assert( Array::is_span_observable, "wrong type U, only plain struct, LE-scalar, or byte types are allowed"); return span(arr.data(), N); } -template +template FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span -make_bytes_span(Array &arr) FLATBUFFERS_NOEXCEPT { +make_bytes_span(Array& arr) FLATBUFFERS_NOEXCEPT { static_assert(Array::is_span_observable, "internal error, Array might hold only scalars or structs"); return span(arr.Data(), sizeof(U) * N); } -template +template FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span -make_bytes_span(const Array &arr) FLATBUFFERS_NOEXCEPT { +make_bytes_span(const Array& arr) FLATBUFFERS_NOEXCEPT { static_assert(Array::is_span_observable, "internal error, Array might hold only scalars or structs"); return span(arr.Data(), sizeof(U) * N); @@ -221,31 +222,31 @@ make_bytes_span(const Array &arr) FLATBUFFERS_NOEXCEPT { // Cast a raw T[length] to a raw flatbuffers::Array // without endian conversion. Use with care. // TODO: move these Cast-methods to `internal` namespace. -template -Array &CastToArray(T (&arr)[length]) { - return *reinterpret_cast *>(arr); +template +Array& CastToArray(T (&arr)[length]) { + return *reinterpret_cast*>(arr); } -template -const Array &CastToArray(const T (&arr)[length]) { - return *reinterpret_cast *>(arr); +template +const Array& CastToArray(const T (&arr)[length]) { + return *reinterpret_cast*>(arr); } -template -Array &CastToArrayOfEnum(T (&arr)[length]) { +template +Array& CastToArrayOfEnum(T (&arr)[length]) { static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); - return *reinterpret_cast *>(arr); + return *reinterpret_cast*>(arr); } -template -const Array &CastToArrayOfEnum(const T (&arr)[length]) { +template +const Array& CastToArrayOfEnum(const T (&arr)[length]) { static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); - return *reinterpret_cast *>(arr); + return *reinterpret_cast*>(arr); } -template -bool operator==(const Array &lhs, - const Array &rhs) noexcept { +template +bool operator==(const Array& lhs, + const Array& rhs) noexcept { return std::addressof(lhs) == std::addressof(rhs) || (lhs.size() == rhs.size() && std::memcmp(lhs.Data(), rhs.Data(), rhs.size() * sizeof(T)) == 0); diff --git a/3rdparty/flatbuffers/include/flatbuffers/base.h b/3rdparty/flatbuffers/include/flatbuffers/base.h index ac8db356a4..987dcbc406 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/base.h +++ b/3rdparty/flatbuffers/include/flatbuffers/base.h @@ -139,9 +139,9 @@ #endif #endif // !defined(FLATBUFFERS_LITTLEENDIAN) -#define FLATBUFFERS_VERSION_MAJOR 23 -#define FLATBUFFERS_VERSION_MINOR 5 -#define FLATBUFFERS_VERSION_REVISION 9 +#define FLATBUFFERS_VERSION_MAJOR 25 +#define FLATBUFFERS_VERSION_MINOR 9 +#define FLATBUFFERS_VERSION_REVISION 23 #define FLATBUFFERS_STRING_EXPAND(X) #X #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) namespace flatbuffers { @@ -155,7 +155,7 @@ namespace flatbuffers { #define FLATBUFFERS_FINAL_CLASS final #define FLATBUFFERS_OVERRIDE override #define FLATBUFFERS_EXPLICIT_CPP11 explicit - #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t + #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : ::flatbuffers::voffset_t #else #define FLATBUFFERS_FINAL_CLASS #define FLATBUFFERS_OVERRIDE @@ -279,20 +279,22 @@ 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. -// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`. -template FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) { - return !!t; +namespace flatbuffers { + // This is constexpr function used for checking compile-time constants. + // Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`. + template FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) { + return !!t; + } } // Enable C++ attribute [[]] if std:c++17 or higher. @@ -337,15 +339,15 @@ typedef uint16_t voffset_t; typedef uintmax_t largest_scalar_t; // In 32bits, this evaluates to 2GB - 1 -#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max() -#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max() +#define FLATBUFFERS_MAX_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset_t>::max)() +#define FLATBUFFERS_MAX_64_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset64_t>::max)() // The minimum size buffer that can be a valid flatbuffer. // Includes the offset to the root table (uoffset_t), the offset to the vtable // of the root table (soffset_t), the size of the vtable (uint16_t), and the // size of the referring table (uint16_t). -#define FLATBUFFERS_MIN_BUFFER_SIZE sizeof(uoffset_t) + sizeof(soffset_t) + \ - sizeof(uint16_t) + sizeof(uint16_t) +#define FLATBUFFERS_MIN_BUFFER_SIZE sizeof(::flatbuffers::uoffset_t) + \ + sizeof(::flatbuffers::soffset_t) + sizeof(uint16_t) + sizeof(uint16_t) // We support aligning the contents of buffers up to this size. #ifndef FLATBUFFERS_MAX_ALIGNMENT @@ -361,7 +363,6 @@ inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) { } #if defined(_MSC_VER) - #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized #pragma warning(push) #pragma warning(disable: 4127) // C4127: conditional expression is constant #endif @@ -422,7 +423,7 @@ template T EndianScalar(T t) { template // 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(p)); } @@ -436,13 +437,13 @@ T ReadScalar(const void *p) { template // 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(p) = EndianScalar(t); } template struct Offset; -template __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset t) { +template FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, Offset t) { *reinterpret_cast(p) = EndianScalar(t.o); } @@ -453,15 +454,22 @@ template __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); } +#if !defined(_MSC_VER) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif // Generic 'operator==' with conditional specialisations. // T e - new value of a scalar field. // T def - default of scalar (is known at compile-time). template inline bool IsTheSameAs(T e, T def) { return e == def; } +#if !defined(_MSC_VER) + #pragma GCC diagnostic pop +#endif #if defined(FLATBUFFERS_NAN_DEFAULTS) && \ defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0) diff --git a/3rdparty/flatbuffers/include/flatbuffers/buffer.h b/3rdparty/flatbuffers/include/flatbuffers/buffer.h index 94d4f7903b..154d187ab7 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/buffer.h +++ b/3rdparty/flatbuffers/include/flatbuffers/buffer.h @@ -20,12 +20,14 @@ #include #include "flatbuffers/base.h" +#include "flatbuffers/stl_emulation.h" namespace flatbuffers { // Wrapper for uoffset_t to allow safe template specialization. // Value is allowed to be 0 to indicate a null object (see e.g. AddOffset). -template struct Offset { +template +struct Offset { // The type of offset to use. typedef uoffset_t offset_type; @@ -36,8 +38,14 @@ template struct Offset { bool IsNull() const { return !o; } }; +template +struct is_specialisation_of_Offset : false_type {}; +template +struct is_specialisation_of_Offset> : true_type {}; + // Wrapper for uoffset64_t Offsets. -template struct Offset64 { +template +struct Offset64 { // The type of offset to use. typedef uoffset64_t offset_type; @@ -48,6 +56,11 @@ template struct Offset64 { bool IsNull() const { return !o; } }; +template +struct is_specialisation_of_Offset64 : false_type {}; +template +struct is_specialisation_of_Offset64> : true_type {}; + // Litmus check for ensuring the Offsets are the expected size. static_assert(sizeof(Offset<>) == 4, "Offset has wrong size"); static_assert(sizeof(Offset64<>) == 8, "Offset64 has wrong size"); @@ -55,12 +68,13 @@ static_assert(sizeof(Offset64<>) == 8, "Offset64 has wrong size"); inline void EndianCheck() { int endiantest = 1; // If this fails, see FLATBUFFERS_LITTLEENDIAN above. - FLATBUFFERS_ASSERT(*reinterpret_cast(&endiantest) == + FLATBUFFERS_ASSERT(*reinterpret_cast(&endiantest) == FLATBUFFERS_LITTLEENDIAN); (void)endiantest; } -template FLATBUFFERS_CONSTEXPR size_t AlignOf() { +template +FLATBUFFERS_CONSTEXPR size_t AlignOf() { // clang-format off #ifdef _MSC_VER return __alignof(T); @@ -76,8 +90,8 @@ template FLATBUFFERS_CONSTEXPR size_t AlignOf() { // Lexicographically compare two strings (possibly containing nulls), and // return true if the first is less than the second. -static inline bool StringLessThan(const char *a_data, uoffset_t a_size, - const char *b_data, uoffset_t b_size) { +static inline bool StringLessThan(const char* a_data, uoffset_t a_size, + const char* b_data, uoffset_t b_size) { const auto cmp = memcmp(a_data, b_data, (std::min)(a_size, b_size)); return cmp == 0 ? a_size < b_size : cmp < 0; } @@ -90,42 +104,43 @@ static inline bool StringLessThan(const char *a_data, uoffset_t a_size, // return type like this. // The typedef is for the convenience of callers of this function // (avoiding the need for a trailing return decltype) -template struct IndirectHelper { +template +struct IndirectHelper { typedef T return_type; typedef T mutable_return_type; static const size_t element_stride = sizeof(T); - static return_type Read(const uint8_t *p, const size_t i) { - return EndianScalar((reinterpret_cast(p))[i]); + static return_type Read(const uint8_t* p, const size_t i) { + return EndianScalar((reinterpret_cast(p))[i]); } - static mutable_return_type Read(uint8_t *p, const size_t i) { + static mutable_return_type Read(uint8_t* p, const size_t i) { return reinterpret_cast( - Read(const_cast(p), i)); + Read(const_cast(p), i)); } }; // For vector of Offsets. -template class OffsetT> +template class OffsetT> struct IndirectHelper> { - typedef const T *return_type; - typedef T *mutable_return_type; + typedef const T* return_type; + typedef T* mutable_return_type; typedef typename OffsetT::offset_type offset_type; static const offset_type element_stride = sizeof(offset_type); - static return_type Read(const uint8_t *const p, const offset_type i) { + static return_type Read(const uint8_t* const p, const offset_type i) { // Offsets are relative to themselves, so first update the pointer to // point to the offset location. - const uint8_t *const offset_location = p + i * element_stride; + const uint8_t* const offset_location = p + i * element_stride; // Then read the scalar value of the offset (which may be 32 or 64-bits) and // then determine the relative location from the offset location. return reinterpret_cast( offset_location + ReadScalar(offset_location)); } - static mutable_return_type Read(uint8_t *const p, const offset_type i) { + static mutable_return_type Read(uint8_t* const p, const offset_type i) { // Offsets are relative to themselves, so first update the pointer to // point to the offset location. - uint8_t *const offset_location = p + i * element_stride; + uint8_t* const offset_location = p + i * element_stride; // Then read the scalar value of the offset (which may be 32 or 64-bits) and // then determine the relative location from the offset location. @@ -135,16 +150,26 @@ struct IndirectHelper> { }; // For vector of structs. -template struct IndirectHelper { - typedef const T *return_type; - typedef T *mutable_return_type; - static const size_t element_stride = sizeof(T); +template +struct IndirectHelper< + T, typename std::enable_if< + !std::is_scalar::type>::value && + !is_specialisation_of_Offset::value && + !is_specialisation_of_Offset64::value>::type> { + private: + typedef typename std::remove_pointer::type>::type + pointee_type; - static return_type Read(const uint8_t *const p, const size_t i) { + public: + typedef const pointee_type* return_type; + typedef pointee_type* mutable_return_type; + static const size_t element_stride = sizeof(pointee_type); + + static return_type Read(const uint8_t* const p, const size_t i) { // Structs are stored inline, relative to the first struct pointer. return reinterpret_cast(p + i * element_stride); } - static mutable_return_type Read(uint8_t *const p, const size_t i) { + static mutable_return_type Read(uint8_t* const p, const size_t i) { // Structs are stored inline, relative to the first struct pointer. return reinterpret_cast(p + i * element_stride); } @@ -157,14 +182,14 @@ template struct IndirectHelper { /// This function is UNDEFINED for FlatBuffers whose schema does not include /// a file_identifier (likely points at padding or the start of a the root /// vtable). -inline const char *GetBufferIdentifier(const void *buf, +inline const char* GetBufferIdentifier(const void* buf, bool size_prefixed = false) { - return reinterpret_cast(buf) + + return reinterpret_cast(buf) + ((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t)); } // Helper to see if the identifier in a buffer has the expected value. -inline bool BufferHasIdentifier(const void *buf, const char *identifier, +inline bool BufferHasIdentifier(const void* buf, const char* identifier, bool size_prefixed = false) { return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier, flatbuffers::kFileIdentifierLength) == 0; @@ -172,26 +197,27 @@ inline bool BufferHasIdentifier(const void *buf, const char *identifier, /// @cond FLATBUFFERS_INTERNAL // Helpers to get a typed pointer to the root object contained in the buffer. -template T *GetMutableRoot(void *buf) { +template +T* GetMutableRoot(void* buf) { if (!buf) return nullptr; EndianCheck(); - return reinterpret_cast( - reinterpret_cast(buf) + - EndianScalar(*reinterpret_cast(buf))); + return reinterpret_cast(reinterpret_cast(buf) + + EndianScalar(*reinterpret_cast(buf))); } -template -T *GetMutableSizePrefixedRoot(void *buf) { - return GetMutableRoot(reinterpret_cast(buf) + sizeof(SizeT)); +template +T* GetMutableSizePrefixedRoot(void* buf) { + return GetMutableRoot(reinterpret_cast(buf) + sizeof(SizeT)); } -template const T *GetRoot(const void *buf) { - return GetMutableRoot(const_cast(buf)); +template +const T* GetRoot(const void* buf) { + return GetMutableRoot(const_cast(buf)); } -template -const T *GetSizePrefixedRoot(const void *buf) { - return GetRoot(reinterpret_cast(buf) + sizeof(SizeT)); +template +const T* GetSizePrefixedRoot(const void* buf) { + return GetRoot(reinterpret_cast(buf) + sizeof(SizeT)); } } // namespace flatbuffers diff --git a/3rdparty/flatbuffers/include/flatbuffers/buffer_ref.h b/3rdparty/flatbuffers/include/flatbuffers/buffer_ref.h index f70941fc64..746903eb97 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/buffer_ref.h +++ b/3rdparty/flatbuffers/include/flatbuffers/buffer_ref.h @@ -27,23 +27,24 @@ namespace flatbuffers { // A BufferRef does not own its buffer. struct BufferRefBase {}; // for std::is_base_of -template struct BufferRef : BufferRefBase { +template +struct BufferRef : BufferRefBase { BufferRef() : buf(nullptr), len(0), must_free(false) {} - BufferRef(uint8_t *_buf, uoffset_t _len) + BufferRef(uint8_t* _buf, uoffset_t _len) : buf(_buf), len(_len), must_free(false) {} ~BufferRef() { if (must_free) free(buf); } - const T *GetRoot() const { return flatbuffers::GetRoot(buf); } + const T* GetRoot() const { return flatbuffers::GetRoot(buf); } bool Verify() { Verifier verifier(buf, len); return verifier.VerifyBuffer(nullptr); } - uint8_t *buf; + uint8_t* buf; uoffset_t len; bool must_free; }; diff --git a/3rdparty/flatbuffers/include/flatbuffers/default_allocator.h b/3rdparty/flatbuffers/include/flatbuffers/default_allocator.h index d4724122cb..d1cab08d74 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/default_allocator.h +++ b/3rdparty/flatbuffers/include/flatbuffers/default_allocator.h @@ -25,32 +25,32 @@ namespace flatbuffers { // DefaultAllocator uses new/delete to allocate memory regions class DefaultAllocator : public Allocator { public: - uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE { + uint8_t* allocate(size_t size) FLATBUFFERS_OVERRIDE { return new uint8_t[size]; } - void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; } + void deallocate(uint8_t* p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; } - static void dealloc(void *p, size_t) { delete[] static_cast(p); } + static void dealloc(void* p, size_t) { delete[] static_cast(p); } }; // These functions allow for a null allocator to mean use the default allocator, // as used by DetachedBuffer and vector_downward below. // This is to avoid having a statically or dynamically allocated default // allocator, or having to move it between the classes that may own it. -inline uint8_t *Allocate(Allocator *allocator, size_t size) { +inline uint8_t* Allocate(Allocator* allocator, size_t size) { return allocator ? allocator->allocate(size) : DefaultAllocator().allocate(size); } -inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) { +inline void Deallocate(Allocator* allocator, uint8_t* p, size_t size) { if (allocator) allocator->deallocate(p, size); else DefaultAllocator().deallocate(p, size); } -inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p, +inline uint8_t* ReallocateDownward(Allocator* allocator, uint8_t* old_p, size_t old_size, size_t new_size, size_t in_use_back, size_t in_use_front) { return allocator ? allocator->reallocate_downward(old_p, old_size, new_size, diff --git a/3rdparty/flatbuffers/include/flatbuffers/detached_buffer.h b/3rdparty/flatbuffers/include/flatbuffers/detached_buffer.h index 5e900baeb5..0577a42d96 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/detached_buffer.h +++ b/3rdparty/flatbuffers/include/flatbuffers/detached_buffer.h @@ -36,8 +36,8 @@ class DetachedBuffer { cur_(nullptr), size_(0) {} - DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf, - size_t reserved, uint8_t *cur, size_t sz) + DetachedBuffer(Allocator* allocator, bool own_allocator, uint8_t* buf, + size_t reserved, uint8_t* cur, size_t sz) : allocator_(allocator), own_allocator_(own_allocator), buf_(buf), @@ -45,7 +45,7 @@ class DetachedBuffer { cur_(cur), size_(sz) {} - DetachedBuffer(DetachedBuffer &&other) noexcept + DetachedBuffer(DetachedBuffer&& other) noexcept : allocator_(other.allocator_), own_allocator_(other.own_allocator_), buf_(other.buf_), @@ -55,7 +55,7 @@ class DetachedBuffer { other.reset(); } - DetachedBuffer &operator=(DetachedBuffer &&other) noexcept { + DetachedBuffer& operator=(DetachedBuffer&& other) noexcept { if (this == &other) return *this; destroy(); @@ -74,28 +74,35 @@ class DetachedBuffer { ~DetachedBuffer() { destroy(); } - const uint8_t *data() const { return cur_; } + const uint8_t* data() const { return cur_; } - uint8_t *data() { return cur_; } + uint8_t* data() { return cur_; } size_t size() const { return size_; } + uint8_t* begin() { return data(); } + const uint8_t* begin() const { return data(); } + uint8_t* end() { return data() + size(); } + const uint8_t* end() const { return data() + size(); } + // These may change access mode, leave these at end of public section - FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other)); + FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer& other)); FLATBUFFERS_DELETE_FUNC( - DetachedBuffer &operator=(const DetachedBuffer &other)); + DetachedBuffer& operator=(const DetachedBuffer& other)); protected: - Allocator *allocator_; + Allocator* allocator_; bool own_allocator_; - uint8_t *buf_; + uint8_t* buf_; size_t reserved_; - uint8_t *cur_; + uint8_t* cur_; size_t size_; inline void destroy() { if (buf_) Deallocate(allocator_, buf_, reserved_); - if (own_allocator_ && allocator_) { delete allocator_; } + if (own_allocator_ && allocator_) { + delete allocator_; + } reset(); } diff --git a/3rdparty/flatbuffers/include/flatbuffers/flatbuffer_builder.h b/3rdparty/flatbuffers/include/flatbuffers/flatbuffer_builder.h index ed932cd9cc..9eea6bab0c 100644 --- a/3rdparty/flatbuffers/include/flatbuffers/flatbuffer_builder.h +++ b/3rdparty/flatbuffers/include/flatbuffers/flatbuffer_builder.h @@ -45,22 +45,24 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) { // Should correspond to what EndTable() below builds up. const voffset_t fixed_fields = 2 * sizeof(voffset_t); // Vtable size and Object Size. - return fixed_fields + field_id * sizeof(voffset_t); + size_t offset = fixed_fields + field_id * sizeof(voffset_t); + FLATBUFFERS_ASSERT(offset < std::numeric_limits::max()); + return static_cast(offset); } -template> -const T *data(const std::vector &v) { +template > +const T* data(const std::vector& v) { // Eventually the returned pointer gets passed down to memcpy, so // we need it to be non-null to avoid undefined behavior. static uint8_t t; - return v.empty() ? reinterpret_cast(&t) : &v.front(); + return v.empty() ? reinterpret_cast(&t) : &v.front(); } -template> -T *data(std::vector &v) { +template > +T* data(std::vector& v) { // Eventually the returned pointer gets passed down to memcpy, so // we need it to be non-null to avoid undefined behavior. static uint8_t t; - return v.empty() ? reinterpret_cast(&t) : &v.front(); + return v.empty() ? reinterpret_cast(&t) : &v.front(); } /// @addtogroup flatbuffers_cpp_api @@ -72,7 +74,8 @@ T *data(std::vector &v) { /// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/ /// `CreateVector` functions. Do this is depth-first order to build up a tree to /// the root. `Finish()` wraps up the buffer ready for transport. -template class FlatBufferBuilderImpl { +template +class FlatBufferBuilderImpl { public: // This switches the size type of the builder, based on if its 64-bit aware // (uoffset64_t) or not (uoffset_t). @@ -91,7 +94,7 @@ template class FlatBufferBuilderImpl { /// types with custom alignment AND you wish to read the buffer in-place /// directly after creation. explicit FlatBufferBuilderImpl( - size_t initial_size = 1024, Allocator *allocator = nullptr, + size_t initial_size = 1024, Allocator* allocator = nullptr, bool own_allocator = false, size_t buffer_minalign = AlignOf()) : buf_(initial_size, allocator, own_allocator, buffer_minalign, @@ -110,7 +113,7 @@ template class FlatBufferBuilderImpl { } /// @brief Move constructor for FlatBufferBuilder. - FlatBufferBuilderImpl(FlatBufferBuilderImpl &&other) noexcept + FlatBufferBuilderImpl(FlatBufferBuilderImpl&& other) noexcept : buf_(1024, nullptr, false, AlignOf(), static_cast(Is64Aware ? FLATBUFFERS_MAX_64_BUFFER_SIZE : FLATBUFFERS_MAX_BUFFER_SIZE)), @@ -131,14 +134,14 @@ template class FlatBufferBuilderImpl { } /// @brief Move assignment operator for FlatBufferBuilder. - FlatBufferBuilderImpl &operator=(FlatBufferBuilderImpl &&other) noexcept { + FlatBufferBuilderImpl& operator=(FlatBufferBuilderImpl&& other) noexcept { // Move construct a temporary and swap idiom FlatBufferBuilderImpl temp(std::move(other)); Swap(temp); return *this; } - void Swap(FlatBufferBuilderImpl &other) { + void Swap(FlatBufferBuilderImpl& other) { using std::swap; buf_.swap(other.buf_); swap(num_field_loc, other.num_field_loc); @@ -180,7 +183,7 @@ template class FlatBufferBuilderImpl { /// @brief The current size of the serialized buffer relative to the end of /// the 32-bit region. /// @return Returns an `uoffset_t` with the current size of the buffer. - template + template // Only enable this method for the 64-bit builder, as only that builder is // concerned with the 32/64-bit boundary, and should be the one to bare any // run time costs. @@ -193,7 +196,7 @@ template class FlatBufferBuilderImpl { return static_cast(GetSize() - length_of_64_bit_region_); } - template + template // Only enable this method for the 32-bit builder. typename std::enable_if::type GetSizeRelative32BitRegion() const { @@ -203,7 +206,7 @@ template class FlatBufferBuilderImpl { /// @brief Get the serialized buffer (after you call `Finish()`). /// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the /// buffer. - uint8_t *GetBufferPointer() const { + uint8_t* GetBufferPointer() const { Finished(); return buf_.data(); } @@ -218,23 +221,15 @@ template class FlatBufferBuilderImpl { /// @brief Get a pointer to an unfinished buffer. /// @return Returns a `uint8_t` pointer to the unfinished buffer. - uint8_t *GetCurrentBufferPointer() const { return buf_.data(); } - - /// @brief Get the released pointer to the serialized buffer. - /// @warning Do NOT attempt to use this FlatBufferBuilder afterwards! - /// @return A `FlatBuffer` that owns the buffer and its allocator and - /// behaves similar to a `unique_ptr` with a deleter. - FLATBUFFERS_ATTRIBUTE([[deprecated("use Release() instead")]]) - DetachedBuffer ReleaseBufferPointer() { - Finished(); - return buf_.release(); - } + uint8_t* GetCurrentBufferPointer() const { return buf_.data(); } /// @brief Get the released DetachedBuffer. /// @return A `DetachedBuffer` that owns the buffer and its allocator. DetachedBuffer Release() { Finished(); - return buf_.release(); + DetachedBuffer buffer = buf_.release(); + Clear(); + return buffer; } /// @brief Get the released pointer to the serialized buffer. @@ -245,10 +240,12 @@ template class FlatBufferBuilderImpl { /// @return A raw pointer to the start of the memory block containing /// the serialized `FlatBuffer`. /// @remark If the allocator is owned, it gets deleted when the destructor is - /// called.. - uint8_t *ReleaseRaw(size_t &size, size_t &offset) { + /// called. + uint8_t* ReleaseRaw(size_t& size, size_t& offset) { Finished(); - return buf_.release_raw(size, offset); + uint8_t* raw = buf_.release_raw(size, offset); + Clear(); + return raw; } /// @brief get the minimum alignment this buffer needs to be accessed @@ -295,22 +292,23 @@ template class FlatBufferBuilderImpl { buf_.fill(PaddingBytes(buf_.size(), elem_size)); } - void PushFlatBuffer(const uint8_t *bytes, size_t size) { + void PushFlatBuffer(const uint8_t* bytes, size_t size) { PushBytes(bytes, size); finished = true; } - void PushBytes(const uint8_t *bytes, size_t size) { buf_.push(bytes, size); } + void PushBytes(const uint8_t* bytes, size_t size) { buf_.push(bytes, size); } void PopBytes(size_t amount) { buf_.pop(amount); } - template void AssertScalarT() { + template + void AssertScalarT() { // The code assumes power of 2 sizes and endian-swap-ability. static_assert(flatbuffers::is_scalar::value, "T must be a scalar type"); } // Write a single aligned scalar to the buffer - template + template ReturnT PushElement(T element) { AssertScalarT(); Align(sizeof(T)); @@ -318,7 +316,7 @@ template class FlatBufferBuilderImpl { return CalculateOffset(); } - template class OffsetT = Offset> + template class OffsetT = Offset> uoffset_t PushElement(OffsetT off) { // Special case for offsets: see ReferTo below. return PushElement(ReferTo(off.o)); @@ -327,34 +325,41 @@ template class FlatBufferBuilderImpl { // When writing fields, we track where they are, so we can create correct // vtables later. void TrackField(voffset_t field, uoffset_t off) { - FieldLoc fl = { off, field }; + FieldLoc fl = {off, field}; buf_.scratch_push_small(fl); num_field_loc++; - if (field > max_voffset_) { max_voffset_ = field; } + if (field > max_voffset_) { + max_voffset_ = field; + } } // Like PushElement, but additionally tracks the field this represents. - template void AddElement(voffset_t field, T e, T def) { + template + void AddElement(voffset_t field, T e, T def) { // We don't serialize values equal to the default. if (IsTheSameAs(e, def) && !force_defaults_) return; TrackField(field, PushElement(e)); } - template void AddElement(voffset_t field, T e) { + template + void AddElement(voffset_t field, T e) { TrackField(field, PushElement(e)); } - template void AddOffset(voffset_t field, Offset off) { + template + void AddOffset(voffset_t field, Offset off) { if (off.IsNull()) return; // Don't store. AddElement(field, ReferTo(off.o), static_cast(0)); } - template void AddOffset(voffset_t field, Offset64 off) { + template + void AddOffset(voffset_t field, Offset64 off) { if (off.IsNull()) return; // Don't store. AddElement(field, ReferTo(off.o), static_cast(0)); } - template void AddStruct(voffset_t field, const T *structptr) { + template + void AddStruct(voffset_t field, const T* structptr) { if (!structptr) return; // Default, don't store. Align(AlignOf()); buf_.push_small(*structptr); @@ -384,12 +389,14 @@ template class FlatBufferBuilderImpl { return ReferTo(off, GetSize()); } - template T ReferTo(const T off, const T2 size) { + template + T ReferTo(const T off, const T2 size) { FLATBUFFERS_ASSERT(off && off <= size); return size - off + static_cast(sizeof(T)); } - template T ReferTo(const T off, const T size) { + template + T ReferTo(const T off, const T size) { FLATBUFFERS_ASSERT(off && off <= size); return size - off + static_cast(sizeof(T)); } @@ -445,7 +452,7 @@ template class FlatBufferBuilderImpl { // Write the offsets into the table for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc); it < buf_.scratch_end(); it += sizeof(FieldLoc)) { - auto field_location = reinterpret_cast(it); + auto field_location = reinterpret_cast(it); const voffset_t pos = static_cast(vtable_offset_loc - field_location->off); // If this asserts, it means you've set a field twice. @@ -454,7 +461,7 @@ template class FlatBufferBuilderImpl { WriteScalar(buf_.data() + field_location->id, pos); } ClearOffsets(); - auto vt1 = reinterpret_cast(buf_.data()); + auto vt1 = reinterpret_cast(buf_.data()); auto vt1_size = ReadScalar(vt1); auto vt_use = GetSizeRelative32BitRegion(); // See if we already have generated a vtable with this exact same @@ -462,8 +469,8 @@ template class FlatBufferBuilderImpl { if (dedup_vtables_) { for (auto it = buf_.scratch_data(); it < buf_.scratch_end(); it += sizeof(uoffset_t)) { - auto vt_offset_ptr = reinterpret_cast(it); - auto vt2 = reinterpret_cast(buf_.data_at(*vt_offset_ptr)); + auto vt_offset_ptr = reinterpret_cast(it); + auto vt2 = reinterpret_cast(buf_.data_at(*vt_offset_ptr)); auto vt2_size = ReadScalar(vt2); if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue; vt_use = *vt_offset_ptr; @@ -494,8 +501,9 @@ template class FlatBufferBuilderImpl { // This checks a required field has been set in a given table that has // just been constructed. - template void Required(Offset table, voffset_t field) { - auto table_ptr = reinterpret_cast(buf_.data_at(table.o)); + template + void Required(Offset table, voffset_t field) { + auto table_ptr = reinterpret_cast(buf_.data_at(table.o)); bool ok = table_ptr->GetOptionalFieldOffset(field) != 0; // If this fails, the caller will show what field needs to be set. FLATBUFFERS_ASSERT(ok); @@ -525,7 +533,8 @@ template class FlatBufferBuilderImpl { // Aligns such than when "len" bytes are written, an object of type `AlignT` // can be written after it (forward in the buffer) without padding. - template void PreAlign(size_t len) { + template + void PreAlign(size_t len) { AssertScalarT(); PreAlign(len, AlignOf()); } @@ -535,8 +544,8 @@ template class FlatBufferBuilderImpl { /// @param[in] str A const char pointer to the data to be stored as a string. /// @param[in] len The number of bytes that should be stored from `str`. /// @return Returns the offset in the buffer where the string starts. - template class OffsetT = Offset> - OffsetT CreateString(const char *str, size_t len) { + template