mdbx: cleanup mdbx_env_create().

This commit is contained in:
Leo Yuriev 2017-05-18 04:58:02 +03:00
parent 6ee3aebc32
commit 818e742c58
2 changed files with 14 additions and 16 deletions

2
mdbx.h
View File

@ -386,7 +386,7 @@ LIBMDBX_API const char *mdbx_strerror_r(int errnum, char *buf, size_t buflen);
* [out] env The address where the new handle will be stored
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_env_create(MDB_env **env);
LIBMDBX_API int mdbx_env_create(MDB_env **penv);
/* Open an environment handle.
*

View File

@ -3614,25 +3614,23 @@ static void __cold mdbx_env_setup_limits(MDB_env *env, size_t pagesize) {
assert(env->me_maxkey_limit > 42 && env->me_maxkey_limit < pagesize);
}
int __cold mdbx_env_create(MDB_env **env) {
MDB_env *e;
e = calloc(1, sizeof(MDB_env));
if (!e)
int __cold mdbx_env_create(MDB_env **penv) {
MDB_env *env = calloc(1, sizeof(MDB_env));
if (!env)
return MDBX_ENOMEM;
e->me_maxreaders = DEFAULT_READERS;
e->me_maxdbs = e->me_numdbs = CORE_DBS;
e->me_fd = INVALID_HANDLE_VALUE;
e->me_lfd = INVALID_HANDLE_VALUE;
e->me_pid = mdbx_getpid();
mdbx_env_setup_limits(e, e->me_os_psize = mdbx_syspagesize());
if (!is_power2(e->me_os_psize))
env->me_maxreaders = DEFAULT_READERS;
env->me_maxdbs = env->me_numdbs = CORE_DBS;
env->me_fd = INVALID_HANDLE_VALUE;
env->me_lfd = INVALID_HANDLE_VALUE;
env->me_pid = mdbx_getpid();
mdbx_env_setup_limits(env, env->me_os_psize = mdbx_syspagesize());
if (!is_power2(env->me_os_psize))
return MDB_INCOMPATIBLE;
VALGRIND_CREATE_MEMPOOL(e, 0, 0);
e->me_signature = MDBX_ME_SIGNATURE;
*env = e;
VALGRIND_CREATE_MEMPOOL(env, 0, 0);
env->me_signature = MDBX_ME_SIGNATURE;
*penv = env;
return MDB_SUCCESS;
}