Compare commits

..
Author SHA1 Message Date
Derek Bailey 3f4f0497ea Regenerate monster_test_bfbs_generated.h with alignas(uint64_t)
Commit 6dda43bb (#9425) added `alignas(uint64_t)` to embedded binary schemas
generated by `flatc --bfbs-gen-embed`. Regenerate `tests/monster_test_bfbs_generated.h`
via `scripts/generate_code.py` to keep checked-in test artifacts in sync and
unblock CI Check Generated Code.

GitOrigin-RevId: 3786479bebd33365edc91aa13388cdf95d7313d9
2026-10-26 15:34:03 +00:00
Derek Bailey 6dda43bbaa Ensure embedded FlatBuffers binary schemas are 8-byte aligned (#9425)
In `src/idl_gen_cpp.cpp`, code generated by `flatc --bfbs-gen-embed` emits `static const uint8_t bfbsData[...] = { ... };`. Because `uint8_t` has 1-byte alignment, the array may be placed at an unaligned address in `.rodata`, triggering alignment traps under Clang UBSan on Arm when accessed via FlatBuffers root accessors.

Add `alignas(uint64_t)` to the generated `bfbsData` array declaration in `GenerateBinarySchema` so embedded binary schemas are 8-byte aligned across all architectures.

PiperOrigin-RevId: 1003962636
2026-10-21 13:37:51 -07:00
Derek Bailey 9a8a511b52 Enable locale-independent strtod_l/strtof_l on Linux glibc (#9424)
Restrict the `__linux__` check for `FLATBUFFERS_LOCALE_INDEPENDENT` in `include/flatbuffers/base.h` to `(!defined(__linux__) || defined(__GLIBC__))` so Linux with glibc enables `strtod_l`/`strtof_l`.

PiperOrigin-RevId: 1002266254
2026-10-21 13:25:17 -07:00
Wouter van Oortmerssen b8431fbcd7 Lobster: change builder size constants (enum -> let)
This is because newer versions of the Lobster compiler reject enums with the same values, and older compilers are fine with the let versions also.
2026-09-14 11:02:13 -07:00
4 changed files with 11 additions and 12 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ namespace flatbuffers {
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || \ #if (defined(_MSC_VER) && _MSC_VER >= 1800) || \
(defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__>= 26) || \ (defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__>= 26) || \
(defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700)) && \ (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700)) && \
!defined(__Fuchsia__) !defined(__Fuchsia__) && (!defined(__linux__) || defined(__GLIBC__))
#define FLATBUFFERS_LOCALE_INDEPENDENT 1 #define FLATBUFFERS_LOCALE_INDEPENDENT 1
#else #else
#define FLATBUFFERS_LOCALE_INDEPENDENT 0 #define FLATBUFFERS_LOCALE_INDEPENDENT 0
+8 -9
View File
@@ -24,15 +24,14 @@ class handle:
struct offset: struct offset:
o:int o:int
enum sizeof: let sz_8 = 1
sz_8 = 1 let sz_16 = 2
sz_16 = 2 let sz_32 = 4
sz_32 = 4 let sz_64 = 8
sz_64 = 8 let sz_voffset = 2
sz_voffset = 2 let sz_uoffset = 4
sz_uoffset = 4 let sz_soffset = 4
sz_soffset = 4 let sz_metadata_fields = 2
sz_metadata_fields = 2
class builder: class builder:
buf = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" buf = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+1 -1
View File
@@ -404,7 +404,7 @@ class CppGenerator : public BaseGenerator {
code_ += "struct {{STRUCT_NAME}}BinarySchema {"; code_ += "struct {{STRUCT_NAME}}BinarySchema {";
code_ += " static const uint8_t *data() {"; code_ += " static const uint8_t *data() {";
code_ += " // Buffer containing the binary schema."; code_ += " // Buffer containing the binary schema.";
code_ += " static const uint8_t bfbsData[" + code_ += " alignas(uint64_t) static const uint8_t bfbsData[" +
NumToString(parser_.builder_.GetSize()) + "] = {"; NumToString(parser_.builder_.GetSize()) + "] = {";
code_ += binary_schema_hex_text; code_ += binary_schema_hex_text;
code_ += " };"; code_ += " };";
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Example {
struct MonsterBinarySchema { struct MonsterBinarySchema {
static const uint8_t *data() { static const uint8_t *data() {
// Buffer containing the binary schema. // Buffer containing the binary schema.
static const uint8_t bfbsData[14520] = { alignas(uint64_t) static const uint8_t bfbsData[14520] = {
0x20,0x00,0x00,0x00,0x42,0x46,0x42,0x53,0x00,0x00,0x00,0x00,0x14,0x00,0x20,0x00,0x04,0x00,0x08,0x00, 0x20,0x00,0x00,0x00,0x42,0x46,0x42,0x53,0x00,0x00,0x00,0x00,0x14,0x00,0x20,0x00,0x04,0x00,0x08,0x00,
0x0C,0x00,0x10,0x00,0x14,0x00,0x18,0x00,0x00,0x00,0x1C,0x00,0x14,0x00,0x00,0x00,0x58,0x00,0x00,0x00, 0x0C,0x00,0x10,0x00,0x14,0x00,0x18,0x00,0x00,0x00,0x1C,0x00,0x14,0x00,0x00,0x00,0x58,0x00,0x00,0x00,
0x34,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x70,0x0D,0x00,0x00,0x08,0x00,0x00,0x00, 0x34,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x70,0x0D,0x00,0x00,0x08,0x00,0x00,0x00,