Skip to content

Commit

Permalink
v0.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Nov 15, 2024
1 parent 90477b7 commit 83e6380
Show file tree
Hide file tree
Showing 17 changed files with 759 additions and 458 deletions.
250 changes: 134 additions & 116 deletions mdbx/mdbx.c

Large diffs are not rendered by default.

136 changes: 92 additions & 44 deletions mdbx/mdbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,43 @@ typedef mode_t mdbx_mode_t;
#define __has_attribute(x) (0)
#endif /* __has_attribute */

#ifndef __has_c_attribute
#define __has_c_attribute(x) (0)
#endif /* __has_c_attribute */

#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif /* __has_cpp_attribute */

#ifndef __has_CXX_attribute
#if defined(__cplusplus) && \
(!defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1942)
#define __has_CXX_attribute(x) __has_cpp_attribute(x)
#else
#define __has_CXX_attribute(x) 0
#endif
#endif /* __has_CXX_attribute */

#ifndef __has_C23_or_CXX_attribute
#if defined(__cplusplus)
#define __has_C23_or_CXX_attribute(x) __has_CXX_attribute(x)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ > 202311L
#define __has_C23_or_CXX_attribute(x) __has_c_attribute(x)
#else
#define __has_C23_or_CXX_attribute(x) 0
#endif
#endif /* __has_C23_or_CXX_attribute */

#ifndef __has_feature
#define __has_feature(x) (0)
#define __has_exceptions_disabled (0)
#else
#define __has_exceptions_disabled \
(__has_feature(cxx_noexcept) && !__has_feature(cxx_exceptions))
#endif /* __has_feature */

#ifndef __has_extension
#define __has_extension(x) (0)
#define __has_extension(x) __has_feature(x)
#endif /* __has_extension */

#ifndef __has_builtin
Expand All @@ -213,15 +240,14 @@ typedef mode_t mdbx_mode_t;
* These functions should be declared with the attribute pure. */
#if defined(DOXYGEN)
#define MDBX_PURE_FUNCTION [[gnu::pure]]
#elif __has_C23_or_CXX_attribute(gnu::pure) && \
(!defined(__apple_build_version__) || !defined(__clang_major__) || \
__clang_major__ > 17)
#define MDBX_PURE_FUNCTION [[gnu::pure]]
#elif (defined(__GNUC__) || __has_attribute(__pure__)) && \
(!defined(__clang__) /* https://bugs.llvm.org/show_bug.cgi?id=43275 */ \
|| !defined(__cplusplus) || !__has_feature(cxx_exceptions))
(!defined(__clang__) /* https://bugs.llvm.org/show_bug.cgi?id=43275 */ || \
!defined(__cplusplus) || __has_exceptions_disabled)
#define MDBX_PURE_FUNCTION __attribute__((__pure__))
#elif defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1920
#define MDBX_PURE_FUNCTION
#elif defined(__cplusplus) && __has_cpp_attribute(gnu::pure) && \
(!defined(__clang__) || !__has_feature(cxx_exceptions))
#define MDBX_PURE_FUNCTION [[gnu::pure]]
#else
#define MDBX_PURE_FUNCTION
#endif /* MDBX_PURE_FUNCTION */
Expand All @@ -231,22 +257,16 @@ typedef mode_t mdbx_mode_t;
* that is compatible to CLANG and proposed [[pure]]. */
#if defined(DOXYGEN)
#define MDBX_NOTHROW_PURE_FUNCTION [[gnu::pure, gnu::nothrow]]
#elif defined(__GNUC__) || \
(__has_attribute(__pure__) && __has_attribute(__nothrow__))
#define MDBX_NOTHROW_PURE_FUNCTION __attribute__((__pure__, __nothrow__))
#elif defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1920
#if __has_cpp_attribute(pure)
#define MDBX_NOTHROW_PURE_FUNCTION [[pure]]
#else
#define MDBX_NOTHROW_PURE_FUNCTION
#endif
#elif defined(__cplusplus) && __has_cpp_attribute(gnu::pure)
#if __has_cpp_attribute(gnu::nothrow)
#elif __has_C23_or_CXX_attribute(gnu::pure)
#if __has_C23_or_CXX_attribute(gnu::nothrow)
#define MDBX_NOTHROW_PURE_FUNCTION [[gnu::pure, gnu::nothrow]]
#else
#define MDBX_NOTHROW_PURE_FUNCTION [[gnu::pure]]
#endif
#elif defined(__cplusplus) && __has_cpp_attribute(pure)
#elif defined(__GNUC__) || \
(__has_attribute(__pure__) && __has_attribute(__nothrow__))
#define MDBX_NOTHROW_PURE_FUNCTION __attribute__((__pure__, __nothrow__))
#elif __has_CXX_attribute(pure)
#define MDBX_NOTHROW_PURE_FUNCTION [[pure]]
#else
#define MDBX_NOTHROW_PURE_FUNCTION
Expand All @@ -264,15 +284,14 @@ typedef mode_t mdbx_mode_t;
* It does not make sense for a const function to return void. */
#if defined(DOXYGEN)
#define MDBX_CONST_FUNCTION [[gnu::const]]
#elif (defined(__GNUC__) || __has_attribute(__pure__)) && \
(!defined(__clang__) /* https://bugs.llvm.org/show_bug.cgi?id=43275 */ \
|| !defined(__cplusplus) || !__has_feature(cxx_exceptions))
#define MDBX_CONST_FUNCTION __attribute__((__const__))
#elif defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1920
#define MDBX_CONST_FUNCTION MDBX_PURE_FUNCTION
#elif defined(__cplusplus) && __has_cpp_attribute(gnu::const) && \
(!defined(__clang__) || !__has_feature(cxx_exceptions))
#elif __has_C23_or_CXX_attribute(gnu::const) && \
(!defined(__apple_build_version__) || !defined(__clang_major__) || \
__clang_major__ > 17)
#define MDBX_CONST_FUNCTION [[gnu::const]]
#elif (defined(__GNUC__) || __has_attribute(__const__)) && \
(!defined(__clang__) /* https://bugs.llvm.org/show_bug.cgi?id=43275 */ || \
!defined(__cplusplus) || __has_exceptions_disabled)
#define MDBX_CONST_FUNCTION __attribute__((__const__))
#else
#define MDBX_CONST_FUNCTION MDBX_PURE_FUNCTION
#endif /* MDBX_CONST_FUNCTION */
Expand All @@ -282,18 +301,16 @@ typedef mode_t mdbx_mode_t;
* that is compatible to CLANG and future [[const]]. */
#if defined(DOXYGEN)
#define MDBX_NOTHROW_CONST_FUNCTION [[gnu::const, gnu::nothrow]]
#elif __has_C23_or_CXX_attribute(gnu::const)
#if __has_C23_or_CXX_attribute(gnu::nothrow)
#define MDBX_NOTHROW_CONST_FUNCTION [[gnu::const, gnu::nothrow]]
#else
#define MDBX_NOTHROW_CONST_FUNCTION [[gnu::const]]
#endif
#elif defined(__GNUC__) || \
(__has_attribute(__const__) && __has_attribute(__nothrow__))
#define MDBX_NOTHROW_CONST_FUNCTION __attribute__((__const__, __nothrow__))
#elif defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1920
#define MDBX_NOTHROW_CONST_FUNCTION MDBX_NOTHROW_PURE_FUNCTION
#elif defined(__cplusplus) && __has_cpp_attribute(gnu::const)
#if __has_cpp_attribute(gnu::nothrow)
#define MDBX_NOTHROW_PURE_FUNCTION [[gnu::const, gnu::nothrow]]
#else
#define MDBX_NOTHROW_PURE_FUNCTION [[gnu::const]]
#endif
#elif defined(__cplusplus) && __has_cpp_attribute(const)
#elif __has_CXX_attribute(const)
#define MDBX_NOTHROW_CONST_FUNCTION [[const]]
#else
#define MDBX_NOTHROW_CONST_FUNCTION MDBX_NOTHROW_PURE_FUNCTION
Expand Down Expand Up @@ -612,7 +629,7 @@ extern "C" {
#define MDBX_VERSION_MINOR 13

#ifndef LIBMDBX_API
#if defined(LIBMDBX_EXPORTS)
#if defined(LIBMDBX_EXPORTS) || defined(DOXYGEN)
#define LIBMDBX_API __dll_export
#elif defined(LIBMDBX_IMPORTS)
#define LIBMDBX_API __dll_import
Expand All @@ -622,7 +639,7 @@ extern "C" {
#endif /* LIBMDBX_API */

#ifdef __cplusplus
#if defined(__clang__) || __has_attribute(type_visibility)
#if defined(__clang__) || __has_attribute(type_visibility) || defined(DOXYGEN)
#define LIBMDBX_API_TYPE LIBMDBX_API __attribute__((type_visibility("default")))
#else
#define LIBMDBX_API_TYPE LIBMDBX_API
Expand Down Expand Up @@ -1996,7 +2013,7 @@ typedef enum MDBX_error {
MDBX_DUPLICATED_CLK = -30413,

/** Some cursors and/or other resources should be closed before table or
* corresponding DBI-handle could be (re)used */
* corresponding DBI-handle could be (re)used and/or closed. */
MDBX_DANGLING_DBI = -30412,

/** The parked read transaction was outed for the sake of
Expand Down Expand Up @@ -2542,6 +2559,11 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *pathname,
* \see mdbx_env_open() */
LIBMDBX_API int mdbx_env_openW(MDBX_env *env, const wchar_t *pathname,
MDBX_env_flags_t flags, mdbx_mode_t mode);
#define mdbx_env_openT(env, pathname, flags, mode) \
mdbx_env_openW(env, pathname, flags, mode)
#else
#define mdbx_env_openT(env, pathname, flags, mode) \
mdbx_env_open(env, pathname, flags, mode)
#endif /* Windows */

/** \brief Deletion modes for \ref mdbx_env_delete().
Expand Down Expand Up @@ -2592,6 +2614,9 @@ LIBMDBX_API int mdbx_env_delete(const char *pathname,
* \see mdbx_env_delete() */
LIBMDBX_API int mdbx_env_deleteW(const wchar_t *pathname,
MDBX_env_delete_mode_t mode);
#define mdbx_env_deleteT(pathname, mode) mdbx_env_deleteW(pathname, mode)
#else
#define mdbx_env_deleteT(pathname, mode) mdbx_env_delete(pathname, mode)
#endif /* Windows */

/** \brief Copy an MDBX environment to the specified path, with options.
Expand Down Expand Up @@ -2713,13 +2738,20 @@ LIBMDBX_API int mdbx_txn_copy2pathname(MDBX_txn *txn, const char *dest,
* \see mdbx_env_copy() */
LIBMDBX_API int mdbx_env_copyW(MDBX_env *env, const wchar_t *dest,
MDBX_copy_flags_t flags);
#define mdbx_env_copyT(env, dest, flags) mdbx_env_copyW(env, dest, flags)

/** \copydoc mdbx_txn_copy2pathname()
* \ingroup c_extra
* \note Available only on Windows.
* \see mdbx_txn_copy2pathname() */
LIBMDBX_API int mdbx_txn_copy2pathnameW(MDBX_txn *txn, const wchar_t *dest,
MDBX_copy_flags_t flags);
#define mdbx_txn_copy2pathnameT(txn, dest, flags) \
mdbx_txn_copy2pathnameW(txn, dest, path)
#else
#define mdbx_env_copyT(env, dest, flags) mdbx_env_copy(env, dest, flags)
#define mdbx_txn_copy2pathnameT(txn, dest, flags) \
mdbx_txn_copy2pathname(txn, dest, path)
#endif /* Windows */

/** \brief Copy an environment to the specified file descriptor, with
Expand Down Expand Up @@ -3386,6 +3418,9 @@ LIBMDBX_API int mdbx_env_get_path(const MDBX_env *env, const char **dest);
* \note Available only on Windows.
* \see mdbx_env_get_path() */
LIBMDBX_API int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **dest);
#define mdbx_env_get_pathT(env, dest) mdbx_env_get_pathW(env, dest)
#else
#define mdbx_env_get_pathT(env, dest) mdbx_env_get_path(env, dest)
#endif /* Windows */

/** \brief Return the file descriptor for the given environment.
Expand Down Expand Up @@ -3848,7 +3883,7 @@ mdbx_env_get_maxvalsize_ex(const MDBX_env *env, MDBX_db_flags_t flags);
/** \deprecated Please use \ref mdbx_env_get_maxkeysize_ex()
* and/or \ref mdbx_env_get_maxvalsize_ex()
* \ingroup c_statinfo */
MDBX_DEPRECATED MDBX_NOTHROW_PURE_FUNCTION LIBMDBX_API int
MDBX_NOTHROW_PURE_FUNCTION MDBX_DEPRECATED LIBMDBX_API int
mdbx_env_get_maxkeysize(const MDBX_env *env);

/** \brief Returns maximal size of key-value pair to fit in a single page
Expand Down Expand Up @@ -4887,9 +4922,12 @@ LIBMDBX_INLINE_API(int, mdbx_dbi_flags,
* \ref mdbx_env_set_maxdbs(), unless that value would be large.
*
* \note Use with care.
* This call is synchronized via mutex with \ref mdbx_dbi_close(), but NOT with
* other transactions running by other threads. The "next" version of libmdbx
* (\ref MithrilDB) will solve this issue.
* This call is synchronized via mutex with \ref mdbx_dbi_open(), but NOT with
* any transaction(s) running by other thread(s).
* So the `mdbx_dbi_close()` MUST NOT be called in-parallel/concurrently
* with any transactions using the closing dbi-handle, nor during other thread
* commit/abort a write transacton(s). The "next" version of libmdbx (\ref
* MithrilDB) will solve this issue.
*
* Handles should only be closed if no other threads are going to reference
* the table handle or one of its cursors any further. Do not close a handle
Expand Down Expand Up @@ -6406,6 +6444,11 @@ LIBMDBX_API int mdbx_env_open_for_recoveryW(MDBX_env *env,
const wchar_t *pathname,
unsigned target_meta,
bool writeable);
#define mdbx_env_open_for_recoveryT(env, pathname, target_mets, writeable) \
mdbx_env_open_for_recoveryW(env, pathname, target_mets, writeable)
#else
#define mdbx_env_open_for_recoveryT(env, pathname, target_mets, writeable) \
mdbx_env_open_for_recovery(env, pathname, target_mets, writeable)
#endif /* Windows */

/** \brief Turn database to the specified meta-page.
Expand Down Expand Up @@ -6455,6 +6498,11 @@ LIBMDBX_API int mdbx_preopen_snapinfo(const char *pathname, MDBX_envinfo *info,
* \see mdbx_preopen_snapinfo() */
LIBMDBX_API int mdbx_preopen_snapinfoW(const wchar_t *pathname,
MDBX_envinfo *info, size_t bytes);
#define mdbx_preopen_snapinfoT(pathname, info, bytes) \
mdbx_preopen_snapinfoW(pathname, info, bytes)
#else
#define mdbx_preopen_snapinfoT(pathname, info, bytes) \
mdbx_preopen_snapinfo(pathname, info, bytes)
#endif /* Windows */

/** \brief Флаги/опции для проверки целостности базы данных.
Expand Down
33 changes: 27 additions & 6 deletions mdbxdist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ if(MDBX_MANAGE_BUILD_FLAGS)
setup_compile_flags()
endif()

list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 HAS_CXX17)
Expand Down Expand Up @@ -481,21 +480,26 @@ if(NOT DEFINED MDBX_CXX_STANDARD)
set(MDBX_CXX_STANDARD 98)
endif()
endif()

list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
list(FIND CMAKE_C_COMPILE_FEATURES c_std_23 HAS_C23)
if(NOT DEFINED MDBX_C_STANDARD)
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad!
# It unable process Windows SDK headers in the C11 mode!
if(MSVC AND MSVC_VERSION GREATER 1927 AND NOT MSVC_VERSION GREATER 1929)
set(MDBX_C_STANDARD 99)
set(C_FALLBACK_11 OFF)
set(C_FALLBACK_GNU11 OFF)
elseif(NOT HAS_C23 LESS 0)
set(MDBX_C_STANDARD 23)
elseif(HAS_C11 LESS 0 AND NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set(MDBX_C_STANDARD 99)
else()
set(MDBX_C_STANDARD 11)
endif()
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
if(MSVC)
if(NOT MSVC_LIB_EXE)
# Find lib.exe
Expand Down Expand Up @@ -592,7 +596,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS)
add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(WIN32)
if(MDBX_NTDLL_EXTRA_IMPLIB)
add_mdbx_option(MDBX_WITHOUT_MSVC_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
endif()
Expand Down Expand Up @@ -656,6 +660,10 @@ else()
set(MDBX_ENABLE_TESTS FALSE)
endif()

if(CI)
add_definitions(-DMDBX_CI="${CI}")
endif()

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

Expand Down Expand Up @@ -796,7 +804,7 @@ macro(target_setup_options TARGET)
set_target_properties(${TARGET} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
endif()
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
if(NOT MDBX_C_STANDARD EQUAL 11 OR (NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11))
set_target_properties(${TARGET} PROPERTIES
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
endif()
Expand Down Expand Up @@ -825,7 +833,7 @@ macro(libmdbx_setup_libs TARGET MODE)
else()
target_link_libraries(${TARGET} ${MODE} Threads::Threads)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(WIN32)
target_link_libraries(${TARGET} ${MODE} ntdll user32 kernel32 advapi32 ole32)
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT)
target_link_libraries(${TARGET} ${MODE} ntdll_extra)
Expand Down Expand Up @@ -906,14 +914,27 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
endif()
endif()

if(WIN32)
# Windows don't have RPATH feature,
# therefore we should prepare PATH or copy DLL(s)
set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}")
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0)
# will use LOCATION property to compose DLLPATH
cmake_policy(SET CMP0026 OLD)
endif()
else()
set(TOOL_MDBX_DLLCRUTCH FALSE)
endif()
else()
set(TOOL_MDBX_LIB mdbx-static)
set(TOOL_MDBX_DLLCRUTCH FALSE)
endif()

# build mdbx-tools
if(MDBX_BUILD_TOOLS)
set(WINGETOPT_SRC "")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(WIN32)
set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c ${MDBX_SOURCE_DIR}/tools/wingetopt.h)
endif()

Expand Down
Loading

0 comments on commit 83e6380

Please sign in to comment.