From 1e3c4dc0efc50c1bc7b0ac82b69e2c253d2b99e4 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 19 Jul 2020 10:41:15 +0300 Subject: [PATCH] mdbx: define & use bool type for C API. Change-Id: Icb6cd635a4813bfc92d31bdc527414bdddce4a63 --- mdbx.h | 16 ++++++++++++++-- src/core.c | 7 ++----- src/defs.h | 12 ------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/mdbx.h b/mdbx.h index c5704f5f..194bdc87 100644 --- a/mdbx.h +++ b/mdbx.h @@ -181,6 +181,18 @@ typedef pthread_t mdbx_tid_t; /*----------------------------------------------------------------------------*/ +#ifndef __cplusplus +#ifndef bool +#define bool _Bool +#endif +#ifndef true +#define true (1) +#endif +#ifndef false +#define false (0) +#endif +#endif /* bool without __cplusplus */ + #if !defined(cxx11_noexcept) #if defined(__cplusplus) && __cplusplus >= 201103L #define cxx11_noexcept noexcept @@ -2358,7 +2370,7 @@ typedef struct MDBX_txn_info MDBX_txn_info; * * \returns A non-zero error value on failure and 0 on success. */ LIBMDBX_API int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, - int scan_rlt); + bool scan_rlt); /** Returns the transaction's MDBX_env. * \ingroup c_transactions @@ -2826,7 +2838,7 @@ LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi); * from the environment and close the DB handle. * * \returns A non-zero error value on failure and 0 on success. */ -LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del); +LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del); /** Get items from a database. * \ingroup c_crud diff --git a/src/core.c b/src/core.c index fa2d81af..977a8222 100644 --- a/src/core.c +++ b/src/core.c @@ -6408,7 +6408,7 @@ int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags, return rc; } -int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, int scan_rlt) { +int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, bool scan_rlt) { int rc = check_txn(txn, MDBX_TXN_BLOCKED - MDBX_TXN_HAS_CHILD); if (unlikely(rc != MDBX_SUCCESS)) return rc; @@ -16842,14 +16842,11 @@ static int mdbx_drop0(MDBX_cursor *mc, int subs) { return rc; } -int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del) { +int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del) { int rc = check_txn_rw(txn, MDBX_TXN_BLOCKED); if (unlikely(rc != MDBX_SUCCESS)) return rc; - if (unlikely(1 < (unsigned)del)) - return MDBX_EINVAL; - if (unlikely(!mdbx_txn_dbi_exists(txn, dbi, DBI_USRVALID))) return MDBX_EINVAL; diff --git a/src/defs.h b/src/defs.h index f4672d5b..d062b7c1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -89,18 +89,6 @@ # endif #endif /* __extern_C */ -#ifndef __cplusplus -# ifndef bool -# define bool _Bool -# endif -# ifndef true -# define true (1) -# endif -# ifndef false -# define false (0) -# endif -#endif - #if !defined(nullptr) && !defined(__cplusplus) || (__cplusplus < 201103L && !defined(_MSC_VER)) # define nullptr NULL #endif