| diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h |
| index a5ac10d..371b6fd 100644 |
| --- a/include/flatbuffers/base.h |
| +++ b/include/flatbuffers/base.h |
| @@ -1,6 +1,16 @@ |
| #ifndef FLATBUFFERS_BASE_H_ |
| #define FLATBUFFERS_BASE_H_ |
| |
| +// For TFLM, we always want FLATBUFFERS_LOCALE_INDEPENDENT to be defined as 0. |
| +// We could achieve this by adding -DFLATBUFFERS_LOCALE_INDEPENDENT=0 to the |
| +// TFLM Makefile. However, for (at least) the Arduino, adding additional build |
| +// flags during the compilation can be a bit awkward. As such, we have instead |
| +// made a decision to change the default to be FLATBUFFERS_LOCALE_INDEPENDENT=0 |
| +// for TFLM to make it easier for external IDE integration. |
| +#ifndef FLATBUFFERS_LOCALE_INDEPENDENT |
| +#define FLATBUFFERS_LOCALE_INDEPENDENT 0 |
| +#endif |
| + |
| // clang-format off |
| |
| // If activate should be declared and included first. |
| diff --git a/include/flatbuffers/default_allocator.h b/include/flatbuffers/default_allocator.h |
| index 8b173af..975d938 100644 |
| --- a/include/flatbuffers/default_allocator.h |
| +++ b/include/flatbuffers/default_allocator.h |
| @@ -39,26 +39,20 @@ class DefaultAllocator : public Allocator { |
| // 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) { |
| - return allocator ? allocator->allocate(size) |
| - : DefaultAllocator().allocate(size); |
| + return allocator->allocate(size); |
| } |
| |
| inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) { |
| - if (allocator) |
| - allocator->deallocate(p, size); |
| - else |
| - DefaultAllocator().deallocate(p, size); |
| + allocator->deallocate(p, size); |
| } |
| |
| 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, |
| - in_use_back, in_use_front) |
| - : DefaultAllocator().reallocate_downward( |
| - old_p, old_size, new_size, in_use_back, in_use_front); |
| + return allocator->reallocate_downward(old_p, old_size, new_size, in_use_back, |
| + in_use_front); |
| } |
| |
| } // namespace flatbuffers |
| |
| -#endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_ |
| \ No newline at end of file |
| +#endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_ |
| diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h |
| index 89f3f30..6e6d0b3 100644 |
| --- a/include/flatbuffers/flexbuffers.h |
| +++ b/include/flatbuffers/flexbuffers.h |
| @@ -496,9 +496,24 @@ class Reference { |
| return static_cast<double>(ReadUInt64(Indirect(), byte_width_)); |
| case FBT_NULL: return 0.0; |
| case FBT_STRING: { |
| +#if 1 |
| +#if !defined( _MSC_VER) |
| +#pragma GCC diagnostic push |
| +#pragma GCC diagnostic ignored "-Wnull-dereference" |
| +#endif |
| + // See b/173239141 for additional context. Patched via |
| + // micro/tools/make/flexbuffers_download.sh |
| + // Introduce a segfault for an unsupported code path for TFLM. |
| + return *(static_cast<double*>(nullptr)); |
| +#if !defined( _MSC_VER) |
| +#pragma GCC diagnostic pop |
| +#endif |
| +#else |
| + // This is the original code |
| double d; |
| flatbuffers::StringToNumber(AsString().c_str(), &d); |
| return d; |
| +#endif |
| } |
| case FBT_VECTOR: return static_cast<double>(AsVector().size()); |
| case FBT_BOOL: |
| diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h |
| index 93a39de..1cd4e8f 100644 |
| --- a/include/flatbuffers/util.h |
| +++ b/include/flatbuffers/util.h |
| @@ -24,6 +24,12 @@ |
| #include "flatbuffers/base.h" |
| #include "flatbuffers/stl_emulation.h" |
| |
| +// For TFLM we always want to use FLATBUFFERS_PREFER_PRINTF=1. See |
| +// http://b/211811553 for more context. |
| +#ifndef FLATBUFFERS_PREFER_PRINTF |
| +#define FLATBUFFERS_PREFER_PRINTF 1 |
| +#endif |
| + |
| #ifndef FLATBUFFERS_PREFER_PRINTF |
| # include <iomanip> |
| # include <sstream> |
| |