This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new 68301745 fix: Align flatbuffer test data stored as globals (#783)
68301745 is described below
commit 68301745eefcdc0dd5187c0fd8cf5ee4f094d1b0
Author: Dewey Dunnington <[email protected]>
AuthorDate: Fri Jun 13 07:13:58 2025 -0500
fix: Align flatbuffer test data stored as globals (#783)
Closes #771, in which flatbuffer verification was failing because of
invalid alignment. The global variables with this data just happened to
be 8-byte aligned on every other platform but it makes sense that on a
32-bit platform there's no reason for this to be the case.
---
src/nanoarrow/device/device_test.cc | 8 ++++++--
src/nanoarrow/ipc/decoder_test.cc | 12 +++++++-----
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/nanoarrow/device/device_test.cc
b/src/nanoarrow/device/device_test.cc
index a303bf34..1a8ad98c 100644
--- a/src/nanoarrow/device/device_test.cc
+++ b/src/nanoarrow/device/device_test.cc
@@ -45,7 +45,9 @@ TEST(NanoarrowDevice, ArrowDeviceCpuBuffer) {
struct ArrowDevice* cpu = ArrowDeviceCpu();
struct ArrowBuffer buffer;
uint8_t data[] = {0x01, 0x02, 0x03, 0x04, 0x05};
- struct ArrowBufferView view = {data, sizeof(data)};
+ struct ArrowBufferView view;
+ view.data.as_uint8 = data;
+ view.size_bytes = sizeof(data);
ASSERT_EQ(ArrowDeviceBufferInit(cpu, view, cpu, &buffer), NANOARROW_OK);
EXPECT_EQ(buffer.size_bytes, 5);
@@ -58,7 +60,9 @@ TEST(NanoarrowDevice, ArrowDeviceCpuBuffer) {
EXPECT_EQ(buffer.data, nullptr);
uint8_t dest[5];
- struct ArrowBufferView dest_view = {dest, sizeof(dest)};
+ struct ArrowBufferView dest_view;
+ dest_view.data.as_uint8 = dest;
+ dest_view.size_bytes = sizeof(dest);
ASSERT_EQ(ArrowDeviceBufferCopy(cpu, view, cpu, dest_view), NANOARROW_OK);
EXPECT_EQ(memcmp(dest, view.data.data, sizeof(data)), 0);
diff --git a/src/nanoarrow/ipc/decoder_test.cc
b/src/nanoarrow/ipc/decoder_test.cc
index 04d8846c..058d9fb1 100644
--- a/src/nanoarrow/ipc/decoder_test.cc
+++ b/src/nanoarrow/ipc/decoder_test.cc
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+#include <cstring>
#include <thread>
#if defined(NANOARROW_BUILD_TESTS_WITH_ARROW)
@@ -71,7 +72,7 @@ TEST(NanoarrowIpcCheckRuntime, CheckRuntime) {
// schema <- arrow::schema(field)
// schema$metadata <- list("some_key" = "some_value")
// schema$serialize()
-static uint8_t kSimpleSchema[] = {
+alignas(8) static uint8_t kSimpleSchema[] = {
0xff, 0xff, 0xff, 0xff, 0x10, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00,
0x0a, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x00, 0x0a, 0x00,
0x00, 0x00,
0x00, 0x01, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
0x0c, 0x00,
@@ -93,7 +94,7 @@ static uint8_t kSimpleSchema[] = {
0x6c, 0x64, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x07, 0x00,
0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00};
-static uint8_t kSimpleRecordBatch[] = {
+alignas(8) static uint8_t kSimpleRecordBatch[] = {
0xff, 0xff, 0xff, 0xff, 0x88, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x0c, 0x00, 0x16, 0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x00,
0x0c, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00,
0x10, 0x00,
@@ -107,7 +108,7 @@ static uint8_t kSimpleRecordBatch[] = {
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-static uint8_t kSimpleRecordBatchCompressed[] = {
+alignas(8) static uint8_t kSimpleRecordBatchCompressed[] = {
0xff, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x00,
0x0c, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x20, 0x00,
@@ -124,7 +125,7 @@ static uint8_t kSimpleRecordBatchCompressed[] = {
0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
-static uint8_t kSimpleRecordBatchUncompressible[] = {
+alignas(8) static uint8_t kSimpleRecordBatchUncompressible[] = {
0xff, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x00,
0x0c, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x20, 0x00,
@@ -284,7 +285,8 @@ TEST(NanoarrowIpcTest, NanoarrowIpcVerifySimpleRecordBatch)
{
data.size_bytes = sizeof(kSimpleRecordBatch);
ArrowIpcDecoderInit(&decoder);
- EXPECT_EQ(ArrowIpcDecoderVerifyHeader(&decoder, data, &error), NANOARROW_OK);
+ ASSERT_EQ(ArrowIpcDecoderVerifyHeader(&decoder, data, &error), NANOARROW_OK)
+ << error.message;
EXPECT_EQ(decoder.message_type, NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH);
EXPECT_EQ(decoder.header_size_bytes,
sizeof(kSimpleRecordBatch) - decoder.body_size_bytes);