diff --git a/mdbx.h b/mdbx.h index 96e6e63e..160bef64 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1633,7 +1633,7 @@ LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, /*----------------------------------------------------------------------------*/ /* attribute support functions for Nexenta */ -typedef uint64_t mdbx_attr_t; +typedef uint_fast64_t mdbx_attr_t; /* Store by cursor with attribute. * @@ -1668,8 +1668,9 @@ typedef uint64_t mdbx_attr_t; * - 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. */ -int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, - mdbx_attr_t attr, unsigned flags); +LIBMDBX_API int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, + MDBX_val *data, mdbx_attr_t attr, + unsigned flags); /* Store items and attributes into a database. * @@ -1713,8 +1714,8 @@ int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, * - 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. */ -int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, - mdbx_attr_t attr, unsigned flags); +LIBMDBX_API int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, + MDBX_val *data, mdbx_attr_t attr, unsigned flags); /* Set items attribute from a database. * @@ -1733,8 +1734,8 @@ int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, * possible errors are: * - MDBX_NOTFOUND - the key-value pair was not in the database. * - MDBX_EINVAL - an invalid parameter was specified. */ -int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, - mdbx_attr_t attr); +LIBMDBX_API int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, + MDBX_val *data, mdbx_attr_t attr); /* Get items attribute from a database cursor. * @@ -1753,8 +1754,9 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, * possible errors are: * - MDBX_NOTFOUND - no matching key found. * - MDBX_EINVAL - an invalid parameter was specified. */ -int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data, - mdbx_attr_t *attrptr, MDBX_cursor_op op); +LIBMDBX_API int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, + MDBX_val *data, mdbx_attr_t *attrptr, + MDBX_cursor_op op); /* Get items attribute from a database. * @@ -1782,8 +1784,8 @@ int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data, * possible errors are: * - MDBX_NOTFOUND - the key was not in the database. * - MDBX_EINVAL - an invalid parameter was specified. */ -int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, - mdbx_attr_t *attrptr); +LIBMDBX_API int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, + MDBX_val *data, mdbx_attr_t *attrptr); #ifdef __cplusplus } diff --git a/src/mdbx.c b/src/mdbx.c index df7bec11..63c4b958 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -11151,9 +11151,9 @@ int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, mdbx_attr_t attr, unsigned flags) { - MDBX_val reserve = {.iov_base = NULL, - .iov_len = - (data ? data->iov_len : 0) + sizeof(mdbx_attr_t)}; + MDBX_val reserve; + reserve.iov_base = NULL; + reserve.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t); int rc = mdbx_put(txn, dbi, key, &reserve, flags | MDBX_RESERVE); if (unlikely(rc != MDBX_SUCCESS)) @@ -11164,9 +11164,9 @@ int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, mdbx_attr_t attr, unsigned flags) { - MDBX_val reserve = {.iov_base = NULL, - .iov_len = - (data ? data->iov_len : 0) + sizeof(mdbx_attr_t)}; + MDBX_val reserve; + reserve.iov_base = NULL; + reserve.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t); int rc = mdbx_cursor_put(cursor, key, &reserve, flags | MDBX_RESERVE); if (unlikely(rc != MDBX_SUCCESS)) @@ -11177,12 +11177,6 @@ int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, mdbx_attr_t attr) { - MDBX_cursor mc; - MDBX_xcursor mx; - MDBX_val old_data; - mdbx_attr_t old_attr; - int rc; - if (unlikely(!key || !txn)) return EINVAL; @@ -11195,8 +11189,11 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, if (unlikely(txn->mt_flags & (MDBX_TXN_RDONLY | MDBX_TXN_BLOCKED))) return (txn->mt_flags & MDBX_TXN_RDONLY) ? EACCES : MDBX_BAD_TXN; + MDBX_cursor mc; + MDBX_xcursor mx; + MDBX_val old_data; mdbx_cursor_init(&mc, txn, dbi, &mx); - rc = mdbx_cursor_set(&mc, key, &old_data, MDBX_SET, NULL); + int rc = mdbx_cursor_set(&mc, key, &old_data, MDBX_SET, NULL); if (unlikely(rc != MDBX_SUCCESS)) { if (rc == MDBX_NOTFOUND && data) { mc.mc_next = txn->mt_cursors[dbi]; @@ -11207,6 +11204,7 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, return rc; } + mdbx_attr_t old_attr; rc = mdbx_attr_peek(&old_data, &old_attr); if (unlikely(rc != MDBX_SUCCESS)) return rc;