From 32764bcb52e70588982d576cb16f435705c11279 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sat, 23 Jul 2016 12:08:12 +0200 Subject: [PATCH] Factor out MDB_SIZE_MAX, MDB_FMT_Y, MDB_FMT_Z --- libraries/liblmdb/lmdb.h | 19 +++++++++++++++++++ libraries/liblmdb/mdb.c | 13 ++----------- libraries/liblmdb/mdb_dump.c | 15 +-------------- libraries/liblmdb/mdb_load.c | 16 ++-------------- libraries/liblmdb/mdb_stat.c | 16 ++-------------- libraries/liblmdb/midl.h | 9 ++------- 6 files changed, 28 insertions(+), 60 deletions(-) diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h index d30ab648b3..92dd753d36 100644 --- a/libraries/liblmdb/lmdb.h +++ b/libraries/liblmdb/lmdb.h @@ -179,13 +179,32 @@ typedef int mdb_mode_t; typedef mode_t mdb_mode_t; #endif +#ifdef _WIN32 +# define MDB_FMT_Z "I" +#else +# define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */ +#endif + #ifdef MDB_VL32 typedef uint64_t mdb_size_t; +#define MDB_SIZE_MAX UINT64_MAX +#ifdef _WIN32 +# define MDB_FMT_Y "I64" +#else +# define MDB_FMT_Y "ll" +#endif #define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */ #else typedef size_t mdb_size_t; +# define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */ +# define MDB_FMT_Y MDB_FMT_Z /**< Obsolescent, see #MDB_PRIz()/#MDB_SCNz() */ #endif +/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */ +#define MDB_PRIz(t) MDB_FMT_Y #t +/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */ +#define MDB_SCNz(t) MDB_FMT_Y #t + /** An abstraction for a file handle. * On POSIX systems file handles are small integers. On Windows * they're opaque pointers. diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index df31780d0c..01c259f849 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -355,12 +355,10 @@ typedef HANDLE mdb_mutex_t, mdb_mutexref_t; #else #define MDB_PROCESS_QUERY_LIMITED_INFORMATION 0x1000 #endif -#define Z "I" #else #define THREAD_RET void * #define THREAD_CREATE(thr,start,arg) pthread_create(&thr,NULL,start,arg) #define THREAD_FINISH(thr) pthread_join(thr,NULL) -#define Z "z" /**< printf format modifier for size_t */ /** For MDB_LOCK_FORMAT: True if readers take a pid lock in the lockfile */ #define MDB_PIDLOCK 1 @@ -458,15 +456,8 @@ typedef pthread_mutex_t mdb_mutex_t[1], *mdb_mutexref_t; #define GET_PAGESIZE(x) ((x) = sysconf(_SC_PAGE_SIZE)) #endif -#ifdef MDB_VL32 -#ifdef _WIN32 -#define Y "I64" -#else -#define Y "ll" -#endif -#else -#define Y Z -#endif +#define Z MDB_FMT_Z /**< printf/scanf format modifier for size_t */ +#define Y MDB_FMT_Y /**< printf/scanf format modifier for #mdb_size_t */ #if defined(_WIN32) || defined(MDB_USE_POSIX_SEM) #define MNAME_LEN 32 diff --git a/libraries/liblmdb/mdb_dump.c b/libraries/liblmdb/mdb_dump.c index 5f3125fa2a..538b243950 100644 --- a/libraries/liblmdb/mdb_dump.c +++ b/libraries/liblmdb/mdb_dump.c @@ -20,20 +20,7 @@ #include #include "lmdb.h" -#ifdef _WIN32 -#define Z "I" -#else -#define Z "z" -#endif -#ifdef MDB_VL32 -#ifdef _WIN32 -#define Y "I64" -#else -#define Y "ll" -#endif -#else -#define Y Z -#endif +#define Y MDB_FMT_Y #define PRINT 1 static int mode; diff --git a/libraries/liblmdb/mdb_load.c b/libraries/liblmdb/mdb_load.c index 27aee40290..fe1d846b53 100644 --- a/libraries/liblmdb/mdb_load.c +++ b/libraries/liblmdb/mdb_load.c @@ -38,20 +38,8 @@ static MDB_envinfo info; static MDB_val kbuf, dbuf; -#ifdef _WIN32 -#define Z "I" -#else -#define Z "z" -#endif -#ifdef MDB_VL32 -#ifdef _WIN32 -#define Y "I64" -#else -#define Y "ll" -#endif -#else -#define Y Z -#endif +#define Z MDB_FMT_Z +#define Y MDB_FMT_Y #define STRLENOF(s) (sizeof(s)-1) diff --git a/libraries/liblmdb/mdb_stat.c b/libraries/liblmdb/mdb_stat.c index de5c3b514c..11c9e481d7 100644 --- a/libraries/liblmdb/mdb_stat.c +++ b/libraries/liblmdb/mdb_stat.c @@ -17,20 +17,8 @@ #include #include "lmdb.h" -#ifdef _WIN32 -#define Z "I" -#else -#define Z "z" -#endif -#ifdef MDB_VL32 -#ifdef _WIN32 -#define Y "I64" -#else -#define Y "ll" -#endif -#else -#define Y Z -#endif +#define Z MDB_FMT_Z +#define Y MDB_FMT_Y static void prstat(MDB_stat *ms) { diff --git a/libraries/liblmdb/midl.h b/libraries/liblmdb/midl.h index b0d518ef03..dc532c44ff 100644 --- a/libraries/liblmdb/midl.h +++ b/libraries/liblmdb/midl.h @@ -26,8 +26,7 @@ #ifndef _MDB_MIDL_H_ #define _MDB_MIDL_H_ -#include -#include +#include "lmdb.h" #ifdef __cplusplus extern "C" { @@ -43,11 +42,7 @@ extern "C" { /** A generic unsigned ID number. These were entryIDs in back-bdb. * Preferably it should have the same size as a pointer. */ -#ifdef MDB_VL32 -typedef uint64_t MDB_ID; -#else -typedef size_t MDB_ID; -#endif +typedef mdb_size_t MDB_ID; /** An IDL is an ID List, a sorted array of IDs. The first * element of the array is a counter for how many actual -- 2.39.5