Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MDB_VL32 support. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions include/lmdbxx/lmdb++.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@

namespace lmdb {
using mode = mdb_mode_t;
/*
* LMDB 0.9.x neither has mdb_size_t nor supports MDB_VL32.
* It can be detected by checking if MDB_SIZE_MAX is defined.
*/
#ifdef MDB_SIZE_MAX
using size_t = mdb_size_t;
#elif defined(MDB_VL32)
#error "Although MDB_VL32 is defined, it is not supported by the underlying LMDB version."
#else
using size_t = std::size_t;
#endif
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -246,7 +257,7 @@ namespace lmdb {
static inline void env_get_flags(MDB_env* env, unsigned int* flags);
static inline void env_get_path(MDB_env* env, const char** path);
static inline void env_get_fd(MDB_env* env, mdb_filehandle_t* fd);
static inline void env_set_mapsize(MDB_env* env, std::size_t size);
static inline void env_set_mapsize(MDB_env* env, lmdb::size_t size);
static inline void env_set_max_readers(MDB_env* env, unsigned int count);
static inline void env_get_max_readers(MDB_env* env, unsigned int* count);
static inline void env_set_max_dbs(MDB_env* env, MDB_dbi count);
Expand Down Expand Up @@ -433,7 +444,7 @@ lmdb::env_get_fd(MDB_env* const env,
*/
static inline void
lmdb::env_set_mapsize(MDB_env* const env,
const std::size_t size) {
const lmdb::size_t size) {
const int rc = ::mdb_env_set_mapsize(env, size);
if (rc != MDB_SUCCESS) {
error::raise("mdb_env_set_mapsize", rc);
Expand Down Expand Up @@ -534,7 +545,7 @@ namespace lmdb {
MDB_env* env, MDB_txn* parent, unsigned int flags, MDB_txn** txn);
static inline MDB_env* txn_env(MDB_txn* txn) noexcept;
#ifdef LMDBXX_TXN_ID
static inline std::size_t txn_id(MDB_txn* txn) noexcept;
static inline lmdb::size_t txn_id(MDB_txn* txn) noexcept;
#endif
static inline void txn_commit(MDB_txn* txn);
static inline void txn_abort(MDB_txn* txn) noexcept;
Expand Down Expand Up @@ -569,7 +580,7 @@ lmdb::txn_env(MDB_txn* const txn) noexcept {
/**
* @note Only available in HEAD, not yet in any 0.9.x release (as of 0.9.16).
*/
static inline std::size_t
static inline lmdb::size_t
lmdb::txn_id(MDB_txn* const txn) noexcept {
return ::mdb_txn_id(txn);
}
Expand Down Expand Up @@ -821,7 +832,7 @@ namespace lmdb {
static inline bool cursor_get(MDB_cursor* cursor, MDB_val* key, MDB_val* data, MDB_cursor_op op);
static inline bool cursor_put(MDB_cursor* cursor, MDB_val* key, MDB_val* data, unsigned int flags);
static inline void cursor_del(MDB_cursor* cursor, unsigned int flags);
static inline void cursor_count(MDB_cursor* cursor, std::size_t& count);
static inline void cursor_count(MDB_cursor* cursor, lmdb::size_t& count);
}

/**
Expand Down Expand Up @@ -926,7 +937,7 @@ lmdb::cursor_del(MDB_cursor* const cursor,
*/
static inline void
lmdb::cursor_count(MDB_cursor* const cursor,
std::size_t& count) {
lmdb::size_t& count) {
const int rc = ::mdb_cursor_count(cursor, &count);
if (rc != MDB_SUCCESS) {
error::raise("mdb_cursor_count", rc);
Expand Down Expand Up @@ -1083,7 +1094,7 @@ class lmdb::env {
* @param size
* @throws lmdb::error on failure
*/
env& set_mapsize(const std::size_t size) {
env& set_mapsize(const lmdb::size_t size) {
lmdb::env_set_mapsize(handle(), size);
return *this;
}
Expand Down Expand Up @@ -1388,7 +1399,7 @@ class lmdb::dbi {
* @param txn a transaction handle
* @throws lmdb::error on failure
*/
std::size_t size(MDB_txn* const txn) const {
lmdb::size_t size(MDB_txn* const txn) const {
return stat(txn).ms_entries;
}

Expand Down Expand Up @@ -1674,8 +1685,8 @@ class lmdb::cursor {
/**
* Return count of duplicates for current key. This call is only valid on databases that support sorted duplicate data items MDB_DUPSORT.
*/
size_t count() {
std::size_t countp;
lmdb::size_t count() {
lmdb::size_t countp;
lmdb::cursor_count(handle(), countp);
return countp;
}
Expand Down