Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
mdbx++: add support for legacy experimental/filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
erthink committed Apr 5, 2022
1 parent 64e23c9 commit 7b95720
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 3 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suffix ?=

INSTALL ?= install
CC ?= gcc
CXX ?= g++
CFLAGS_EXTRA ?=
LD ?= ld
MDBX_BUILD_OPTIONS ?=-DNDEBUG=1
Expand All @@ -40,6 +41,7 @@ CXXFLAGS = $(strip $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS)))
LIBS ?= $(shell $(uname2libs))
LDFLAGS ?= $(shell $(uname2ldflags))
EXE_LDFLAGS ?= -pthread
LIB_STDCXXFS ?= $(eval LIB_STDCXXFS := $$(shell echo 'int main(void) { MDBX_STD_FILESYSTEM_PATH probe; return probe.is_absolute(); }' | cat mdbx.h++ - | sed $$$$'1s/\xef\xbb\xbf//' | $(CXX) -x c++ $(CXXFLAGS) - -Wl,--allow-multiple-definition -lstdc++fs $(LIBS) $(LDFLAGS) $(EXE_LDFLAGS) -o /dev/null 2>probe4lstdfs.err >/dev/null && echo '-Wl,--allow-multiple-definition -lstdc++fs'))$(LIB_STDCXXFS)

################################################################################

Expand Down Expand Up @@ -231,7 +233,7 @@ lib-static libmdbx.a: mdbx-static.o mdbx++-static.o

lib-shared libmdbx.$(SO_SUFFIX): mdbx-dylib.o mdbx++-dylib.o
@echo ' LD $@'
$(QUIET)$(CXX) $(CXXFLAGS) $^ -pthread -shared $(LDFLAGS) $(LIBS) -o $@
$(QUIET)$(CXX) $(CXXFLAGS) $^ -pthread -shared $(LDFLAGS) $(LIB_STDCXXFS) $(LIBS) -o $@

#> dist-cutoff-begin
ifeq ($(wildcard mdbx.c),mdbx.c)
Expand Down
22 changes: 15 additions & 7 deletions mdbx.h++
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@

#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
#include <filesystem>
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
#endif

#include "mdbx.h"
Expand Down Expand Up @@ -323,13 +325,19 @@ using filehandle = ::mdbx_filehandle_t;
__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
(!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
__IPHONE_OS_VERSION_MIN_REQUIRED >= 130100))
#define MDBX_STD_FILESYSTEM_PATH
using path = ::std::filesystem::path;
#define MDBX_STD_FILESYSTEM_PATH ::std::filesystem::path
#elif defined(__cpp_lib_experimental_filesystem) && \
__cpp_lib_experimental_filesystem >= 201406L
#define MDBX_STD_FILESYSTEM_PATH ::std::experimental::filesystem::path
#endif /* MDBX_STD_FILESYSTEM_PATH */

#ifdef MDBX_STD_FILESYSTEM_PATH
using path = MDBX_STD_FILESYSTEM_PATH;
#elif defined(_WIN32) || defined(_WIN64)
using path = ::std::wstring;
#else
using path = ::std::string;
#endif
#endif /* mdbx::path */

/// \brief Transfers C++ exceptions thru C callbacks.
/// \details Implements saving exceptions before returning
Expand Down Expand Up @@ -3162,7 +3170,7 @@ public:
/// \brief Make a copy (backup) of an existing environment to the specified
/// path.
#ifdef MDBX_STD_FILESYSTEM_PATH
env &copy(const ::std::filesystem::path &destination, bool compactify,
env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify,
bool force_dynamic_size = false);
#endif /* MDBX_STD_FILESYSTEM_PATH */
#if defined(_WIN32) || defined(_WIN64)
Expand Down Expand Up @@ -3195,7 +3203,7 @@ public:
/// \brief Removes the environment's files in a proper and multiprocess-safe
/// way.
#ifdef MDBX_STD_FILESYSTEM_PATH
static bool remove(const ::std::filesystem::path &,
static bool remove(const MDBX_STD_FILESYSTEM_PATH &,
const remove_mode mode = just_remove);
#endif /* MDBX_STD_FILESYSTEM_PATH */
#if defined(_WIN32) || defined(_WIN64)
Expand Down Expand Up @@ -3440,7 +3448,7 @@ public:

/// \brief Open existing database.
#ifdef MDBX_STD_FILESYSTEM_PATH
env_managed(const ::std::filesystem::path &, const operate_parameters &,
env_managed(const MDBX_STD_FILESYSTEM_PATH &, const operate_parameters &,
bool accede = true);
#endif /* MDBX_STD_FILESYSTEM_PATH */
#if defined(_WIN32) || defined(_WIN64)
Expand All @@ -3461,7 +3469,7 @@ public:

/// \brief Create new or open existing database.
#ifdef MDBX_STD_FILESYSTEM_PATH
env_managed(const ::std::filesystem::path &, const create_parameters &,
env_managed(const MDBX_STD_FILESYSTEM_PATH &, const create_parameters &,
const operate_parameters &, bool accede = true);
#endif /* MDBX_STD_FILESYSTEM_PATH */
#if defined(_WIN32) || defined(_WIN64)
Expand Down
16 changes: 8 additions & 8 deletions src/mdbx.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,9 @@ bool env::is_pristine() const {
bool env::is_empty() const { return get_stat().ms_leaf_pages == 0; }

#ifdef MDBX_STD_FILESYSTEM_PATH
env &env::copy(const ::std::filesystem::path &destination, bool compactify,
env &env::copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify,
bool force_dynamic_size) {
const path_to_pchar<::std::filesystem::path> utf8(destination);
const path_to_pchar<MDBX_STD_FILESYSTEM_PATH> utf8(destination);
error::success_or_throw(
::mdbx_env_copy(handle_, utf8,
(compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
Expand Down Expand Up @@ -1299,9 +1299,9 @@ path env::get_path() const {
}

#ifdef MDBX_STD_FILESYSTEM_PATH
bool env::remove(const ::std::filesystem::path &pathname,
bool env::remove(const MDBX_STD_FILESYSTEM_PATH &pathname,
const remove_mode mode) {
const path_to_pchar<::std::filesystem::path> utf8(pathname);
const path_to_pchar<MDBX_STD_FILESYSTEM_PATH> utf8(pathname);
return error::boolean_or_throw(
::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode)));
}
Expand Down Expand Up @@ -1358,11 +1358,11 @@ __cold void env_managed::setup(unsigned max_maps, unsigned max_readers) {
}

#ifdef MDBX_STD_FILESYSTEM_PATH
__cold env_managed::env_managed(const ::std::filesystem::path &pathname,
__cold env_managed::env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname,
const operate_parameters &op, bool accede)
: env_managed(create_env()) {
setup(op.max_maps, op.max_readers);
const path_to_pchar<::std::filesystem::path> utf8(pathname);
const path_to_pchar<MDBX_STD_FILESYSTEM_PATH> utf8(pathname);
error::success_or_throw(
::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0));

Expand All @@ -1371,12 +1371,12 @@ __cold env_managed::env_managed(const ::std::filesystem::path &pathname,
MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_INCOMPATIBLE);
}

__cold env_managed::env_managed(const ::std::filesystem::path &pathname,
__cold env_managed::env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname,
const env_managed::create_parameters &cp,
const env::operate_parameters &op, bool accede)
: env_managed(create_env()) {
setup(op.max_maps, op.max_readers);
const path_to_pchar<::std::filesystem::path> utf8(pathname);
const path_to_pchar<MDBX_STD_FILESYSTEM_PATH> utf8(pathname);
set_geometry(cp.geometry);
error::success_or_throw(
::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),
Expand Down

0 comments on commit 7b95720

Please sign in to comment.