Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Sep 18, 2024
2 parents 4874f97 + 9298fbe commit 7a5b59b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.22)
project(metall-ffi VERSION 0.2.4)
project(metall-ffi VERSION 0.2.5)

include(cmake/boilerplate_init.cmake)
boilerplate_init()
Expand Down
20 changes: 20 additions & 0 deletions src/dice/ffi/metall.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
#include <stdbool.h>
#include <stddef.h>

#if __has_include(<metall/logger_interface.h>)
#include <metall/logger_interface.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if !__has_include(<metall/logger_interface.h>)
/// \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;

/**
Expand Down
35 changes: 33 additions & 2 deletions src/dice/ffi/metall_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,42 @@
#include <metall/metall.hpp>

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<typename T>
using allocator_type = typename metall::manager::template allocator_type<T>;

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
2 changes: 2 additions & 0 deletions test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <dice/ffi/metall.h>

#if __has_include(<metall/logger_interface.h>)
extern "C" void metall_log(metall_log_level, char const *, size_t, char const *) {
// noop
}
#endif

int main() {
metall_open("/tmp/test");
Expand Down
2 changes: 2 additions & 0 deletions tests/tests_Sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include <string>
#include <random>

#if __has_include(<metall/logger_interface.h>)
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") {
Expand Down

0 comments on commit 7a5b59b

Please sign in to comment.