Skip to content

Commit f11e22d

Browse files
committed
Update FlatBuffers to 23.5.26
1 parent aa59bd0 commit f11e22d

28 files changed

+1489
-860
lines changed

external/flatbuffers/allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ class Allocator {
6565

6666
} // namespace flatbuffers
6767

68-
#endif // FLATBUFFERS_ALLOCATOR_H_
68+
#endif // FLATBUFFERS_ALLOCATOR_H_

external/flatbuffers/array.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#ifndef FLATBUFFERS_ARRAY_H_
1818
#define FLATBUFFERS_ARRAY_H_
1919

20+
#include <cstdint>
21+
#include <memory>
22+
2023
#include "flatbuffers/base.h"
2124
#include "flatbuffers/stl_emulation.h"
2225
#include "flatbuffers/vector.h"
@@ -35,7 +38,7 @@ template<typename T, uint16_t length> class Array {
3538
public:
3639
typedef uint16_t size_type;
3740
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
38-
typedef VectorIterator<T, return_type> const_iterator;
41+
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
3942
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
4043

4144
// If T is a LE-scalar or a struct (!scalar_tag::value).
@@ -156,11 +159,13 @@ template<typename T, uint16_t length> class Array {
156159

157160
// Specialization for Array[struct] with access using Offset<void> pointer.
158161
// This specialization used by idl_gen_text.cpp.
159-
template<typename T, uint16_t length> class Array<Offset<T>, length> {
162+
template<typename T, uint16_t length, template<typename> class OffsetT>
163+
class Array<OffsetT<T>, length> {
160164
static_assert(flatbuffers::is_same<T, void>::value, "unexpected type T");
161165

162166
public:
163167
typedef const void *return_type;
168+
typedef uint16_t size_type;
164169

165170
const uint8_t *Data() const { return data_; }
166171

@@ -238,6 +243,14 @@ const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) {
238243
return *reinterpret_cast<const Array<E, length> *>(arr);
239244
}
240245

246+
template<typename T, uint16_t length>
247+
bool operator==(const Array<T, length> &lhs,
248+
const Array<T, length> &rhs) noexcept {
249+
return std::addressof(lhs) == std::addressof(rhs) ||
250+
(lhs.size() == rhs.size() &&
251+
std::memcmp(lhs.Data(), rhs.Data(), rhs.size() * sizeof(T)) == 0);
252+
}
253+
241254
} // namespace flatbuffers
242255

243256
#endif // FLATBUFFERS_ARRAY_H_

external/flatbuffers/base.h

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <cstdlib>
3333
#include <cstring>
3434

35-
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
35+
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) && defined(__AVR__)
3636
#include <utility.h>
3737
#else
3838
#include <utility>
@@ -43,6 +43,7 @@
4343
#include <vector>
4444
#include <set>
4545
#include <algorithm>
46+
#include <limits>
4647
#include <iterator>
4748
#include <memory>
4849

@@ -138,9 +139,9 @@
138139
#endif
139140
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
140141

141-
#define FLATBUFFERS_VERSION_MAJOR 2
142-
#define FLATBUFFERS_VERSION_MINOR 0
143-
#define FLATBUFFERS_VERSION_REVISION 8
142+
#define FLATBUFFERS_VERSION_MAJOR 23
143+
#define FLATBUFFERS_VERSION_MINOR 5
144+
#define FLATBUFFERS_VERSION_REVISION 26
144145
#define FLATBUFFERS_STRING_EXPAND(X) #X
145146
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
146147
namespace flatbuffers {
@@ -233,12 +234,17 @@ namespace flatbuffers {
233234
}
234235
#define FLATBUFFERS_HAS_STRING_VIEW 1
235236
// Check for absl::string_view
236-
#elif __has_include("absl/strings/string_view.h")
237-
#include "absl/strings/string_view.h"
238-
namespace flatbuffers {
239-
typedef absl::string_view string_view;
240-
}
241-
#define FLATBUFFERS_HAS_STRING_VIEW 1
237+
#elif __has_include("absl/strings/string_view.h") && \
238+
__has_include("absl/base/config.h") && \
239+
(__cplusplus >= 201411)
240+
#include "absl/base/config.h"
241+
#if !defined(ABSL_USES_STD_STRING_VIEW)
242+
#include "absl/strings/string_view.h"
243+
namespace flatbuffers {
244+
typedef absl::string_view string_view;
245+
}
246+
#define FLATBUFFERS_HAS_STRING_VIEW 1
247+
#endif
242248
#endif
243249
#endif // __has_include
244250
#endif // !FLATBUFFERS_HAS_STRING_VIEW
@@ -273,14 +279,14 @@ namespace flatbuffers {
273279
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
274280

275281
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
276-
// - __suppress_ubsan__("undefined")
277-
// - __suppress_ubsan__("signed-integer-overflow")
282+
// - FLATBUFFERS_SUPPRESS_UBSAN("undefined")
283+
// - FLATBUFFERS_SUPPRESS_UBSAN("signed-integer-overflow")
278284
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
279-
#define __suppress_ubsan__(type) __attribute__((no_sanitize(type)))
285+
#define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize(type)))
280286
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
281-
#define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined))
287+
#define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize_undefined))
282288
#else
283-
#define __suppress_ubsan__(type)
289+
#define FLATBUFFERS_SUPPRESS_UBSAN(type)
284290
#endif
285291

286292
// This is constexpr function used for checking compile-time constants.
@@ -318,9 +324,11 @@ namespace flatbuffers {
318324
// Also, using a consistent offset type maintains compatibility of serialized
319325
// offset values between 32bit and 64bit systems.
320326
typedef uint32_t uoffset_t;
327+
typedef uint64_t uoffset64_t;
321328

322329
// Signed offsets for references that can go in both directions.
323330
typedef int32_t soffset_t;
331+
typedef int64_t soffset64_t;
324332

325333
// Offset/index used in v-tables, can be changed to uint8_t in
326334
// format forks to save a bit of space if desired.
@@ -329,7 +337,8 @@ typedef uint16_t voffset_t;
329337
typedef uintmax_t largest_scalar_t;
330338

331339
// In 32bits, this evaluates to 2GB - 1
332-
#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1)
340+
#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max()
341+
#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max()
333342

334343
// The minimum size buffer that can be a valid flatbuffer.
335344
// Includes the offset to the root table (uoffset_t), the offset to the vtable
@@ -413,7 +422,7 @@ template<typename T> T EndianScalar(T t) {
413422

414423
template<typename T>
415424
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
416-
__suppress_ubsan__("alignment")
425+
FLATBUFFERS_SUPPRESS_UBSAN("alignment")
417426
T ReadScalar(const void *p) {
418427
return EndianScalar(*reinterpret_cast<const T *>(p));
419428
}
@@ -427,13 +436,13 @@ T ReadScalar(const void *p) {
427436

428437
template<typename T>
429438
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
430-
__suppress_ubsan__("alignment")
439+
FLATBUFFERS_SUPPRESS_UBSAN("alignment")
431440
void WriteScalar(void *p, T t) {
432441
*reinterpret_cast<T *>(p) = EndianScalar(t);
433442
}
434443

435444
template<typename T> struct Offset;
436-
template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
445+
template<typename T> FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, Offset<T> t) {
437446
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
438447
}
439448

@@ -444,7 +453,7 @@ template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, O
444453
// Computes how many bytes you'd have to pad to be able to write an
445454
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
446455
// memory).
447-
__suppress_ubsan__("unsigned-integer-overflow")
456+
FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow")
448457
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
449458
return ((~buf_size) + 1) & (scalar_size - 1);
450459
}

external/flatbuffers/buffer.h

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,41 @@
1717
#ifndef FLATBUFFERS_BUFFER_H_
1818
#define FLATBUFFERS_BUFFER_H_
1919

20+
#include <algorithm>
21+
2022
#include "flatbuffers/base.h"
2123

2224
namespace flatbuffers {
2325

2426
// Wrapper for uoffset_t to allow safe template specialization.
2527
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
26-
template<typename T> struct Offset {
27-
uoffset_t o;
28+
template<typename T = void> struct Offset {
29+
// The type of offset to use.
30+
typedef uoffset_t offset_type;
31+
32+
offset_type o;
2833
Offset() : o(0) {}
29-
Offset(uoffset_t _o) : o(_o) {}
30-
Offset<void> Union() const { return Offset<void>(o); }
34+
Offset(const offset_type _o) : o(_o) {}
35+
Offset<> Union() const { return o; }
3136
bool IsNull() const { return !o; }
3237
};
3338

39+
// Wrapper for uoffset64_t Offsets.
40+
template<typename T = void> struct Offset64 {
41+
// The type of offset to use.
42+
typedef uoffset64_t offset_type;
43+
44+
offset_type o;
45+
Offset64() : o(0) {}
46+
Offset64(const offset_type offset) : o(offset) {}
47+
Offset64<> Union() const { return o; }
48+
bool IsNull() const { return !o; }
49+
};
50+
51+
// Litmus check for ensuring the Offsets are the expected size.
52+
static_assert(sizeof(Offset<>) == 4, "Offset has wrong size");
53+
static_assert(sizeof(Offset64<>) == 8, "Offset64 has wrong size");
54+
3455
inline void EndianCheck() {
3556
int endiantest = 1;
3657
// If this fails, see FLATBUFFERS_LITTLEENDIAN above.
@@ -73,25 +94,59 @@ template<typename T> struct IndirectHelper {
7394
typedef T return_type;
7495
typedef T mutable_return_type;
7596
static const size_t element_stride = sizeof(T);
76-
static return_type Read(const uint8_t *p, uoffset_t i) {
97+
98+
static return_type Read(const uint8_t *p, const size_t i) {
7799
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
78100
}
101+
static mutable_return_type Read(uint8_t *p, const size_t i) {
102+
return reinterpret_cast<mutable_return_type>(
103+
Read(const_cast<const uint8_t *>(p), i));
104+
}
79105
};
80-
template<typename T> struct IndirectHelper<Offset<T>> {
106+
107+
// For vector of Offsets.
108+
template<typename T, template<typename> class OffsetT>
109+
struct IndirectHelper<OffsetT<T>> {
81110
typedef const T *return_type;
82111
typedef T *mutable_return_type;
83-
static const size_t element_stride = sizeof(uoffset_t);
84-
static return_type Read(const uint8_t *p, uoffset_t i) {
85-
p += i * sizeof(uoffset_t);
86-
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
112+
typedef typename OffsetT<T>::offset_type offset_type;
113+
static const offset_type element_stride = sizeof(offset_type);
114+
115+
static return_type Read(const uint8_t *const p, const offset_type i) {
116+
// Offsets are relative to themselves, so first update the pointer to
117+
// point to the offset location.
118+
const uint8_t *const offset_location = p + i * element_stride;
119+
120+
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
121+
// then determine the relative location from the offset location.
122+
return reinterpret_cast<return_type>(
123+
offset_location + ReadScalar<offset_type>(offset_location));
124+
}
125+
static mutable_return_type Read(uint8_t *const p, const offset_type i) {
126+
// Offsets are relative to themselves, so first update the pointer to
127+
// point to the offset location.
128+
uint8_t *const offset_location = p + i * element_stride;
129+
130+
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
131+
// then determine the relative location from the offset location.
132+
return reinterpret_cast<mutable_return_type>(
133+
offset_location + ReadScalar<offset_type>(offset_location));
87134
}
88135
};
136+
137+
// For vector of structs.
89138
template<typename T> struct IndirectHelper<const T *> {
90139
typedef const T *return_type;
91140
typedef T *mutable_return_type;
92141
static const size_t element_stride = sizeof(T);
93-
static return_type Read(const uint8_t *p, uoffset_t i) {
94-
return reinterpret_cast<const T *>(p + i * sizeof(T));
142+
143+
static return_type Read(const uint8_t *const p, const size_t i) {
144+
// Structs are stored inline, relative to the first struct pointer.
145+
return reinterpret_cast<return_type>(p + i * element_stride);
146+
}
147+
static mutable_return_type Read(uint8_t *const p, const size_t i) {
148+
// Structs are stored inline, relative to the first struct pointer.
149+
return reinterpret_cast<mutable_return_type>(p + i * element_stride);
95150
}
96151
};
97152

@@ -118,25 +173,27 @@ inline bool BufferHasIdentifier(const void *buf, const char *identifier,
118173
/// @cond FLATBUFFERS_INTERNAL
119174
// Helpers to get a typed pointer to the root object contained in the buffer.
120175
template<typename T> T *GetMutableRoot(void *buf) {
176+
if (!buf) return nullptr;
121177
EndianCheck();
122178
return reinterpret_cast<T *>(
123179
reinterpret_cast<uint8_t *>(buf) +
124180
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
125181
}
126182

127-
template<typename T> T *GetMutableSizePrefixedRoot(void *buf) {
128-
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) +
129-
sizeof(uoffset_t));
183+
template<typename T, typename SizeT = uoffset_t>
184+
T *GetMutableSizePrefixedRoot(void *buf) {
185+
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) + sizeof(SizeT));
130186
}
131187

132188
template<typename T> const T *GetRoot(const void *buf) {
133189
return GetMutableRoot<T>(const_cast<void *>(buf));
134190
}
135191

136-
template<typename T> const T *GetSizePrefixedRoot(const void *buf) {
137-
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(uoffset_t));
192+
template<typename T, typename SizeT = uoffset_t>
193+
const T *GetSizePrefixedRoot(const void *buf) {
194+
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(SizeT));
138195
}
139196

140197
} // namespace flatbuffers
141198

142-
#endif // FLATBUFFERS_BUFFER_H_
199+
#endif // FLATBUFFERS_BUFFER_H_

external/flatbuffers/buffer_ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ template<typename T> struct BufferRef : BufferRefBase {
5050

5151
} // namespace flatbuffers
5252

53-
#endif // FLATBUFFERS_BUFFER_REF_H_
53+
#endif // FLATBUFFERS_BUFFER_REF_H_

0 commit comments

Comments
 (0)