From 7b95720f59d952eb2f39652761638689b2eaf95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Tue, 5 Apr 2022 13:33:50 +0300 Subject: [PATCH] mdbx++: add support for legacy `experimental/filesystem`. --- GNUmakefile | 4 +++- mdbx.h++ | 22 +++++++++++++++------- src/mdbx.c++ | 16 ++++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 081d4f67..873ce226 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -27,6 +27,7 @@ suffix ?= INSTALL ?= install CC ?= gcc +CXX ?= g++ CFLAGS_EXTRA ?= LD ?= ld MDBX_BUILD_OPTIONS ?=-DNDEBUG=1 @@ -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) ################################################################################ @@ -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) diff --git a/mdbx.h++ b/mdbx.h++ index 903a9f88..d24a1777 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -72,6 +72,8 @@ #if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L #include +#elif __has_include() +#include #endif #include "mdbx.h" @@ -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 @@ -3162,7 +3170,7 @@ public: /// \brief Make a copy (backup) of an existing environment to the specified /// path. #ifdef MDBX_STD_FILESYSTEM_PATH - env ©(const ::std::filesystem::path &destination, bool compactify, + env ©(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false); #endif /* MDBX_STD_FILESYSTEM_PATH */ #if defined(_WIN32) || defined(_WIN64) @@ -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) @@ -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) @@ -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) diff --git a/src/mdbx.c++ b/src/mdbx.c++ index 82656151..373f5282 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -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 utf8(destination); error::success_or_throw( ::mdbx_env_copy(handle_, utf8, (compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) | @@ -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 utf8(pathname); return error::boolean_or_throw( ::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode))); } @@ -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 utf8(pathname); error::success_or_throw( ::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0)); @@ -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 utf8(pathname); set_geometry(cp.geometry); error::success_or_throw( ::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),