Skip to content

Commit

Permalink
Merge pull request skade#36 from realbigsean/compile-to-pi
Browse files Browse the repository at this point in the history
Update i8 to c_char
  • Loading branch information
skade authored Apr 3, 2020
2 parents 8835d66 + 6e966f6 commit aa85937
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/database/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<K: Key> Batch<K> for Database<K> {
if error == ptr::null_mut() {
Ok(())
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
}
}
Expand Down Expand Up @@ -124,9 +124,9 @@ pub trait WritebatchIterator {
}

extern "C" fn put_callback<K: Key, T: WritebatchIterator<K = K>>(state: *mut c_void,
key: *const i8,
key: *const c_char,
keylen: size_t,
val: *const i8,
val: *const c_char,
vallen: size_t) {
unsafe {
let iter: &mut T = &mut *(state as *mut T);
Expand All @@ -138,7 +138,7 @@ extern "C" fn put_callback<K: Key, T: WritebatchIterator<K = K>>(state: *mut c_v
}

extern "C" fn deleted_callback<K: Key, T: WritebatchIterator<K = K>>(state: *mut c_void,
key: *const i8,
key: *const c_char,
keylen: size_t) {
unsafe {
let iter: &mut T = &mut *(state as *mut T);
Expand Down
4 changes: 2 additions & 2 deletions src/database/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ unsafe trait InternalComparator : Comparator where Self: Sized {
}

extern "C" fn compare(state: *mut c_void,
a: *const i8,
a: *const c_char,
a_len: size_t,
b: *const i8,
b: *const c_char,
b_len: size_t)
-> i32 {
unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/database/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use libc::c_void;
use leveldb_sys::leveldb_free;
use std;
use libc::c_char;

/// A leveldb error, just containing the error string
/// provided by leveldb.
Expand All @@ -21,7 +22,7 @@ impl Error {
///
/// This method is `unsafe` because the pointer must be valid and point to heap.
/// The pointer will be passed to `free`!
pub unsafe fn new_from_i8(message: *const i8) -> Error {
pub unsafe fn new_from_char(message: *const c_char) -> Error {
use std::str::from_utf8;
use std::ffi::CStr;

Expand Down
6 changes: 3 additions & 3 deletions src/database/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<K: Key> KV<K> for Database<K> {
if error == ptr::null_mut() {
Ok(())
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
})
}
Expand All @@ -96,7 +96,7 @@ impl<K: Key> KV<K> for Database<K> {
if error == ptr::null_mut() {
Ok(())
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
})
}
Expand All @@ -119,7 +119,7 @@ impl<K: Key> KV<K> for Database<K> {
if error == ptr::null_mut() {
Ok(Bytes::from_raw(result as *mut u8, length))
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
})
}
Expand Down
9 changes: 5 additions & 4 deletions src/database/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use error::Error;
use std::ffi::CString;
use std::ptr;
use std::path::Path;
use libc::c_char;

use leveldb_sys::{leveldb_destroy_db, leveldb_repair_db};

Expand All @@ -14,13 +15,13 @@ pub fn destroy(name: &Path, options: Options) -> Result<(), Error> {
let c_string = CString::new(name.to_str().unwrap()).unwrap();
let c_options = c_options(&options, None);
leveldb_destroy_db(c_options,
c_string.as_bytes_with_nul().as_ptr() as *const i8,
c_string.as_bytes_with_nul().as_ptr() as *const c_char,
&mut error);

if error == ptr::null_mut() {
Ok(())
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
}
}
Expand All @@ -32,13 +33,13 @@ pub fn repair(name: &Path, options: Options) -> Result<(), Error> {
let c_string = CString::new(name.to_str().unwrap()).unwrap();
let c_options = c_options(&options, None);
leveldb_repair_db(c_options,
c_string.as_bytes_with_nul().as_ptr() as *const i8,
c_string.as_bytes_with_nul().as_ptr() as *const c_char,
&mut error);

if error == ptr::null_mut() {
Ok(())
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
}
}
9 changes: 5 additions & 4 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use comparator::{Comparator, create_comparator};
use self::key::Key;

use std::marker::PhantomData;
use libc::c_char;

pub mod options;
pub mod error;
Expand Down Expand Up @@ -110,14 +111,14 @@ impl<K: Key> Database<K> {
let c_string = CString::new(name.to_str().unwrap()).unwrap();
let c_options = c_options(&options, None);
let db = leveldb_open(c_options as *const leveldb_options_t,
c_string.as_bytes_with_nul().as_ptr() as *const i8,
c_string.as_bytes_with_nul().as_ptr() as *const c_char,
&mut error);
leveldb_options_destroy(c_options);

if error == ptr::null_mut() {
Ok(Database::new(db, options, None))
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
}
}
Expand All @@ -140,14 +141,14 @@ impl<K: Key> Database<K> {
let c_string = CString::new(name.to_str().unwrap()).unwrap();
let c_options = c_options(&options, Some(comp_ptr));
let db = leveldb_open(c_options as *const leveldb_options_t,
c_string.as_bytes_with_nul().as_ptr() as *const i8,
c_string.as_bytes_with_nul().as_ptr() as *const c_char,
&mut error);
leveldb_options_destroy(c_options);

if error == ptr::null_mut() {
Ok(Database::new(db, options, Some(comp_ptr)))
} else {
Err(Error::new_from_i8(error))
Err(Error::new_from_char(error))
}
}
}
Expand Down

0 comments on commit aa85937

Please sign in to comment.