diff --git a/src/bits.h b/src/bits.h index d17567f7..6f9c0cf0 100644 --- a/src/bits.h +++ b/src/bits.h @@ -120,6 +120,12 @@ /* *INDENT-ON* */ /* clang-format on */ +#if UINTPTR_MAX > 0xffffFFFFul || ULONG_MAX > 0xffffFFFFul +#define MDBX_WORDBITS 64 +#else +#define MDBX_WORDBITS 32 +#endif /* MDBX_WORDBITS */ + /*----------------------------------------------------------------------------*/ /* Basic constants and types */ @@ -163,7 +169,7 @@ * size up to 2^44 bytes, in case of 4K pages. */ typedef uint32_t pgno_t; #define PRIaPGNO PRIu32 -#define MAX_PAGENO ((pgno_t)UINT64_C(0xffffFFFFffff)) +#define MAX_PAGENO UINT32_C(0x7FFFffff) #define MIN_PAGENO NUM_METAS /* A transaction ID. */ @@ -392,11 +398,13 @@ typedef struct MDBX_page { #else #define MAX_MAPSIZE32 UINT32_C(0x7ff80000) #endif -#define MAX_MAPSIZE64 \ - ((sizeof(pgno_t) > 4) ? UINT64_C(0x7fffFFFFfff80000) \ - : MAX_PAGENO * (uint64_t)MAX_PAGESIZE) +#define MAX_MAPSIZE64 (MAX_PAGENO * (uint64_t)MAX_PAGESIZE) -#define MAX_MAPSIZE ((sizeof(size_t) < 8) ? MAX_MAPSIZE32 : MAX_MAPSIZE64) +#if MDBX_WORDBITS >= 64 +#define MAX_MAPSIZE MAX_MAPSIZE64 +#else +#define MAX_MAPSIZE MAX_MAPSIZE32 +#endif /* MDBX_WORDBITS */ /* The header for the reader table (a memory-mapped lock file). */ typedef struct MDBX_lockinfo {