mdbx: more 'const' for API.

Change-Id: Iedea253733105acc4010e07a65a594f8ea52ce56
This commit is contained in:
Leonid Yuriev
2020-04-18 20:16:37 +03:00
parent 90bf7eb817
commit 1e9cc6b0a5
2 changed files with 81 additions and 76 deletions

74
mdbx.h
View File

@@ -1944,7 +1944,7 @@ LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, unsigned flags, int onoff);
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_env_get_flags(MDBX_env *env, unsigned *flags);
LIBMDBX_API int mdbx_env_get_flags(const MDBX_env *env, unsigned *flags);
/* Return the path that was used in mdbx_env_open().
*
@@ -1956,7 +1956,7 @@ LIBMDBX_API int mdbx_env_get_flags(MDBX_env *env, unsigned *flags);
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_env_get_path(MDBX_env *env, const char **dest);
LIBMDBX_API int mdbx_env_get_path(const MDBX_env *env, const char **dest);
/* Return the file descriptor for the given environment.
*
@@ -1969,7 +1969,7 @@ LIBMDBX_API int mdbx_env_get_path(MDBX_env *env, const char **dest);
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_env_get_fd(MDBX_env *env, mdbx_filehandle_t *fd);
LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd);
/* Set all size-related parameters of environment, including page size and the
* min/max size of the memory map.
@@ -2222,7 +2222,7 @@ LIBMDBX_API int mdbx_env_set_maxreaders(MDBX_env *env, unsigned readers);
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_env_get_maxreaders(MDBX_env *env, unsigned *readers);
LIBMDBX_API int mdbx_env_get_maxreaders(const MDBX_env *env, unsigned *readers);
/* Set the maximum number of named databases for the environment.
*
@@ -2253,9 +2253,9 @@ LIBMDBX_API int mdbx_env_set_maxdbs(MDBX_env *env, MDBX_dbi dbs);
*
* Returns The maximum size of a key we can write,
* or -1 if something is wrong. */
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(MDBX_env *env, unsigned flags);
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(MDBX_env *env, unsigned flags);
__deprecated LIBMDBX_API int mdbx_env_get_maxkeysize(MDBX_env *env);
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, unsigned flags);
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(const MDBX_env *env, unsigned flags);
__deprecated LIBMDBX_API int mdbx_env_get_maxkeysize(const MDBX_env *env);
/* Set application information associated with the MDBX_env.
*
@@ -2269,7 +2269,7 @@ LIBMDBX_API int mdbx_env_set_userctx(MDBX_env *env, void *ctx);
*
* [in] env An environment handle returned by mdbx_env_create()
* Returns The pointer set by mdbx_env_set_userctx(). */
LIBMDBX_API void *mdbx_env_get_userctx(MDBX_env *env);
LIBMDBX_API void *mdbx_env_get_userctx(const MDBX_env *env);
/* Create a transaction for use with the environment.
*
@@ -2382,12 +2382,13 @@ typedef struct MDBX_txn_info {
* not needed (see description of MDBX_txn_info above).
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_txn_info(MDBX_txn *txn, MDBX_txn_info *info, int scan_rlt);
LIBMDBX_API int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info,
int scan_rlt);
/* Returns the transaction's MDBX_env.
*
* [in] txn A transaction handle returned by mdbx_txn_begin() */
LIBMDBX_API MDBX_env *mdbx_txn_env(MDBX_txn *txn);
LIBMDBX_API MDBX_env *mdbx_txn_env(const MDBX_txn *txn);
/* Return the transaction's flags.
*
@@ -2397,7 +2398,7 @@ LIBMDBX_API MDBX_env *mdbx_txn_env(MDBX_txn *txn);
*
* Returns A transaction flags, valid if input is an valid transaction,
* otherwise -1. */
LIBMDBX_API int mdbx_txn_flags(MDBX_txn *txn);
LIBMDBX_API int mdbx_txn_flags(const MDBX_txn *txn);
/* Return the transaction's ID.
*
@@ -2409,7 +2410,7 @@ LIBMDBX_API int mdbx_txn_flags(MDBX_txn *txn);
*
* Returns A transaction ID, valid if input is an active transaction,
* otherwise 0. */
LIBMDBX_API uint64_t mdbx_txn_id(MDBX_txn *txn);
LIBMDBX_API uint64_t mdbx_txn_id(const MDBX_txn *txn);
/* Commit all the operations of a transaction into the database.
*
@@ -2516,7 +2517,7 @@ LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const mdbx_canary *canary);
* will be copied.
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_canary_get(MDBX_txn *txn, mdbx_canary *canary);
LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, mdbx_canary *canary);
/* A callback function used to compare two keys in a database */
typedef int(MDBX_cmp_func)(const MDBX_val *a, const MDBX_val *b);
@@ -2732,7 +2733,7 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del);
* possible errors are:
* - MDBX_NOTFOUND = the key was not in the database.
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *data);
/* Get items from a database and optionaly number of data items for a given key.
@@ -2844,7 +2845,7 @@ LIBMDBX_API int mdbx_get_nearest(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
* - MDBX_TXN_FULL = the transaction has too many dirty pages.
* - MDBX_EACCES = an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *data, unsigned flags);
/* Replace items in a database.
@@ -2883,7 +2884,7 @@ LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
* multi-value/duplicates.
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *new_data, MDBX_val *old_data,
unsigned flags);
@@ -2907,8 +2908,8 @@ LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
* possible errors are:
* - MDBX_EACCES = an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
MDBX_val *data);
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
const MDBX_val *data);
/* Create a cursor handle.
*
@@ -2972,12 +2973,12 @@ LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor);
/* Return the cursor's transaction handle.
*
* [in] cursor A cursor handle returned by mdbx_cursor_open(). */
LIBMDBX_API MDBX_txn *mdbx_cursor_txn(MDBX_cursor *cursor);
LIBMDBX_API MDBX_txn *mdbx_cursor_txn(const MDBX_cursor *cursor);
/* Return the cursor's database handle.
*
* [in] cursor A cursor handle returned by mdbx_cursor_open(). */
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(MDBX_cursor *cursor);
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor);
/* Retrieve by cursor.
*
@@ -3004,11 +3005,11 @@ LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key,
* This function stores key/data pairs into the database. The cursor is
* positioned at the new item, or on failure usually near it.
*
* [in] cursor A cursor handle returned by mdbx_cursor_open().
* [in] key The key operated on.
* [in] data The data operated on.
* [in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here:
* [in] cursor A cursor handle returned by mdbx_cursor_open().
* [in] key The key operated on.
* [in,out] data The data operated on.
* [in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here:
*
* - MDBX_CURRENT
* Replace the item at the current cursor position. The key parameter
@@ -3065,7 +3066,7 @@ LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key,
* - MDBX_TXN_FULL = the transaction has too many dirty pages.
* - MDBX_EACCES = an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL = an invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, MDBX_val *key,
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key,
MDBX_val *data, unsigned flags);
/* Delete current key/data pair.
@@ -3101,7 +3102,7 @@ LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, unsigned flags);
* possible errors are:
* - MDBX_EINVAL = cursor is not initialized, or an invalid parameter
* was specified. */
LIBMDBX_API int mdbx_cursor_count(MDBX_cursor *cursor, size_t *countp);
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *countp);
/* Determines whether the cursor is pointed to a key-value pair or not,
* i.e. was not positioned or points to the end of data.
@@ -3112,7 +3113,7 @@ LIBMDBX_API int mdbx_cursor_count(MDBX_cursor *cursor, size_t *countp);
* - MDBX_RESULT_TRUE = no more data available or cursor not positioned;
* - MDBX_RESULT_FALSE = data available;
* - Otherwise the error code. */
LIBMDBX_API int mdbx_cursor_eof(MDBX_cursor *mc);
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *mc);
/* Determines whether the cursor is pointed to the first key-value pair or not.
*
@@ -3122,7 +3123,7 @@ LIBMDBX_API int mdbx_cursor_eof(MDBX_cursor *mc);
* - MDBX_RESULT_TRUE = cursor positioned to the first key-value pair.
* - MDBX_RESULT_FALSE = cursor NOT positioned to the first key-value pair.
* - Otherwise the error code. */
LIBMDBX_API int mdbx_cursor_on_first(MDBX_cursor *mc);
LIBMDBX_API int mdbx_cursor_on_first(const MDBX_cursor *mc);
/* Determines whether the cursor is pointed to the last key-value pair or not.
*
@@ -3132,7 +3133,7 @@ LIBMDBX_API int mdbx_cursor_on_first(MDBX_cursor *mc);
* - MDBX_RESULT_TRUE = cursor positioned to the last key-value pair.
* - MDBX_RESULT_FALSE = cursor NOT positioned to the last key-value pair.
* - Otherwise the error code. */
LIBMDBX_API int mdbx_cursor_on_last(MDBX_cursor *mc);
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *mc);
/* Estimates the distance between cursors as a number of elements. The results
* of such estimation can be used to build and/or optimize query execution
@@ -3287,7 +3288,7 @@ LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
* [in] b The second item to compare.
*
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
LIBMDBX_API int mdbx_cmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
const MDBX_val *b);
/* Compare two data items according to a particular database.
@@ -3301,7 +3302,7 @@ LIBMDBX_API int mdbx_cmp(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
* [in] b The second item to compare.
*
* Returns < 0 if a < b, 0 if a == b, > 0 if a > b */
LIBMDBX_API int mdbx_dcmp(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
LIBMDBX_API int mdbx_dcmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
const MDBX_val *b);
/* A callback function used to enumerate the reader lock table.
@@ -3337,8 +3338,8 @@ typedef int(MDBX_reader_list_func)(void *ctx, int num, int slot, mdbx_pid_t pid,
*
* Returns A non-zero error value on failure and 0 on success,
* or MDBX_RESULT_TRUE (-1) if the reader lock table is empty. */
LIBMDBX_API int mdbx_reader_list(MDBX_env *env, MDBX_reader_list_func *func,
void *ctx);
LIBMDBX_API int mdbx_reader_list(const MDBX_env *env,
MDBX_reader_list_func *func, void *ctx);
/* Check for stale entries in the reader lock table.
*
@@ -3360,7 +3361,8 @@ LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead);
*
* Returns Number of transactions committed after the given was started for
* read, or negative value on failure. */
__deprecated LIBMDBX_API int mdbx_txn_straggler(MDBX_txn *txn, int *percent);
__deprecated LIBMDBX_API int mdbx_txn_straggler(const MDBX_txn *txn,
int *percent);
/* A lack-of-space callback function to resolve issues with a laggard readers.
*
@@ -3433,7 +3435,7 @@ LIBMDBX_API int mdbx_env_set_oomfunc(MDBX_env *env, MDBX_oom_func *oom_func);
* [in] env An environment handle returned by mdbx_env_create().
*
* Returns A MDBX_oom_func function or NULL if disabled. */
LIBMDBX_API MDBX_oom_func *mdbx_env_get_oomfunc(MDBX_env *env);
LIBMDBX_API MDBX_oom_func *mdbx_env_get_oomfunc(const MDBX_env *env);
/**** B-tree Traversal *********************************************************
* This is internal API for mdbx_chk tool. You should avoid to use it, except