-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c ffi #39
Open
hanabi1224
wants to merge
9
commits into
michaelsproul:master
Choose a base branch
from
hanabi1224:cffi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
c ffi #39
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6eed4dd
first batch
8b9eac9
feature cffi
hanabi1224 e41b482
impl TrieKey for CStr and CString
hanabi1224 5adc9a9
Use CString as key type
hanabi1224 ab9d7b9
fix build
hanabi1224 ff7d4c9
Merge branch 'master' into cffi
hanabi1224 259fb4e
resolve comments
hanabi1224 7355479
cargo fmt
160c2b0
remove cast
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use libc::c_char; | ||
use std::ffi::CString; | ||
|
||
use super::trie_common::TrieCommon; | ||
use super::Trie; | ||
|
||
ffi_fn! { | ||
fn radix_trie_create()-> *mut Trie<CString, usize>{ | ||
let trie = Trie::<CString, usize>::new(); | ||
return Box::into_raw(Box::new(trie)); | ||
} | ||
} | ||
|
||
ffi_fn! { | ||
fn radix_trie_free(trie_ptr: *mut Trie<CString, usize>){ | ||
unsafe { Box::from_raw(trie_ptr as *mut Trie<CString, usize>); } | ||
} | ||
} | ||
|
||
ffi_fn! { | ||
fn radix_trie_insert(trie_ptr:*mut Trie<CString, usize>, key_ptr:*const c_char, value:usize){ | ||
let trie = unsafe { &mut *(trie_ptr as *mut Trie<CString, usize>) }; | ||
let key = unsafe { CString::from_raw(key_ptr as *mut c_char) }; | ||
trie.insert(key, value); | ||
} | ||
} | ||
|
||
ffi_fn! { | ||
fn radix_trie_len(trie_ptr:*const Trie<CString, usize>)->usize{ | ||
let trie = unsafe { &*trie_ptr }; | ||
return trie.len(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
//! | ||
//! To get started, see the docs for `Trie` below. | ||
|
||
// #![deny(warnings)] | ||
// #![warn(missing_docs)] | ||
|
||
extern crate endian_type; | ||
|
@@ -11,13 +12,21 @@ extern crate quickcheck; | |
#[cfg(test)] | ||
extern crate rand; | ||
|
||
#[macro_use] | ||
mod macros; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate, delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
#[cfg(feature = "cffi")] | ||
extern crate libc; | ||
#[cfg(feature = "cffi")] | ||
mod c_ffi; | ||
#[cfg(feature = "cffi")] | ||
pub use c_ffi::*; | ||
|
||
pub use keys::TrieKey; | ||
pub use nibble_vec::NibbleVec; | ||
pub use trie_common::TrieCommon; | ||
use trie_node::TrieNode; | ||
|
||
#[macro_use] | ||
mod macros; | ||
pub mod iter; | ||
mod keys; | ||
#[cfg(feature = "serde")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
trie_ptr
argument to this function should be*mut Trie<CString, usize>
, at least to convey the intent that it's a mutable pointer (and to allow us to remove some of the casting gunk)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to run
rustfmt
over the whole project before the build will pass, you can see the.travis.yml
for how to set it upThanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You can remove the cast
(trie_ptr as *mut Trie<CString, usize>)
tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! resolved