Created
August 14, 2024 15:22
-
-
Save bkietz/6150b9aae6d1bea0c85c0527d7fb04d6 to your computer and use it in GitHub Desktop.
flatcc requires even empty vectors are aligned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include "nanoarrow/ipc/flatcc_generated.h" | |
static const char dump[] = { | |
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, | |
0x0e, 0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, | |
0x00, 0x03, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, | |
0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, | |
0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
}; | |
int main() { | |
#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(org_apache_arrow_flatbuf, x) | |
// assert(ns(Message_verify_as_root(dump, sizeof(dump))) == flatcc_verify_ok); | |
ns(Message_table_t) message = ns(Message_as_root(dump)); | |
assert(ns(Message_header_type(message)) == ns(MessageHeader_RecordBatch)); | |
ns(RecordBatch_table_t) record_batch = | |
(ns(RecordBatch_table_t))ns(Message_header_get(message)); | |
ns(Buffer_vec_t) buffers = ns(RecordBatch_buffers_get(record_batch)); | |
assert(ns(Buffer_vec_len(buffers)) == 0); | |
static_assert(alignof(ns(Buffer_t)) == 8, ""); | |
int offset = (const char *)buffers - dump; | |
// assert(offset % 8 == 0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.14) | |
project(flatcc_repro) | |
include(FetchContent) | |
include(ExternalProject) | |
# fetch flatcc v0.6.1 | |
FetchContent_Declare( | |
flatcc | |
GIT_REPOSITORY https://github.com/dvidelabs/flatcc.git | |
GIT_TAG v0.6.1 | |
PATCH_COMMAND | |
# Minor patch to get include dirs right for the flatccrt target | |
git reset --hard HEAD && git apply "${CMAKE_SOURCE_DIR}/flatcc.patch" | |
) | |
option(FLATCC_RTONLY "enable build of runtime library only" ON) | |
option(FLATCC_INSTALL "enable install targets" ON) | |
FetchContent_MakeAvailable(flatcc) | |
add_executable(repro Asserts.c) | |
target_link_libraries(repro PRIVATE flatccrt) | |
# fetch flatcc_generated.h | |
ExternalProject_Add( | |
nanoarrow | |
GIT_REPOSITORY https://github.com/apache/arrow-nanoarrow.git | |
GIT_TAG 16f4306f58193eff18013cc75d8b7b49f1ad4108 | |
CONFIGURE_COMMAND "" | |
BUILD_COMMAND "" | |
INSTALL_COMMAND "" | |
) | |
ExternalProject_Get_property(nanoarrow SOURCE_DIR) | |
target_include_directories(repro PRIVATE "${SOURCE_DIR}/src") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt | |
index 127e2a4..8f81f74 100644 | |
--- a/src/runtime/CMakeLists.txt | |
+++ b/src/runtime/CMakeLists.txt | |
@@ -1,7 +1,3 @@ | |
-include_directories ( | |
- "${PROJECT_SOURCE_DIR}/include" | |
-) | |
- | |
add_library(flatccrt | |
builder.c | |
emitter.c | |
@@ -10,6 +6,10 @@ add_library(flatccrt | |
json_parser.c | |
json_printer.c | |
) | |
+target_include_directories( | |
+ flatccrt | |
+ PUBLIC "${PROJECT_SOURCE_DIR}/include" | |
+) | |
if (FLATCC_INSTALL) | |
install(TARGETS flatccrt DESTINATION ${lib_dir}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment