Changed ffi types to pointer for i686 compatibility

master
arkpar 10 years ago committed by Tyler Neely
parent c18043f427
commit cc6e143318
No known key found for this signature in database
GPG Key ID: 23E6C4FBEAE5E4E3
  1. 83
      src/ffi.rs
  2. 12
      src/rocksdb.rs
  3. 6
      src/rocksdb_options.rs

@ -17,45 +17,50 @@ use self::libc::{c_char, c_int, c_void, size_t};
use std::ffi::CStr; use std::ffi::CStr;
use std::str::from_utf8; use std::str::from_utf8;
#[derive(Copy, Clone)] pub enum DBOptionsOpaque {}
#[repr(C)] pub type DBOptions = *const DBOptionsOpaque;
pub struct DBOptions(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBInstanceOpaque {}
#[repr(C)] pub type DBInstance = *const DBInstanceOpaque;
pub struct DBInstance(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBWriteOptionsOpaque {}
#[repr(C)] pub type DBWriteOptions = *const DBWriteOptionsOpaque;
pub struct DBWriteOptions(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBReadOptionsOpaque {}
#[repr(C)] pub type DBReadOptions = *const DBReadOptionsOpaque;
pub struct DBReadOptions(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBMergeOperatorOpaque {}
#[repr(C)] pub type DBMergeOperator = *const DBMergeOperatorOpaque;
pub struct DBMergeOperator(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBBlockBasedTableOptionsOpaque {}
#[repr(C)] pub type DBBlockBasedTableOptions = *const DBBlockBasedTableOptionsOpaque;
pub struct DBBlockBasedTableOptions(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBCacheOpaque {}
#[repr(C)] pub type DBCache = *const DBCacheOpaque;
pub struct DBCache(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBFilterPolicyOpaque {}
#[repr(C)] pub type DBFilterPolicy = *const DBFilterPolicyOpaque;
pub struct DBFilterPolicy(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBSnapshotOpaque {}
#[repr(C)] pub type DBSnapshot = *const DBSnapshotOpaque;
pub struct DBSnapshot(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBIteratorOpaque {}
#[repr(C)] pub type DBIterator = *const DBIteratorOpaque;
pub struct DBIterator(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBCFHandleOpaque {}
#[repr(C)] pub type DBCFHandle = *const DBCFHandleOpaque;
pub struct DBCFHandle(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBWriteBatchOpaque {}
#[repr(C)] pub type DBWriteBatch = *const DBWriteBatchOpaque;
pub struct DBWriteBatch(pub *const c_void);
#[derive(Copy, Clone)] pub enum DBComparatorOpaque {}
#[repr(C)] pub type DBComparator = *const DBComparatorOpaque;
pub struct DBComparator(pub *const c_void);
pub enum DBSliceTransformOpaque {}
pub type DBSliceTransform = *const DBSliceTransformOpaque;
pub const BLOCK_BASED_INDEX_TYPE_BINARY_SEARCH: c_int = 0;
pub const BLOCK_BASED_INDEX_TYPE_HASH_SEARCH: c_int = 1;
pub fn new_bloom_filter(bits: c_int) -> DBFilterPolicy { pub fn new_bloom_filter(bits: c_int) -> DBFilterPolicy {
unsafe { rocksdb_filterpolicy_create_bloom(bits) } unsafe { rocksdb_filterpolicy_create_bloom(bits) }

@ -23,7 +23,7 @@ use std::path::Path;
use std::slice; use std::slice;
use std::str::from_utf8; use std::str::from_utf8;
use self::libc::{c_void, size_t}; use self::libc::size_t;
use rocksdb_ffi::{self, DBCFHandle, error_message}; use rocksdb_ffi::{self, DBCFHandle, error_message};
use rocksdb_options::{Options, WriteOptions}; use rocksdb_options::{Options, WriteOptions};
@ -317,7 +317,7 @@ impl DB {
// These handles will be populated by DB. // These handles will be populated by DB.
let cfhandles: Vec<rocksdb_ffi::DBCFHandle> = let cfhandles: Vec<rocksdb_ffi::DBCFHandle> =
cfs_v.iter() cfs_v.iter()
.map(|_| rocksdb_ffi::DBCFHandle(0 as *mut c_void)) .map(|_| 0 as rocksdb_ffi::DBCFHandle)
.collect(); .collect();
// TODO(tyler) allow options to be passed in. // TODO(tyler) allow options to be passed in.
@ -338,7 +338,7 @@ impl DB {
} }
for handle in cfhandles.iter() { for handle in cfhandles.iter() {
if handle.0.is_null() { if handle.is_null() {
return Err("Received null column family handle from DB." return Err("Received null column family handle from DB."
.to_string()); .to_string());
} }
@ -352,7 +352,7 @@ impl DB {
if !err.is_null() { if !err.is_null() {
return Err(error_message(err)); return Err(error_message(err));
} }
if db.0.is_null() { if db.is_null() {
return Err("Could not initialize database.".to_string()); return Err("Could not initialize database.".to_string());
} }
@ -422,7 +422,7 @@ impl DB {
key: &[u8], key: &[u8],
readopts: &ReadOptions) readopts: &ReadOptions)
-> Result<Option<DBVector>, String> { -> Result<Option<DBVector>, String> {
if readopts.inner.0.is_null() { if readopts.inner.is_null() {
return Err("Unable to create rocksdb read options. This is a \ return Err("Unable to create rocksdb read options. This is a \
fairly trivial call, and its failure may be \ fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded rocksdb \ indicative of a mis-compiled or mis-loaded rocksdb \
@ -461,7 +461,7 @@ impl DB {
key: &[u8], key: &[u8],
readopts: &ReadOptions) readopts: &ReadOptions)
-> Result<Option<DBVector>, String> { -> Result<Option<DBVector>, String> {
if readopts.inner.0.is_null() { if readopts.inner.is_null() {
return Err("Unable to create rocksdb read options. This is a \ return Err("Unable to create rocksdb read options. This is a \
fairly trivial call, and its failure may be \ fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded rocksdb \ indicative of a mis-compiled or mis-loaded rocksdb \

@ -63,8 +63,7 @@ impl BlockBasedOptions {
let block_opts = unsafe { let block_opts = unsafe {
rocksdb_ffi::rocksdb_block_based_options_create() rocksdb_ffi::rocksdb_block_based_options_create()
}; };
let rocksdb_ffi::DBBlockBasedTableOptions(opt_ptr) = block_opts; if block_opts.is_null() {
if opt_ptr.is_null() {
panic!("Could not create rocksdb block based options".to_string()); panic!("Could not create rocksdb block based options".to_string());
} }
BlockBasedOptions { inner: block_opts } BlockBasedOptions { inner: block_opts }
@ -106,8 +105,7 @@ impl Options {
pub fn new() -> Options { pub fn new() -> Options {
unsafe { unsafe {
let opts = rocksdb_ffi::rocksdb_options_create(); let opts = rocksdb_ffi::rocksdb_options_create();
let rocksdb_ffi::DBOptions(opt_ptr) = opts; if opts.is_null() {
if opt_ptr.is_null() {
panic!("Could not create rocksdb options".to_string()); panic!("Could not create rocksdb options".to_string());
} }
Options { inner: opts } Options { inner: opts }

Loading…
Cancel
Save