Skip to content

Commit

Permalink
Wrap ffi functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dureuill committed Nov 17, 2022
1 parent 3db2bfa commit 2877761
Showing 1 changed file with 155 additions and 30 deletions.
185 changes: 155 additions & 30 deletions heed/src/mdb/lmdb_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,163 @@ pub use ffi::{
MDB_CREATE,
MDB_CURRENT,
MDB_RDONLY,

mdb_env_close,
mdb_env_copyfd2 as mdb_env_copy2fd,
mdb_env_create,
mdb_env_get_flags,
mdb_env_info,
mdb_env_open,
mdb_env_set_mapsize,
mdb_env_set_maxdbs,
mdb_env_set_maxreaders,
mdb_env_stat,
mdb_env_sync,

mdb_dbi_close,
mdb_dbi_open,
mdb_del,
mdb_drop,
mdb_get,
mdb_put,
mdb_stat,

mdb_txn_abort,
mdb_txn_begin,
mdb_txn_commit,

mdb_cursor_close,
mdb_cursor_del,
mdb_cursor_get,
mdb_cursor_open,
mdb_cursor_put
};

pub unsafe fn mdb_env_close(env: *mut MDB_env) {
ffi::mdb_env_close(env)
}

pub unsafe fn mdb_env_copy2fd(
env: *mut MDB_env,
fd: mdb_filehandle_t,
flags: ::libc::c_uint,
) -> ::libc::c_int {
ffi::mdb_env_copyfd2(env, fd, flags)
}

pub unsafe fn mdb_env_create(env: *mut *mut MDB_env) -> ::libc::c_int {
ffi::mdb_env_create(env)
}

pub unsafe fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut ::libc::c_uint) -> ::libc::c_int {
ffi::mdb_env_get_flags(env, flags)
}

// FIXME: should we expose ffi::MDB_envinfo as this function cannot be called without it? 🤔
pub unsafe fn mdb_env_info(env: *mut MDB_env, stat: *mut ffi::MDB_envinfo) -> ::libc::c_int {
ffi::mdb_env_info(env, stat)
}

pub unsafe fn mdb_env_open(
env: *mut MDB_env,
path: *const ::libc::c_char,
flags: ::libc::c_uint,
mode: ffi::mdb_mode_t,
) -> ::libc::c_int {
ffi::mdb_env_open(env, path, flags, mode)
}

pub unsafe fn mdb_env_set_mapsize(env: *mut MDB_env, size: ffi::mdb_size_t) -> ::libc::c_int {
ffi::mdb_env_set_mapsize(env, size)
}

pub unsafe fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> ::libc::c_int {
ffi::mdb_env_set_maxdbs(env, dbs)
}

pub unsafe fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: ::libc::c_uint) -> ::libc::c_int {
ffi::mdb_env_set_maxreaders(env, readers)
}

pub unsafe fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> ::libc::c_int {
ffi::mdb_env_stat(env, stat)
}

pub unsafe fn mdb_env_sync(env: *mut MDB_env, force: ::libc::c_int) -> ::libc::c_int {
ffi::mdb_env_sync(env, force)
}

pub unsafe fn mdb_dbi_close(env: *mut MDB_env, dbi: MDB_dbi) {
ffi::mdb_dbi_close(env, dbi)
}

pub unsafe fn mdb_dbi_open(
txn: *mut MDB_txn,
name: *const ::libc::c_char,
flags: ::libc::c_uint,
dbi: *mut MDB_dbi,
) -> ::libc::c_int {
ffi::mdb_dbi_open(txn, name, flags, dbi)
}

pub unsafe fn mdb_del(
txn: *mut MDB_txn,
dbi: MDB_dbi,
key: *mut ffi::MDB_val,
data: *mut ffi::MDB_val,
) -> ::libc::c_int {
ffi::mdb_del(txn, dbi, key, data)
}

pub unsafe fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: ::libc::c_int) -> ::libc::c_int {
ffi::mdb_drop(txn, dbi, del)
}

pub unsafe fn mdb_get(
txn: *mut MDB_txn,
dbi: MDB_dbi,
key: *mut ffi::MDB_val,
data: *mut ffi::MDB_val,
) -> ::libc::c_int {
ffi::mdb_get(txn, dbi, key, data)
}

// FIXME: should we expose ffi::MDB_val as this function cannot be called without it? 🤔
pub unsafe fn mdb_put(
txn: *mut MDB_txn,
dbi: MDB_dbi,
key: *mut ffi::MDB_val,
data: *mut ffi::MDB_val,
flags: ::libc::c_uint,
) -> ::libc::c_int {
ffi::mdb_put(txn, dbi, key, data, flags)
}

pub unsafe fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> ::libc::c_int {
ffi::mdb_stat(txn, dbi, stat)
}

pub unsafe fn mdb_txn_abort(txn: *mut MDB_txn) {
ffi::mdb_txn_abort(txn)
}

pub unsafe fn mdb_txn_begin(
env: *mut MDB_env,
parent: *mut MDB_txn,
flags: ::libc::c_uint,
txn: *mut *mut MDB_txn,
) -> ::libc::c_int {
ffi::mdb_txn_begin(env, parent, flags, txn)
}

pub unsafe fn mdb_txn_commit(txn: *mut MDB_txn) -> ::libc::c_int {
ffi::mdb_txn_commit(txn)
}

pub unsafe fn mdb_cursor_close(cursor: *mut MDB_cursor) {
ffi::mdb_cursor_close(cursor)
}

pub unsafe fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: ::libc::c_uint) -> ::libc::c_int {
ffi::mdb_cursor_del(cursor, flags)
}

pub unsafe fn mdb_cursor_get(
cursor: *mut MDB_cursor,
key: *mut ffi::MDB_val,
data: *mut ffi::MDB_val,
op: ffi::MDB_cursor_op,
) -> ::libc::c_int {
ffi::mdb_cursor_get(cursor, key, data, op)
}

pub unsafe fn mdb_cursor_open(
txn: *mut MDB_txn,
dbi: MDB_dbi,
cursor: *mut *mut MDB_cursor,
) -> ::libc::c_int {
ffi::mdb_cursor_open(txn, dbi, cursor)
}

pub unsafe fn mdb_cursor_put(
cursor: *mut MDB_cursor,
key: *mut ffi::MDB_val,
data: *mut ffi::MDB_val,
flags: ::libc::c_uint,
) -> ::libc::c_int {
ffi::mdb_cursor_put(cursor, key, data, flags)
}

pub mod cursor_op {
use super::ffi::{self, MDB_cursor_op};

Expand Down

0 comments on commit 2877761

Please sign in to comment.