From cc6e1433186b9de0f499e7d39726b6b6d3ff4224 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 25 Feb 2016 20:13:51 +0100 Subject: [PATCH 1/6] Changed ffi types to pointer for i686 compatibility --- src/ffi.rs | 83 ++++++++++++++++++++++-------------------- src/rocksdb.rs | 12 +++--- src/rocksdb_options.rs | 6 +-- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index c83302f..5f36276 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -17,45 +17,50 @@ use self::libc::{c_char, c_int, c_void, size_t}; use std::ffi::CStr; use std::str::from_utf8; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBOptions(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBInstance(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBWriteOptions(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBReadOptions(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBMergeOperator(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBBlockBasedTableOptions(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBCache(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBFilterPolicy(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBSnapshot(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBIterator(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBCFHandle(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBWriteBatch(pub *const c_void); -#[derive(Copy, Clone)] -#[repr(C)] -pub struct DBComparator(pub *const c_void); +pub enum DBOptionsOpaque {} +pub type DBOptions = *const DBOptionsOpaque; + +pub enum DBInstanceOpaque {} +pub type DBInstance = *const DBInstanceOpaque; + +pub enum DBWriteOptionsOpaque {} +pub type DBWriteOptions = *const DBWriteOptionsOpaque; + +pub enum DBReadOptionsOpaque {} +pub type DBReadOptions = *const DBReadOptionsOpaque; + +pub enum DBMergeOperatorOpaque {} +pub type DBMergeOperator = *const DBMergeOperatorOpaque; + +pub enum DBBlockBasedTableOptionsOpaque {} +pub type DBBlockBasedTableOptions = *const DBBlockBasedTableOptionsOpaque; + +pub enum DBCacheOpaque {} +pub type DBCache = *const DBCacheOpaque; + +pub enum DBFilterPolicyOpaque {} +pub type DBFilterPolicy = *const DBFilterPolicyOpaque; + +pub enum DBSnapshotOpaque {} +pub type DBSnapshot = *const DBSnapshotOpaque; + +pub enum DBIteratorOpaque {} +pub type DBIterator = *const DBIteratorOpaque; + +pub enum DBCFHandleOpaque {} +pub type DBCFHandle = *const DBCFHandleOpaque; + +pub enum DBWriteBatchOpaque {} +pub type DBWriteBatch = *const DBWriteBatchOpaque; + +pub enum DBComparatorOpaque {} +pub type DBComparator = *const DBComparatorOpaque; + +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 { unsafe { rocksdb_filterpolicy_create_bloom(bits) } diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 70167a3..ffd513c 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -23,7 +23,7 @@ use std::path::Path; use std::slice; 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_options::{Options, WriteOptions}; @@ -317,7 +317,7 @@ impl DB { // These handles will be populated by DB. let cfhandles: Vec = cfs_v.iter() - .map(|_| rocksdb_ffi::DBCFHandle(0 as *mut c_void)) + .map(|_| 0 as rocksdb_ffi::DBCFHandle) .collect(); // TODO(tyler) allow options to be passed in. @@ -338,7 +338,7 @@ impl DB { } for handle in cfhandles.iter() { - if handle.0.is_null() { + if handle.is_null() { return Err("Received null column family handle from DB." .to_string()); } @@ -352,7 +352,7 @@ impl DB { if !err.is_null() { return Err(error_message(err)); } - if db.0.is_null() { + if db.is_null() { return Err("Could not initialize database.".to_string()); } @@ -422,7 +422,7 @@ impl DB { key: &[u8], readopts: &ReadOptions) -> Result, String> { - if readopts.inner.0.is_null() { + if readopts.inner.is_null() { return Err("Unable to create rocksdb read options. This is a \ fairly trivial call, and its failure may be \ indicative of a mis-compiled or mis-loaded rocksdb \ @@ -461,7 +461,7 @@ impl DB { key: &[u8], readopts: &ReadOptions) -> Result, String> { - if readopts.inner.0.is_null() { + if readopts.inner.is_null() { return Err("Unable to create rocksdb read options. This is a \ fairly trivial call, and its failure may be \ indicative of a mis-compiled or mis-loaded rocksdb \ diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 35d9f6d..176afda 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -63,8 +63,7 @@ impl BlockBasedOptions { let block_opts = unsafe { rocksdb_ffi::rocksdb_block_based_options_create() }; - let rocksdb_ffi::DBBlockBasedTableOptions(opt_ptr) = block_opts; - if opt_ptr.is_null() { + if block_opts.is_null() { panic!("Could not create rocksdb block based options".to_string()); } BlockBasedOptions { inner: block_opts } @@ -106,8 +105,7 @@ impl Options { pub fn new() -> Options { unsafe { let opts = rocksdb_ffi::rocksdb_options_create(); - let rocksdb_ffi::DBOptions(opt_ptr) = opts; - if opt_ptr.is_null() { + if opts.is_null() { panic!("Could not create rocksdb options".to_string()); } Options { inner: opts } From 740f3735d04d179b29f47c4f7169f9a004dd67a3 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 1 May 2016 16:42:36 -0700 Subject: [PATCH 2/6] touchups to make arkpar's backport work --- src/ffi.rs | 6 +++--- src/rocksdb_options.rs | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 5f36276..c8f5777 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -422,7 +422,7 @@ fn internal() { unsafe { use std::ffi::CString; let opts = rocksdb_options_create(); - assert!(!opts.0.is_null()); + assert!(!opts.is_null()); rocksdb_options_increase_parallelism(opts, 0); rocksdb_options_optimize_level_style_compaction(opts, 0); @@ -441,7 +441,7 @@ fn internal() { assert!(err.is_null()); let writeopts = rocksdb_writeoptions_create(); - assert!(!writeopts.0.is_null()); + assert!(!writeopts.is_null()); let key = b"name\x00"; let val = b"spacejam\x00"; @@ -456,7 +456,7 @@ fn internal() { assert!(err.is_null()); let readopts = rocksdb_readoptions_create(); - assert!(!readopts.0.is_null()); + assert!(!readopts.is_null()); let val_len: size_t = 0; let val_len_ptr = &val_len as *const size_t; diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 176afda..6a801d3 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -329,8 +329,7 @@ impl Options { impl WriteOptions { pub fn new() -> WriteOptions { let write_opts = unsafe { rocksdb_ffi::rocksdb_writeoptions_create() }; - let rocksdb_ffi::DBWriteOptions(opt_ptr) = write_opts; - if opt_ptr.is_null() { + if write_opts.is_null() { panic!("Could not create rocksdb write options".to_string()); } WriteOptions { inner: write_opts } From 8d0024e95f188eec085e5312982850aa90c64055 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 1 May 2016 16:48:29 -0700 Subject: [PATCH 3/6] bump to 0.3.3 --- Cargo.toml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 915df2b..49fc4f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rocksdb" description = "A Rust wrapper for Facebook's RocksDB embeddable database." -version = "0.3.2" +version = "0.3.3" authors = ["Tyler Neely ", "David Greenberg "] license = "Apache-2.0" keywords = ["database", "embedded", "LSM-tree", "persistence"] diff --git a/README.md b/README.md index 5d96e40..457dcc2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ rust-rocksdb [![Build Status](https://travis-ci.org/spacejam/rust-rocksdb.svg?branch=master)](https://travis-ci.org/spacejam/rust-rocksdb) [![crates.io](http://meritbadge.herokuapp.com/rocksdb)](https://crates.io/crates/rocksdb) -This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.2 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. +This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.3 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. ### status - [x] basic open/put/get/delete/close @@ -36,7 +36,7 @@ sudo make install ###### Cargo.toml ```rust [dependencies] -rocksdb = "0.3.2" +rocksdb = "0.3.3" ``` ###### Code ```rust From c005eb9c223f219fbaf885b01f9d5012ab8cd674 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Mon, 2 May 2016 08:56:12 -0700 Subject: [PATCH 4/6] Bump libc crate to 0.2.10, fix the improper use of u64 where usize should have been used in some places. --- Cargo.toml | 2 +- src/ffi.rs | 8 ++++---- src/rocksdb_options.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49fc4f9..625bd9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ name = "test" path = "test/test.rs" [dependencies] -libc = "0.1.8" +libc = "0.2.10" diff --git a/src/ffi.rs b/src/ffi.rs index c8f5777..741d6d5 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -162,17 +162,17 @@ extern "C" { pub fn rocksdb_options_set_level0_stop_writes_trigger(options: DBOptions, no: c_int); pub fn rocksdb_options_set_write_buffer_size(options: DBOptions, - bytes: u64); + bytes: usize); pub fn rocksdb_options_set_target_file_size_base(options: DBOptions, bytes: u64); pub fn rocksdb_options_set_target_file_size_multiplier(options: DBOptions, mul: c_int); pub fn rocksdb_options_set_max_log_file_size(options: DBOptions, - bytes: u64); + bytes: usize); pub fn rocksdb_options_set_max_manifest_file_size(options: DBOptions, - bytes: u64); + bytes: usize); pub fn rocksdb_options_set_hash_skip_list_rep(options: DBOptions, - bytes: u64, + bytes: usize, a1: i32, a2: i32); pub fn rocksdb_options_set_compaction_style(options: DBOptions, diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 6a801d3..a3e9469 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -69,7 +69,7 @@ impl BlockBasedOptions { BlockBasedOptions { inner: block_opts } } - pub fn set_block_size(&mut self, size: u64) { + pub fn set_block_size(&mut self, size: usize) { unsafe { rocksdb_ffi::rocksdb_block_based_options_set_block_size(self.inner, size); From 5f438b154761cc64ca01af73d05ff1729b1444b5 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Mon, 2 May 2016 09:34:57 -0700 Subject: [PATCH 5/6] bump to 0.3.4 --- Cargo.toml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49fc4f9..4ca8075 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rocksdb" description = "A Rust wrapper for Facebook's RocksDB embeddable database." -version = "0.3.3" +version = "0.3.4" authors = ["Tyler Neely ", "David Greenberg "] license = "Apache-2.0" keywords = ["database", "embedded", "LSM-tree", "persistence"] diff --git a/README.md b/README.md index 457dcc2..9ce1f94 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ rust-rocksdb [![Build Status](https://travis-ci.org/spacejam/rust-rocksdb.svg?branch=master)](https://travis-ci.org/spacejam/rust-rocksdb) [![crates.io](http://meritbadge.herokuapp.com/rocksdb)](https://crates.io/crates/rocksdb) -This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.3 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. +This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.4 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. ### status - [x] basic open/put/get/delete/close @@ -36,7 +36,7 @@ sudo make install ###### Cargo.toml ```rust [dependencies] -rocksdb = "0.3.3" +rocksdb = "0.3.4" ``` ###### Code ```rust From ea77df7e6ea678cad06e276caae40f303f6051cf Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Mon, 2 May 2016 09:38:13 -0700 Subject: [PATCH 6/6] bump to 0.3.5 --- Cargo.toml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efad13a..e808242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rocksdb" description = "A Rust wrapper for Facebook's RocksDB embeddable database." -version = "0.3.4" +version = "0.3.5" authors = ["Tyler Neely ", "David Greenberg "] license = "Apache-2.0" keywords = ["database", "embedded", "LSM-tree", "persistence"] diff --git a/README.md b/README.md index 9ce1f94..1a7a045 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ rust-rocksdb [![Build Status](https://travis-ci.org/spacejam/rust-rocksdb.svg?branch=master)](https://travis-ci.org/spacejam/rust-rocksdb) [![crates.io](http://meritbadge.herokuapp.com/rocksdb)](https://crates.io/crates/rocksdb) -This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.4 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. +This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.3.5 crate should work with the Rust 1.5 stable and nightly releases as of 5/1/16. ### status - [x] basic open/put/get/delete/close @@ -36,7 +36,7 @@ sudo make install ###### Cargo.toml ```rust [dependencies] -rocksdb = "0.3.4" +rocksdb = "0.3.5" ``` ###### Code ```rust