From 9a7270ef9dffdb8b9b7d5c6cf2d4d85563e52a45 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Tue, 31 Jul 2018 17:22:40 +0300 Subject: [PATCH] Fixed crash `test_column_family` test on macOS --- src/db.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/db.rs b/src/db.rs index 78fd8c7..6cca63f 100644 --- a/src/db.rs +++ b/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>(opts: &Options, path: P) -> Result, 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) } }