Merge pull request #199 from aleksuss/fix-list-cf-osx

Fixed crash `test_column_family` test on macOS
master
Jordan Terrell 6 years ago committed by GitHub
commit 94b43090b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/db.rs

@ -28,6 +28,7 @@ use std::path::Path;
use std::ptr;
use std::slice;
use std::str;
use std::ffi::CStr;
pub fn new_bloom_filter(bits: c_int) -> *mut ffi::rocksdb_filterpolicy_t {
unsafe { ffi::rocksdb_filterpolicy_create_bloom(bits) }
@ -698,8 +699,7 @@ impl DB {
}
pub fn list_cf<P: AsRef<Path>>(opts: &Options, path: P) -> Result<Vec<String>, Error> {
let path = path.as_ref();
let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
let cpath = match CString::new(path.as_ref().to_string_lossy().as_bytes()) {
Ok(c) => c,
Err(_) => {
return Err(Error::new(
@ -719,10 +719,11 @@ impl DB {
&mut length,
));
let vec = Vec::from_raw_parts(ptr, length, length)
let vec = slice::from_raw_parts(ptr, length)
.iter()
.map(|&ptr| CString::from_raw(ptr).into_string().unwrap())
.map(|ptr| CStr::from_ptr(*ptr).to_string_lossy().into_owned())
.collect();
ffi::rocksdb_list_column_families_destroy(ptr, length);
Ok(vec)
}
}

Loading…
Cancel
Save