From 46d172e339a510f9cc5e24365495a70f89dd2482 Mon Sep 17 00:00:00 2001 From: Liss Heidrich <31625940+liss-h@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:16:48 +0200 Subject: [PATCH] Fix: compatibility with older metall versions (#18) --- src/dice/ffi/metall.h | 20 ++++++++++++++++++ src/dice/ffi/metall_internal.hpp | 35 ++++++++++++++++++++++++++++++-- test_package/example.cpp | 2 ++ tests/tests_Sanity.cpp | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/dice/ffi/metall.h b/src/dice/ffi/metall.h index c84d152..7689efd 100644 --- a/src/dice/ffi/metall.h +++ b/src/dice/ffi/metall.h @@ -4,12 +4,32 @@ #include #include +#if __has_include() #include +#endif #ifdef __cplusplus extern "C" { #endif +#if !__has_include() +/// \brief Log message level +typedef enum metall_log_level { + /// \brief Critical logger message + metall_critical = 5, + /// \brief Error logger message + metall_error = 4, + /// \brief Warning logger message + metall_warning = 3, + /// \brief Info logger message + metall_info = 2, + /// \brief Debug logger message + metall_debug = 1, + /// \brief Verbose (lowest priority) logger message + metall_verbose = 0, +} metall_log_level; +#endif + typedef struct metall_manager metall_manager; /** diff --git a/src/dice/ffi/metall_internal.hpp b/src/dice/ffi/metall_internal.hpp index d3dcdfc..38925a9 100644 --- a/src/dice/ffi/metall_internal.hpp +++ b/src/dice/ffi/metall_internal.hpp @@ -5,11 +5,42 @@ #include namespace dice::metall_ffi::internal { - /** +#if METALL_VERSION >= 2800 + /** * @brief The metall manager type used internally. * This object type is whats actually behind the opaque ::metall_manager * in the interface */ - using metall_manager = metall::manager; + using metall_manager = metall::manager; +#else + + /** + * @brief The metall manager type used internally. + * This object type is whats actually behind the opaque ::metall_manager * in the interface. + * This is a wrapper that contains the read_only flag for older versions that do not support read_only() yet. + */ + struct metall_manager : metall::manager { + bool read_only_; + + template + using allocator_type = typename metall::manager::template allocator_type; + + metall_manager(metall::create_only_t op, char const *path) : metall::manager{op, path}, + read_only_{false} { + } + + metall_manager(metall::open_only_t op, char const *path) : metall::manager{op, path}, + read_only_{false} { + } + + metall_manager(metall::open_read_only_t op, char const *path) : metall::manager{op, path}, + read_only_{true} { + } + + [[nodiscard]] bool read_only() const noexcept { + return read_only_; + } + }; +#endif } // namespace #endif//DICE_METALLFFI_METALLINTERNAL_HPP diff --git a/test_package/example.cpp b/test_package/example.cpp index 9d06265..a160b9e 100644 --- a/test_package/example.cpp +++ b/test_package/example.cpp @@ -1,8 +1,10 @@ #include +#if __has_include() extern "C" void metall_log(metall_log_level, char const *, size_t, char const *) { // noop } +#endif int main() { metall_open("/tmp/test"); diff --git a/tests/tests_Sanity.cpp b/tests/tests_Sanity.cpp index ac9394f..eefb935 100644 --- a/tests/tests_Sanity.cpp +++ b/tests/tests_Sanity.cpp @@ -6,9 +6,11 @@ #include #include +#if __has_include() extern "C" void metall_log(metall_log_level lvl, char const *file, size_t line, char const *msg) { std::cerr << lvl << " " << file << ":" << line << ": " << msg << std::endl; } +#endif TEST_SUITE("metall-ffi") { TEST_CASE("sanity check") {