diff --git a/mdbx.h++ b/mdbx.h++ index ace662d8..64143c48 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -3228,6 +3228,8 @@ public: #endif /* Windows */ env ©(const ::std::string &destination, bool compactify, bool force_dynamic_size = false); + env ©(const char *destination, bool compactify, + bool force_dynamic_size = false); /// \brief Copy an environment to the specified file descriptor. env ©(filehandle fd, bool compactify, bool force_dynamic_size = false); @@ -3252,14 +3254,16 @@ public: /// \brief Removes the environment's files in a proper and multiprocess-safe /// way. #ifdef MDBX_STD_FILESYSTEM_PATH - static bool remove(const MDBX_STD_FILESYSTEM_PATH &, + static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove); #endif /* MDBX_STD_FILESYSTEM_PATH */ #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN) - static bool remove(const ::std::wstring &, + static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove); #endif /* Windows */ - static bool remove(const ::std::string &, + static bool remove(const ::std::string &pathname, + const remove_mode mode = just_remove); + static bool remove(const char *pathname, const remove_mode mode = just_remove); /// \brief Statistics for a database in the MDBX environment. @@ -3497,15 +3501,17 @@ public: /// \brief Open existing database. #ifdef MDBX_STD_FILESYSTEM_PATH - env_managed(const MDBX_STD_FILESYSTEM_PATH &, const operate_parameters &, - bool accede = true); + env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, + const operate_parameters &, bool accede = true); #endif /* MDBX_STD_FILESYSTEM_PATH */ #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN) - env_managed(const ::std::wstring &, const operate_parameters &, + env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true); #endif /* Windows */ - env_managed(const ::std::string &, const operate_parameters &, + env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true); + explicit env_managed(const char *pathname, const operate_parameters &, + bool accede = true); /// \brief Additional parameters for creating a new database. struct create_parameters { @@ -3518,15 +3524,18 @@ public: /// \brief Create new or open existing database. #ifdef MDBX_STD_FILESYSTEM_PATH - env_managed(const MDBX_STD_FILESYSTEM_PATH &, const create_parameters &, - const operate_parameters &, bool accede = true); + env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, + const create_parameters &, const operate_parameters &, + bool accede = true); #endif /* MDBX_STD_FILESYSTEM_PATH */ #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN) - env_managed(const ::std::wstring &, const create_parameters &, + env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede = true); #endif /* Windows */ - env_managed(const ::std::string &, const create_parameters &, + env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true); + explicit env_managed(const char *pathname, const create_parameters &, + const operate_parameters &, bool accede = true); /// \brief Explicitly closes the environment and release the memory map. /// diff --git a/src/mdbx.c++ b/src/mdbx.c++ index f8bf60be..ccb5fa3e 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -214,12 +214,6 @@ MDBX_MAYBE_UNUSED PATH pchar_to_path(const char *c_str) { return PATH(c_str); } -template <> struct path_to_pchar { - const char *const ptr; - path_to_pchar(const std::string &path) : ptr(path.c_str()) {} - operator const char *() const { return ptr; } -}; - #if defined(_WIN32) || defined(_WIN64) #ifndef WC_ERR_INVALID_CHARS @@ -1271,17 +1265,21 @@ env &env::copy(const ::std::wstring &destination, bool compactify, } #endif /* Windows */ -env &env::copy(const ::std::string &destination, bool compactify, +env &env::copy(const char *destination, bool compactify, bool force_dynamic_size) { - const path_to_pchar<::std::string> utf8(destination); error::success_or_throw( - ::mdbx_env_copy(handle_, utf8, + ::mdbx_env_copy(handle_, destination, (compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) | (force_dynamic_size ? MDBX_CP_FORCE_DYNAMIC_SIZE : MDBX_CP_DEFAULTS))); return *this; } +env &env::copy(const ::std::string &destination, bool compactify, + bool force_dynamic_size) { + return copy(destination.c_str(), compactify, force_dynamic_size); +} + env &env::copy(filehandle fd, bool compactify, bool force_dynamic_size) { error::success_or_throw( ::mdbx_env_copy2fd(handle_, fd, @@ -1314,10 +1312,13 @@ bool env::remove(const ::std::wstring &pathname, const remove_mode mode) { } #endif /* Windows */ -bool env::remove(const ::std::string &pathname, const remove_mode mode) { - const path_to_pchar<::std::string> utf8(pathname); +bool env::remove(const char *pathname, const remove_mode mode) { return error::boolean_or_throw( - ::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode))); + ::mdbx_env_delete(pathname, MDBX_env_delete_mode_t(mode))); +} + +bool env::remove(const ::std::string &pathname, const remove_mode mode) { + return remove(pathname.c_str(), mode); } //------------------------------------------------------------------------------ @@ -1418,35 +1419,42 @@ __cold env_managed::env_managed(const ::std::wstring &pathname, } #endif /* Windows */ -__cold env_managed::env_managed(const ::std::string &pathname, +__cold env_managed::env_managed(const char *pathname, const operate_parameters &op, bool accede) : env_managed(create_env()) { setup(op.max_maps, op.max_readers); - const path_to_pchar<::std::string> utf8(pathname); error::success_or_throw( - ::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0)); + ::mdbx_env_open(handle_, pathname, op.make_flags(accede), 0)); if (op.options.nested_write_transactions && !get_options().nested_write_transactions) MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_INCOMPATIBLE); } -__cold env_managed::env_managed(const ::std::string &pathname, +__cold env_managed::env_managed(const char *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::string> utf8(pathname); set_geometry(cp.geometry); - error::success_or_throw( - ::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory), - cp.file_mode_bits)); + error::success_or_throw(::mdbx_env_open( + handle_, pathname, op.make_flags(accede, cp.use_subdirectory), + cp.file_mode_bits)); if (op.options.nested_write_transactions && !get_options().nested_write_transactions) MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_INCOMPATIBLE); } +__cold env_managed::env_managed(const ::std::string &pathname, + const operate_parameters &op, bool accede) + : env_managed(pathname.c_str(), op, accede) {} + +__cold env_managed::env_managed(const ::std::string &pathname, + const env_managed::create_parameters &cp, + const env::operate_parameters &op, bool accede) + : env_managed(pathname.c_str(), cp, op, accede) {} + //------------------------------------------------------------------------------ txn_managed txn::start_nested() {