Update for stable Rust

without.crypto
Dan Burkert 9 years ago
parent cf967d1929
commit c101fa5c1f
  1. 6
      .gitmodules
  2. 8
      Cargo.toml
  3. 2
      lmdb-sys/build.rs
  4. 1
      lmdb-sys/lmdb
  5. 1
      lmdb-sys/mdb
  6. 4
      lmdb-sys/src/ffi.rs
  7. 23
      src/cursor.rs
  8. 4
      src/environment.rs
  9. 5
      src/flags.rs
  10. 5
      src/lib.rs
  11. 38
      src/transaction.rs

6
.gitmodules vendored

@ -1,3 +1,3 @@
[submodule "lmdb-sys/mdb"]
path = lmdb-sys/mdb
url = https://gitorious.org/mdb/mdb.git
[submodule "lmdb-sys/lmdb"]
path = lmdb-sys/lmdb
url = https://github.com/LMDB/lmdb

@ -20,9 +20,9 @@ path = "lmdb-sys"
version = "0.4.3"
[dependencies]
bitflags = "*"
libc = "*"
bitflags = "0.3"
libc = "0.2"
[dev-dependencies]
rand = "*"
tempdir = "*"
rand = "0.3"
tempdir = "0.3"

@ -7,7 +7,7 @@ use std::path::PathBuf;
fn main() {
let mut lmdb: PathBuf = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
lmdb.push("mdb");
lmdb.push("lmdb");
lmdb.push("libraries");
lmdb.push("liblmdb");

@ -0,0 +1 @@
Subproject commit fb5a768a77ca5330e15a3a34ceb694bc11cb216a

@ -1 +0,0 @@
Subproject commit 3368d1f5e243225cba4d730fba19ff600798ebe3

@ -6,7 +6,6 @@ pub type MDB_dbi = ::libc::c_uint;
pub enum MDB_cursor { }
#[repr(C)]
#[derive(Copy)]
pub struct MDB_val {
pub mv_size: ::libc::size_t,
pub mv_data: *mut ::libc::c_void,
@ -36,7 +35,7 @@ pub const MDB_SET_RANGE: ::libc::c_uint = 17;
pub type MDB_cursor_op = ::libc::c_uint;
#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct MDB_stat {
pub ms_psize: ::libc::c_uint,
pub ms_depth: ::libc::c_uint,
@ -47,7 +46,6 @@ pub struct MDB_stat {
}
#[repr(C)]
#[derive(Copy)]
pub struct MDB_envinfo {
pub me_mapaddr: *mut ::libc::c_void,
pub me_mapsize: ::libc::size_t,

@ -1,6 +1,6 @@
use libc::{c_void, size_t, c_uint};
use std::{ptr, slice};
use std::marker::{PhantomData, PhantomFn};
use std::marker::PhantomData;
use database::Database;
use error::{Error, Result, lmdb_result};
@ -9,15 +9,12 @@ use flags::WriteFlags;
use transaction::Transaction;
/// An LMDB cursor.
pub trait Cursor<'txn> : PhantomFn<(), &'txn [u8]> {
pub trait Cursor<'txn> {
/// Returns a raw pointer to the underlying LMDB cursor.
///
/// The caller **must** ensure that the pointer is not used after the lifetime of the cursor.
fn cursor(&self) -> *mut ffi::MDB_cursor;
}
/// Cursor extension methods.
pub trait CursorExt<'txn> : Cursor<'txn> + Sized {
/// Retrieves a key/data pair from the cursor. Depending on the cursor op, the current key may
/// be returned.
@ -96,8 +93,6 @@ pub trait CursorExt<'txn> : Cursor<'txn> + Sized {
}
}
impl<'txn, T> CursorExt<'txn> for T where T: Cursor<'txn> {}
/// A read-only cursor for navigating the items within a database.
pub struct RoCursor<'txn> {
cursor: *mut ffi::MDB_cursor,
@ -110,10 +105,6 @@ impl <'txn> Cursor<'txn> for RoCursor<'txn> {
}
}
impl <'txn> !Sync for RoCursor<'txn> {}
impl <'txn> !Send for RoCursor<'txn> {}
#[unsafe_destructor]
impl <'txn> Drop for RoCursor<'txn> {
fn drop(&mut self) {
unsafe { ffi::mdb_cursor_close(self.cursor) }
@ -125,7 +116,7 @@ impl <'txn> RoCursor<'txn> {
/// Creates a new read-only cursor in the given database and transaction. Prefer using
/// `Transaction::open_cursor`.
#[doc(hidden)]
pub fn new(txn: &'txn Transaction, db: Database) -> Result<RoCursor<'txn>> {
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))); }
Ok(RoCursor {
@ -147,10 +138,6 @@ impl <'txn> Cursor<'txn> for RwCursor<'txn> {
}
}
impl <'txn> !Sync for RwCursor<'txn> {}
impl <'txn> !Send for RwCursor<'txn> {}
#[unsafe_destructor]
impl <'txn> Drop for RwCursor<'txn> {
fn drop(&mut self) {
unsafe { ffi::mdb_cursor_close(self.cursor) }
@ -162,7 +149,7 @@ impl <'txn> RwCursor<'txn> {
/// Creates a new read-only cursor in the given database and transaction. Prefer using
/// `RwTransaction::open_rw_cursor`.
#[doc(hidden)]
pub fn new(txn: &'txn Transaction, db: Database) -> Result<RwCursor<'txn>> {
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))); }
Ok(RwCursor { cursor: cursor, _marker: PhantomData })

@ -1,5 +1,5 @@
use libc::{c_uint, size_t, mode_t};
use std::ffi::{AsOsStr, CString};
use std::ffi::CString;
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
use std::ptr;
@ -9,7 +9,7 @@ use ffi;
use error::{Result, lmdb_result};
use database::Database;
use transaction::{RoTransaction, RwTransaction, Transaction, TransactionExt};
use transaction::{RoTransaction, RwTransaction, Transaction};
use flags::{DatabaseFlags, EnvironmentFlags};
/// An LMDB environment.

@ -4,7 +4,6 @@ use ffi::*;
bitflags! {
#[doc="Environment Options"]
#[derive(Debug)]
flags EnvironmentFlags: c_uint {
#[doc="Use a fixed address for the mmap region. This flag must be specified"]
@ -48,7 +47,7 @@ bitflags! {
#[doc="flushes dirty buffers to disk and how often `Environment::sync` is called. However,"]
#[doc="if the filesystem preserves write order and the `WRITE_MAP` flag is not used,"]
#[doc="transactions exhibit ACI (atomicity, consistency, isolation) properties and only"]
#[doc="lose D (durability). I.e. database integrity"] #[doc="is maintained, but a system"]
#[doc="lose D (durability). I.e. database integrity is maintained, but a system"]
#[doc="crash may undo the final transactions. Note that (`NO_SYNC | WRITE_MAP`) leaves the"]
#[doc="system with no hint for when to write transactions to disk, unless"]
#[doc="`Environment::sync` is called. (`MAP_ASYNC | WRITE_MAP`) may be preferable."]
@ -105,7 +104,6 @@ bitflags! {
bitflags! {
#[doc="Database Options"]
#[derive(Debug)]
flags DatabaseFlags: c_uint {
#[doc="Keys are strings to be compared in reverse order, from the end of the strings"]
@ -141,7 +139,6 @@ bitflags! {
bitflags! {
#[doc="Write Options"]
#[derive(Debug)]
flags WriteFlags: c_uint {
#[doc="Insert the new item only if the key does not already appear in the database."]

@ -1,8 +1,7 @@
//! Idiomatic and safe APIs for interacting with the
//! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/).
#![feature(optin_builtin_traits, unsafe_destructor)]
#![cfg_attr(test, feature(std_misc, test))]
#![cfg_attr(test, feature(test))]
extern crate libc;
extern crate lmdb_sys as ffi;
@ -14,7 +13,6 @@ extern crate lmdb_sys as ffi;
pub use cursor::{
Cursor,
CursorExt,
RoCursor,
RwCursor
};
@ -27,7 +25,6 @@ pub use transaction::{
RoTransaction,
RwTransaction,
Transaction,
TransactionExt,
};
macro_rules! lmdb_try {

@ -1,6 +1,6 @@
use libc::{c_uint, c_void, size_t};
use std::{mem, ptr, slice};
use std::marker::{PhantomData, PhantomFn} ;
use std::marker::PhantomData ;
use ffi;
@ -13,17 +13,13 @@ use flags::{DatabaseFlags, EnvironmentFlags, WriteFlags};
/// An LMDB transaction.
///
/// All database operations require a transaction.
pub trait Transaction<'env> : PhantomFn<(), &'env Environment> {
pub trait Transaction : Sized {
/// Returns a raw pointer to the underlying LMDB transaction.
///
/// The caller **must** ensure that the pointer is not used after the lifetime of the
/// transaction.
fn txn(&self) -> *mut ffi::MDB_txn;
}
/// Transaction extension methods.
pub trait TransactionExt<'env> : Transaction<'env> + Sized {
/// Commits the transaction.
///
@ -100,18 +96,12 @@ pub trait TransactionExt<'env> : Transaction<'env> + Sized {
}
}
impl<'env, T> TransactionExt<'env> for T where T: Transaction<'env> {}
/// An LMDB read-only transaction.
pub struct RoTransaction<'env> {
txn: *mut ffi::MDB_txn,
_marker: PhantomData<&'env ()>,
}
impl <'env> !Sync for RoTransaction<'env> {}
impl <'env> !Send for RoTransaction<'env> {}
#[unsafe_destructor]
impl <'env> Drop for RoTransaction<'env> {
fn drop(&mut self) {
unsafe { ffi::mdb_txn_abort(self.txn) }
@ -154,7 +144,7 @@ impl <'env> RoTransaction<'env> {
}
}
impl <'env> Transaction<'env> for RoTransaction<'env> {
impl <'env> Transaction for RoTransaction<'env> {
fn txn(&self) -> *mut ffi::MDB_txn {
self.txn
}
@ -166,7 +156,6 @@ pub struct InactiveTransaction<'env> {
_marker: PhantomData<&'env ()>,
}
#[unsafe_destructor]
impl <'env> Drop for InactiveTransaction<'env> {
fn drop(&mut self) {
unsafe { ffi::mdb_txn_abort(self.txn) }
@ -195,10 +184,6 @@ pub struct RwTransaction<'env> {
_marker: PhantomData<&'env ()>,
}
impl <'env> !Sync for RwTransaction<'env> {}
impl <'env> !Send for RwTransaction<'env> {}
#[unsafe_destructor]
impl <'env> Drop for RwTransaction<'env> {
fn drop(&mut self) {
unsafe { ffi::mdb_txn_abort(self.txn) }
@ -346,7 +331,7 @@ impl <'env> RwTransaction<'env> {
}
}
impl <'env> Transaction<'env> for RwTransaction<'env> {
impl <'env> Transaction for RwTransaction<'env> {
fn txn(&self) -> *mut ffi::MDB_txn {
self.txn
}
@ -359,7 +344,8 @@ mod test {
use rand::{Rng, XorShiftRng};
use std::io::Write;
use std::ptr;
use std::sync::{Arc, Barrier, Future};
use std::sync::{Arc, Barrier};
use std::thread::{self, JoinHandle};
use test::{Bencher, black_box};
use tempdir::TempDir;
@ -503,7 +489,7 @@ mod test {
let n = 10usize; // Number of concurrent readers
let barrier = Arc::new(Barrier::new(n + 1));
let mut futures: Vec<Future<bool>> = Vec::with_capacity(n);
let mut futures: Vec<JoinHandle<bool>> = Vec::with_capacity(n);
let key = b"key";
let val = b"val";
@ -512,7 +498,7 @@ mod test {
let reader_env = env.clone();
let reader_barrier = barrier.clone();
futures.push(Future::spawn(move|| {
futures.push(thread::spawn(move|| {
let db = reader_env.open_db(None).unwrap();
{
let txn = reader_env.begin_ro_txn().unwrap();
@ -535,7 +521,7 @@ mod test {
txn.commit().unwrap();
barrier.wait();
assert!(futures.iter_mut().all(|b| b.get()))
assert!(futures.into_iter().all(|b| b.join().unwrap()))
}
#[test]
@ -544,7 +530,7 @@ mod test {
let env = Arc::new(Environment::new().open(dir.path()).unwrap());
let n = 10usize; // Number of concurrent writers
let mut futures: Vec<Future<bool>> = Vec::with_capacity(n);
let mut futures: Vec<JoinHandle<bool>> = Vec::with_capacity(n);
let key = "key";
let val = "val";
@ -552,7 +538,7 @@ mod test {
for i in 0..n {
let writer_env = env.clone();
futures.push(Future::spawn(move|| {
futures.push(thread::spawn(move|| {
let db = writer_env.open_db(None).unwrap();
let mut txn = writer_env.begin_rw_txn().unwrap();
txn.put(db,
@ -563,7 +549,7 @@ mod test {
txn.commit().is_ok()
}));
}
assert!(futures.iter_mut().all(|b| b.get()));
assert!(futures.into_iter().all(|b| b.join().unwrap()));
let db = env.open_db(None).unwrap();
let txn = env.begin_ro_txn().unwrap();

Loading…
Cancel
Save