mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-29 08:28:49 +08:00
mdbx: refine internal constant (use UINT32_C, etc minors).
Change-Id: I0f994ee75b5aa1494fcc8ca42a46120865676e25
This commit is contained in:
parent
f93818a926
commit
151d4540de
2
Makefile
2
Makefile
@ -73,7 +73,7 @@ clean:
|
||||
rm -rf $(TOOLS) test/test @* *.[ao] *.[ls]o *~ tmp.db/* *.gcov *.log *.err src/*.o test/*.o
|
||||
|
||||
check: test/test mdbx_chk
|
||||
rm -f $(TESTDB) && (set -o pipefail; test/test --pathname=$(TESTDB) --dont-cleanup-after basic | tee test.log | tail -n 42) && ./mdbx_chk -vn $(TESTDB)
|
||||
rm -f $(TESTDB) test.log && (set -o pipefail; test/test --pathname=$(TESTDB) --dont-cleanup-after basic | tee -a test.log | tail -n 42) && ./mdbx_chk -vn $(TESTDB)
|
||||
|
||||
define core-rule
|
||||
$(patsubst %.c,%.o,$(1)): $(1) $(CORE_INC) mdbx.h Makefile
|
||||
|
25
src/bits.h
25
src/bits.h
@ -113,6 +113,7 @@
|
||||
#define MAIN_DBI 1
|
||||
/* Number of DBs in metapage (free and main) - also hardcoded elsewhere */
|
||||
#define CORE_DBS 2
|
||||
#define MAX_DBI (INT16_MAX - CORE_DBS)
|
||||
|
||||
/* Number of meta pages - also hardcoded elsewhere */
|
||||
#define NUM_METAS 3
|
||||
@ -142,6 +143,8 @@ typedef uint64_t txnid_t;
|
||||
* this is plenty. */
|
||||
typedef uint16_t indx_t;
|
||||
|
||||
#define MEGABYTE ((size_t)1 << 20)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Core structures for database and shared memory (i.e. format definition) */
|
||||
#pragma pack(push, 1)
|
||||
@ -472,8 +475,8 @@ typedef struct MDBX_dbx {
|
||||
/* A database transaction.
|
||||
* Every operation requires a transaction handle. */
|
||||
struct MDBX_txn {
|
||||
#define MDBX_MT_SIGNATURE (0x93D53A31)
|
||||
unsigned mt_signature;
|
||||
#define MDBX_MT_SIGNATURE UINT32_C(0x93D53A31)
|
||||
uint32_t mt_signature;
|
||||
MDBX_txn *mt_parent; /* parent of a nested txn */
|
||||
/* Nested txn under this txn, set together with flag MDBX_TXN_HAS_CHILD */
|
||||
MDBX_txn *mt_child;
|
||||
@ -567,10 +570,10 @@ struct MDBX_xcursor;
|
||||
* Exception: An xcursor's pointer to a P_SUBP page can be stale.
|
||||
* (A node with F_DUPDATA but no F_SUBDATA contains a subpage). */
|
||||
struct MDBX_cursor {
|
||||
#define MDBX_MC_SIGNATURE (0xFE05D5B1)
|
||||
#define MDBX_MC_READY4CLOSE (0x2817A047)
|
||||
#define MDBX_MC_WAIT4EOT (0x90E297A7)
|
||||
unsigned mc_signature;
|
||||
#define MDBX_MC_SIGNATURE UINT32_C(0xFE05D5B1)
|
||||
#define MDBX_MC_READY4CLOSE UINT32_C(0x2817A047)
|
||||
#define MDBX_MC_WAIT4EOT UINT32_C(0x90E297A7)
|
||||
uint32_t mc_signature;
|
||||
/* Next cursor on this DB in this txn */
|
||||
MDBX_cursor *mc_next;
|
||||
/* Backup of the original cursor if this cursor is a shadow */
|
||||
@ -639,16 +642,16 @@ typedef struct MDBX_pgstate {
|
||||
|
||||
/* The database environment. */
|
||||
struct MDBX_env {
|
||||
#define MDBX_ME_SIGNATURE (0x9A899641)
|
||||
unsigned me_signature;
|
||||
#define MDBX_ME_SIGNATURE UINT32_C(0x9A899641)
|
||||
uint32_t me_signature;
|
||||
mdbx_filehandle_t me_fd; /* The main data file */
|
||||
mdbx_filehandle_t me_lfd; /* The lock file */
|
||||
/* Failed to update the meta page. Probably an I/O error. */
|
||||
#define MDBX_FATAL_ERROR 0x80000000U
|
||||
#define MDBX_FATAL_ERROR UINT32_C(0x80000000)
|
||||
/* Some fields are initialized. */
|
||||
#define MDBX_ENV_ACTIVE 0x20000000U
|
||||
#define MDBX_ENV_ACTIVE UINT32_C(0x20000000)
|
||||
/* me_txkey is set */
|
||||
#define MDBX_ENV_TXKEY 0x10000000U
|
||||
#define MDBX_ENV_TXKEY UINT32_C(0x10000000)
|
||||
uint32_t me_flags; /* see mdbx_env */
|
||||
unsigned me_psize; /* DB page size, inited from me_os_psize */
|
||||
unsigned me_psize2log; /* log2 of DB page size */
|
||||
|
12
src/mdbx.c
12
src/mdbx.c
@ -1380,9 +1380,7 @@ static __inline void mdbx_meta_set_txnid(const MDBX_env *env, MDBX_meta *meta,
|
||||
static __inline uint64_t mdbx_meta_sign(const MDBX_meta *meta) {
|
||||
uint64_t sign = MDBX_DATASIGN_NONE;
|
||||
#if 0 /* TODO */
|
||||
sign = hippeus_hash64(&meta->mm_mapsize,
|
||||
sizeof(MDBX_meta) - offsetof(MDBX_meta, mm_mapsize),
|
||||
meta->mm_version | (uint64_t)MDBX_DXD_MAGIC << 32);
|
||||
sign = hippeus_hash64(...);
|
||||
#else
|
||||
(void)meta;
|
||||
#endif
|
||||
@ -4060,6 +4058,9 @@ int __cold mdbx_env_set_mapsize(MDBX_env *env, size_t size) {
|
||||
}
|
||||
|
||||
int __cold mdbx_env_set_maxdbs(MDBX_env *env, MDBX_dbi dbs) {
|
||||
if (unlikely(dbs > MAX_DBI))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(!env))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
@ -4961,6 +4962,7 @@ static int mdbx_page_get(MDBX_cursor *mc, pgno_t pgno, MDBX_page **ret,
|
||||
|
||||
mapped:
|
||||
p = pgno2page(env, pgno);
|
||||
/* TODO: check p->mp_validator here */
|
||||
|
||||
done:
|
||||
*ret = p;
|
||||
@ -9759,7 +9761,7 @@ int __cold mdbx_reader_check(MDBX_env *env, int *dead) {
|
||||
return MDBX_EINVAL;
|
||||
if (dead)
|
||||
*dead = 0;
|
||||
return mdbx_reader_check0(env, 0, dead);
|
||||
return mdbx_reader_check0(env, false, dead);
|
||||
}
|
||||
|
||||
/* Return:
|
||||
@ -10164,7 +10166,7 @@ int __cold mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
|
||||
ctx.mw_user = user;
|
||||
ctx.mw_visitor = visitor;
|
||||
|
||||
int rc = visitor(0, NUM_METAS, user, "mdbx", "meta", NUM_METAS,
|
||||
int rc = visitor(0, NUM_METAS, user, "meta", "meta", NUM_METAS,
|
||||
sizeof(MDBX_meta) * NUM_METAS, PAGEHDRSZ * NUM_METAS,
|
||||
(txn->mt_env->me_psize - sizeof(MDBX_meta) - PAGEHDRSZ) *
|
||||
NUM_METAS);
|
||||
|
@ -48,8 +48,6 @@ static void signal_handler(int sig) {
|
||||
gotsignal = 1;
|
||||
}
|
||||
|
||||
#define MAX_DBI 32768
|
||||
|
||||
#define EXIT_INTERRUPTED (EXIT_FAILURE + 4)
|
||||
#define EXIT_FAILURE_SYS (EXIT_FAILURE + 3)
|
||||
#define EXIT_FAILURE_MDB (EXIT_FAILURE + 2)
|
||||
@ -809,7 +807,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
rc = mdbx_env_set_maxdbs(env, MAX_DBI);
|
||||
if (rc < 0) {
|
||||
if (rc) {
|
||||
error("mdbx_env_set_maxdbs failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
goto bailout;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user