without.crypto
Dan Burkert 7 years ago
parent c15f22c884
commit d0fda113ca
  1. 8
      src/cursor.rs
  2. 2
      src/database.rs
  3. 16
      src/environment.rs
  4. 17
      src/transaction.rs

@ -28,7 +28,7 @@ pub trait Cursor<'txn> {
let mut key_val = slice_to_val(key);
let mut data_val = slice_to_val(data);
let key_ptr = key_val.mv_data;
try!(lmdb_result(ffi::mdb_cursor_get(self.cursor(), &mut key_val, &mut data_val, op)));
lmdb_result(ffi::mdb_cursor_get(self.cursor(), &mut key_val, &mut data_val, op))?;
let key_out = if key_ptr != key_val.mv_data { Some(val_to_slice(key_val)) } else { None };
let data_out = val_to_slice(data_val);
Ok((key_out, data_out))
@ -91,7 +91,7 @@ pub trait Cursor<'txn> {
/// key.
fn iter_dup_of<K>(&mut self, key: &K) -> Result<Iter<'txn>> where K:
AsRef<[u8]> {
try!(self.get(Some(key.as_ref()), None, ffi::MDB_SET));
self.get(Some(key.as_ref()), None, ffi::MDB_SET)?;
Ok(Iter::new(self.cursor(), ffi::MDB_GET_CURRENT, ffi::MDB_NEXT_DUP))
}
}
@ -127,7 +127,7 @@ impl <'txn> RoCursor<'txn> {
#[doc(hidden)]
pub fn new<T>(txn: &'txn T, db: Database) -> Result<RoCursor<'txn>> where T: Transaction {
let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut();
unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); }
unsafe { lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))?; }
Ok(RoCursor {
cursor: cursor,
_marker: PhantomData,
@ -166,7 +166,7 @@ impl <'txn> RwCursor<'txn> {
#[doc(hidden)]
pub fn new<T>(txn: &'txn T, db: Database) -> Result<RwCursor<'txn>> where T: Transaction {
let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut();
unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); }
unsafe { lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))?; }
Ok(RwCursor { cursor: cursor, _marker: PhantomData })
}

@ -28,7 +28,7 @@ impl Database {
let c_name = name.map(|n| CString::new(n).unwrap());
let name_ptr = if let Some(ref c_name) = c_name { c_name.as_ptr() } else { ptr::null() };
let mut dbi: ffi::MDB_dbi = 0;
try!(lmdb_result(ffi::mdb_dbi_open(txn, name_ptr, flags, &mut dbi)));
lmdb_result(ffi::mdb_dbi_open(txn, name_ptr, flags, &mut dbi))?;
Ok(Database { dbi: dbi })
}

@ -76,9 +76,9 @@ impl Environment {
/// The database name may not contain the null character.
pub fn open_db<'env>(&'env self, name: Option<&str>) -> Result<Database> {
let mutex = self.dbi_open_mutex.lock();
let txn = try!(self.begin_ro_txn());
let db = unsafe { try!(txn.open_db(name)) };
try!(txn.commit());
let txn = self.begin_ro_txn()?;
let db = unsafe { txn.open_db(name)? };
txn.commit()?;
drop(mutex);
Ok(db)
}
@ -102,18 +102,18 @@ impl Environment {
flags: DatabaseFlags)
-> Result<Database> {
let mutex = self.dbi_open_mutex.lock();
let txn = try!(self.begin_rw_txn());
let db = unsafe { try!(txn.create_db(name, flags)) };
try!(txn.commit());
let txn = self.begin_rw_txn()?;
let db = unsafe { txn.create_db(name, flags)? };
txn.commit()?;
drop(mutex);
Ok(db)
}
pub fn get_db_flags<'env>(&'env self, db: Database) -> Result<DatabaseFlags> {
let txn = try!(self.begin_ro_txn());
let txn = self.begin_ro_txn()?;
let mut flags: c_uint = 0;
unsafe {
try!(lmdb_result(ffi::mdb_dbi_flags(txn.txn(), db.dbi(), &mut flags)));
lmdb_result(ffi::mdb_dbi_flags(txn.txn(), db.dbi(), &mut flags))?;
}
Ok(DatabaseFlags::from_bits(flags).unwrap())
}

@ -98,7 +98,7 @@ pub trait Transaction : Sized {
fn db_flags(&self, db: Database) -> Result<DatabaseFlags> {
let mut flags: c_uint = 0;
unsafe {
try!(lmdb_result(ffi::mdb_dbi_flags(self.txn(), db.dbi(), &mut flags)));
lmdb_result(ffi::mdb_dbi_flags(self.txn(), db.dbi(), &mut flags))?;
}
Ok(DatabaseFlags::from_bits_truncate(flags))
}
@ -130,10 +130,7 @@ impl <'env> RoTransaction<'env> {
pub fn new(env: &'env Environment) -> Result<RoTransaction<'env>> {
let mut txn: *mut ffi::MDB_txn = ptr::null_mut();
unsafe {
try!(lmdb_result(ffi::mdb_txn_begin(env.env(),
ptr::null_mut(),
ffi::MDB_RDONLY,
&mut txn)));
lmdb_result(ffi::mdb_txn_begin(env.env(), ptr::null_mut(), ffi::MDB_RDONLY, &mut txn))?;
Ok(RoTransaction { txn: txn, _marker: PhantomData })
}
}
@ -195,7 +192,7 @@ impl <'env> InactiveTransaction<'env> {
let txn = self.txn;
unsafe {
mem::forget(self);
try!(lmdb_result(ffi::mdb_txn_renew(txn)))
lmdb_result(ffi::mdb_txn_renew(txn))?
};
Ok(RoTransaction { txn: txn, _marker: PhantomData })
}
@ -227,10 +224,10 @@ impl <'env> RwTransaction<'env> {
pub fn new(env: &'env Environment) -> Result<RwTransaction<'env>> {
let mut txn: *mut ffi::MDB_txn = ptr::null_mut();
unsafe {
try!(lmdb_result(ffi::mdb_txn_begin(env.env(),
lmdb_result(ffi::mdb_txn_begin(env.env(),
ptr::null_mut(),
EnvironmentFlags::empty().bits(),
&mut txn)));
&mut txn))?;
Ok(RwTransaction { txn: txn, _marker: PhantomData })
}
}
@ -305,11 +302,11 @@ impl <'env> RwTransaction<'env> {
let mut data_val: ffi::MDB_val = ffi::MDB_val { mv_size: len,
mv_data: ptr::null_mut::<c_void>() };
unsafe {
try!(lmdb_result(ffi::mdb_put(self.txn(),
lmdb_result(ffi::mdb_put(self.txn(),
database.dbi(),
&mut key_val,
&mut data_val,
flags.bits() | ffi::MDB_RESERVE)));
flags.bits() | ffi::MDB_RESERVE))?;
Ok(slice::from_raw_parts_mut(data_val.mv_data as *mut u8,
data_val.mv_size as usize))
}

Loading…
Cancel
Save