From 8b19902c5133a422728c3be10acaef8a3ec91213 Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Fri, 25 Oct 2024 11:57:51 -0500 Subject: [PATCH] add assertions that struct alignment is correct --- arrow-ipc/regen.sh | 20 ++++++++++++++++++++ arrow-ipc/src/gen/File.rs | 12 ++++++++++++ arrow-ipc/src/gen/Message.rs | 12 ++++++++++++ arrow-ipc/src/gen/Schema.rs | 12 ++++++++++++ 4 files changed, 56 insertions(+) diff --git a/arrow-ipc/regen.sh b/arrow-ipc/regen.sh index d828e1027380..e3840d924a0e 100755 --- a/arrow-ipc/regen.sh +++ b/arrow-ipc/regen.sh @@ -144,6 +144,26 @@ for f in `ls *.rs`; do fi done +# Since $FLATC might be unpatched, add assertions that we have correct struct alignment +function add_struct_alignment_test { +>>"$1" cat <<'HEREDOC' +#[cfg(test)] +mod tests { + use super::*; + use flatbuffers::Push; + + #[test] + fn struct_alignment() { + // https://github.com/google/flatbuffers/pull/8398 + assert_eq!($2::alignment(), PushAlignment::new(8)); + } +} +HEREDOC +} +add_struct_alignment_test Schema.rs Buffer +add_struct_alignment_test Message.rs FieldNode +add_struct_alignment_test File.rs Block + # Return back to base directory popd cargo +stable fmt -- src/gen/* diff --git a/arrow-ipc/src/gen/File.rs b/arrow-ipc/src/gen/File.rs index 0895a878bcae..9365e6536bee 100644 --- a/arrow-ipc/src/gen/File.rs +++ b/arrow-ipc/src/gen/File.rs @@ -494,3 +494,15 @@ pub fn finish_size_prefixed_footer_buffer<'a, 'b, A: flatbuffers::Allocator + 'a ) { fbb.finish_size_prefixed(root, None); } + +#[cfg(test)] +mod tests { + use super::*; + use flatbuffers::Push; + + #[test] + fn struct_alignment() { + // https://github.com/google/flatbuffers/pull/8398 + assert_eq!(Block::alignment(), PushAlignment::new(8)); + } +} diff --git a/arrow-ipc/src/gen/Message.rs b/arrow-ipc/src/gen/Message.rs index 81d22c810ab3..54f6a5960d7c 100644 --- a/arrow-ipc/src/gen/Message.rs +++ b/arrow-ipc/src/gen/Message.rs @@ -1498,3 +1498,15 @@ pub fn finish_size_prefixed_message_buffer<'a, 'b, A: flatbuffers::Allocator + ' ) { fbb.finish_size_prefixed(root, None); } + +#[cfg(test)] +mod tests { + use super::*; + use flatbuffers::Push; + + #[test] + fn struct_alignment() { + // https://github.com/google/flatbuffers/pull/8398 + assert_eq!(FieldNode::alignment(), PushAlignment::new(8)); + } +} diff --git a/arrow-ipc/src/gen/Schema.rs b/arrow-ipc/src/gen/Schema.rs index 9ceefca5c5b3..8625268d57ff 100644 --- a/arrow-ipc/src/gen/Schema.rs +++ b/arrow-ipc/src/gen/Schema.rs @@ -5602,3 +5602,15 @@ pub fn finish_size_prefixed_schema_buffer<'a, 'b, A: flatbuffers::Allocator + 'a ) { fbb.finish_size_prefixed(root, None); } + +#[cfg(test)] +mod tests { + use super::*; + use flatbuffers::Push; + + #[test] + fn struct_alignment() { + // https://github.com/google/flatbuffers/pull/8398 + assert_eq!(Buffer::alignment(), PushAlignment::new(8)); + } +}