mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx++: add support for legacy experimental/filesystem
.
This commit is contained in:
parent
64e23c9be0
commit
7b95720f59
@ -27,6 +27,7 @@ suffix ?=
|
|||||||
|
|
||||||
INSTALL ?= install
|
INSTALL ?= install
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
|
CXX ?= g++
|
||||||
CFLAGS_EXTRA ?=
|
CFLAGS_EXTRA ?=
|
||||||
LD ?= ld
|
LD ?= ld
|
||||||
MDBX_BUILD_OPTIONS ?=-DNDEBUG=1
|
MDBX_BUILD_OPTIONS ?=-DNDEBUG=1
|
||||||
@ -40,6 +41,7 @@ CXXFLAGS = $(strip $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS)))
|
|||||||
LIBS ?= $(shell $(uname2libs))
|
LIBS ?= $(shell $(uname2libs))
|
||||||
LDFLAGS ?= $(shell $(uname2ldflags))
|
LDFLAGS ?= $(shell $(uname2ldflags))
|
||||||
EXE_LDFLAGS ?= -pthread
|
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
|
lib-shared libmdbx.$(SO_SUFFIX): mdbx-dylib.o mdbx++-dylib.o
|
||||||
@echo ' LD $@'
|
@echo ' LD $@'
|
||||||
$(QUIET)$(CXX) $(CXXFLAGS) $^ -pthread -shared $(LDFLAGS) $(LIBS) -o $@
|
$(QUIET)$(CXX) $(CXXFLAGS) $^ -pthread -shared $(LDFLAGS) $(LIB_STDCXXFS) $(LIBS) -o $@
|
||||||
|
|
||||||
#> dist-cutoff-begin
|
#> dist-cutoff-begin
|
||||||
ifeq ($(wildcard mdbx.c),mdbx.c)
|
ifeq ($(wildcard mdbx.c),mdbx.c)
|
||||||
|
22
mdbx.h++
22
mdbx.h++
@ -72,6 +72,8 @@
|
|||||||
|
|
||||||
#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
|
#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#elif __has_include(<experimental/filesystem>)
|
||||||
|
#include <experimental/filesystem>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mdbx.h"
|
#include "mdbx.h"
|
||||||
@ -323,13 +325,19 @@ using filehandle = ::mdbx_filehandle_t;
|
|||||||
__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
|
__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
|
||||||
(!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
|
(!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
|
||||||
__IPHONE_OS_VERSION_MIN_REQUIRED >= 130100))
|
__IPHONE_OS_VERSION_MIN_REQUIRED >= 130100))
|
||||||
#define MDBX_STD_FILESYSTEM_PATH
|
#define MDBX_STD_FILESYSTEM_PATH ::std::filesystem::path
|
||||||
using 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)
|
#elif defined(_WIN32) || defined(_WIN64)
|
||||||
using path = ::std::wstring;
|
using path = ::std::wstring;
|
||||||
#else
|
#else
|
||||||
using path = ::std::string;
|
using path = ::std::string;
|
||||||
#endif
|
#endif /* mdbx::path */
|
||||||
|
|
||||||
/// \brief Transfers C++ exceptions thru C callbacks.
|
/// \brief Transfers C++ exceptions thru C callbacks.
|
||||||
/// \details Implements saving exceptions before returning
|
/// \details Implements saving exceptions before returning
|
||||||
@ -3162,7 +3170,7 @@ public:
|
|||||||
/// \brief Make a copy (backup) of an existing environment to the specified
|
/// \brief Make a copy (backup) of an existing environment to the specified
|
||||||
/// path.
|
/// path.
|
||||||
#ifdef MDBX_STD_FILESYSTEM_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);
|
bool force_dynamic_size = false);
|
||||||
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -3195,7 +3203,7 @@ public:
|
|||||||
/// \brief Removes the environment's files in a proper and multiprocess-safe
|
/// \brief Removes the environment's files in a proper and multiprocess-safe
|
||||||
/// way.
|
/// way.
|
||||||
#ifdef MDBX_STD_FILESYSTEM_PATH
|
#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);
|
const remove_mode mode = just_remove);
|
||||||
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -3440,7 +3448,7 @@ public:
|
|||||||
|
|
||||||
/// \brief Open existing database.
|
/// \brief Open existing database.
|
||||||
#ifdef MDBX_STD_FILESYSTEM_PATH
|
#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);
|
bool accede = true);
|
||||||
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -3461,7 +3469,7 @@ public:
|
|||||||
|
|
||||||
/// \brief Create new or open existing database.
|
/// \brief Create new or open existing database.
|
||||||
#ifdef MDBX_STD_FILESYSTEM_PATH
|
#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);
|
const operate_parameters &, bool accede = true);
|
||||||
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
#endif /* MDBX_STD_FILESYSTEM_PATH */
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
16
src/mdbx.c++
16
src/mdbx.c++
@ -1247,9 +1247,9 @@ bool env::is_pristine() const {
|
|||||||
bool env::is_empty() const { return get_stat().ms_leaf_pages == 0; }
|
bool env::is_empty() const { return get_stat().ms_leaf_pages == 0; }
|
||||||
|
|
||||||
#ifdef MDBX_STD_FILESYSTEM_PATH
|
#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) {
|
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(
|
error::success_or_throw(
|
||||||
::mdbx_env_copy(handle_, utf8,
|
::mdbx_env_copy(handle_, utf8,
|
||||||
(compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
|
(compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
|
||||||
@ -1299,9 +1299,9 @@ path env::get_path() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MDBX_STD_FILESYSTEM_PATH
|
#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 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(
|
return error::boolean_or_throw(
|
||||||
::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode)));
|
::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
|
#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)
|
const operate_parameters &op, bool accede)
|
||||||
: env_managed(create_env()) {
|
: env_managed(create_env()) {
|
||||||
setup(op.max_maps, op.max_readers);
|
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(
|
error::success_or_throw(
|
||||||
::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0));
|
::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);
|
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_managed::create_parameters &cp,
|
||||||
const env::operate_parameters &op, bool accede)
|
const env::operate_parameters &op, bool accede)
|
||||||
: env_managed(create_env()) {
|
: env_managed(create_env()) {
|
||||||
setup(op.max_maps, op.max_readers);
|
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);
|
set_geometry(cp.geometry);
|
||||||
error::success_or_throw(
|
error::success_or_throw(
|
||||||
::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),
|
::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user