From 2bace2ca0d78c83641cc0691ed7fa3938cea2fec Mon Sep 17 00:00:00 2001 From: hh9527 Date: Tue, 15 Nov 2016 22:06:44 +0800 Subject: [PATCH 1/2] Fix: https://github.com/spacejam/rust-rocksdb/issues/96 (#1) * Update ffi_util.rs * Update rocksdb.rs --- src/ffi_util.rs | 3 +-- src/rocksdb.rs | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ffi_util.rs b/src/ffi_util.rs index c979f72..07c3bff 100644 --- a/src/ffi_util.rs +++ b/src/ffi_util.rs @@ -15,11 +15,10 @@ use libc::{self, c_char, c_void}; use std::ffi::CStr; -use std::str; pub fn error_message(ptr: *const c_char) -> String { let cstr = unsafe { CStr::from_ptr(ptr as *const _) }; - let s = str::from_utf8(cstr.to_bytes()).unwrap().to_owned(); + let s = String::from_utf8_lossy(cstr.to_bytes()).into(); unsafe { libc::free(ptr as *mut c_void); } diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 248957c..4e5443f 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -911,10 +911,9 @@ fn errors_do_stuff() { // The DB will still be open when we try to destroy it and the lock should fail. match DB::destroy(&opts, path) { Err(s) => { - assert!(s == - Error::new("IO error: lock _rust_rocksdb_error/LOCK: No \ - locks available" - .to_owned())) + let message = s.to_string(); + assert!(message.find("IO error:").is_some()); + assert!(message.find("_rust_rocksdb_error/LOCK:").is_some()); } Ok(_) => panic!("should fail"), } From 51dd65627267b251c5c73c9a95e76a8ea20c47fd Mon Sep 17 00:00:00 2001 From: hh9527 Date: Thu, 17 Nov 2016 12:46:24 +0800 Subject: [PATCH 2/2] Fix compile failed in stable/beta --- src/ffi_util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffi_util.rs b/src/ffi_util.rs index 07c3bff..9256845 100644 --- a/src/ffi_util.rs +++ b/src/ffi_util.rs @@ -18,7 +18,7 @@ use std::ffi::CStr; pub fn error_message(ptr: *const c_char) -> String { let cstr = unsafe { CStr::from_ptr(ptr as *const _) }; - let s = String::from_utf8_lossy(cstr.to_bytes()).into(); + let s = String::from_utf8_lossy(cstr.to_bytes()).into_owned(); unsafe { libc::free(ptr as *mut c_void); }