diff --git a/lmdb-sys/Cargo.toml b/lmdb-sys/Cargo.toml index 6f12c97..57c1a8c 100644 --- a/lmdb-sys/Cargo.toml +++ b/lmdb-sys/Cargo.toml @@ -13,7 +13,7 @@ build = "build.rs" name = "lmdb-sys" [dependencies.rust-bindgen] -path = "../../rust-bindgen" +git = "https://github.com/crabtw/rust-bindgen.git" [build-dependencies.pkg-config] pkg-config = "*" diff --git a/lmdb-sys/mdb b/lmdb-sys/mdb index 9cc04f6..462dc09 160000 --- a/lmdb-sys/mdb +++ b/lmdb-sys/mdb @@ -1 +1 @@ -Subproject commit 9cc04f604f80f033d712f5f1faeb4ed97ca74f40 +Subproject commit 462dc097451834477b597447af69c5acc93182b7 diff --git a/lmdb-sys/src/lib.rs b/lmdb-sys/src/lib.rs index f81946a..77a6135 100644 --- a/lmdb-sys/src/lib.rs +++ b/lmdb-sys/src/lib.rs @@ -1,7 +1,8 @@ #![allow(dead_code, uppercase_variables, non_camel_case_types)] -#![feature(phase,globs)] +#![feature(plugin)] -#[phase(plugin)] extern crate bindgen; +#[plugin] +extern crate bindgen; extern crate libc; use libc::{size_t, mode_t}; diff --git a/src/database.rs b/src/database.rs index 373bcc1..c2371e1 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,5 +1,5 @@ use libc::c_uint; -use std::c_str::ToCStr; +use std::ffi::CString; use std::ptr; use ffi; @@ -25,7 +25,7 @@ impl Database { name: Option<&str>, flags: c_uint) -> LmdbResult { - let c_name = name.map(|n| n.to_c_str()); + let c_name = name.map(|n| CString::from_slice(n.as_bytes())); 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))); diff --git a/src/environment.rs b/src/environment.rs index 3859cae..6f20cb9 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -1,6 +1,7 @@ use libc::{c_uint, size_t, mode_t}; -use std::c_str::ToCStr; +use std::ffi::CString; use std::io::FilePermission; +use std::path::BytesContainer; use std::ptr; use std::sync::Mutex; @@ -177,7 +178,7 @@ impl EnvironmentBuilder { ffi::mdb_env_close(env)) } lmdb_try_with_cleanup!(ffi::mdb_env_open(env, - path.to_c_str().as_ptr(), + CString::from_slice(path.container_as_bytes()).as_ptr(), self.flags.bits(), mode.bits() as mode_t), ffi::mdb_env_close(env)); diff --git a/src/error.rs b/src/error.rs index 38042c4..4fb02a5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,6 @@ use libc::c_int; +use std; +use std::mem; use std::error::Error; use std::str; @@ -106,7 +108,12 @@ impl LmdbError { impl Error for LmdbError { fn description(&self) -> &str { - unsafe { str::from_c_str(ffi::mdb_strerror(self.to_err_code()) as *const _) } + unsafe { + // This is safe since the error messages returned from mdb_strerror are static. + let err: &'static *const i8 = + mem::transmute(&(ffi::mdb_strerror(self.to_err_code()) as *const i8)); + str::from_utf8_unchecked(std::ffi::c_str_to_bytes(err)) + } } } diff --git a/src/lib.rs b/src/lib.rs index f659c72..36ea124 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,9 @@ //! Provides the minimal amount of abstraction necessary to interact with LMDB safely in Rust. In //! general, the API is very similar to the LMDB [C-API](http://symas.com/mdb/doc/). -#![feature(phase, globs, macro_rules, unsafe_destructor, associated_types)] +#![feature(phase, unsafe_destructor)] -#[phase(plugin, link)] extern crate log; +#[macro_use] extern crate log; extern crate libc; extern crate "lmdb-sys" as ffi;