aboutsummaryrefslogtreecommitdiff
path: root/src/rust/protover/ffi.rs
diff options
context:
space:
mode:
authorChelsea Holland Komlo <me@chelseakomlo.com>2017-10-14 23:05:31 -0400
committerNick Mathewson <nickm@torproject.org>2017-10-27 10:02:08 -0400
commit76bbdfbfa9eca46b53d3ec5a44deafce51d2875a (patch)
treec98dda928f61621d324e889f29ecf31ab9e917cb /src/rust/protover/ffi.rs
parentd14a83f74fcbe5fae97d944ac8f7f8645e160d3a (diff)
downloadtor-76bbdfbfa9eca46b53d3ec5a44deafce51d2875a.tar.gz
tor-76bbdfbfa9eca46b53d3ec5a44deafce51d2875a.zip
add tor allocator for rust
Diffstat (limited to 'src/rust/protover/ffi.rs')
-rw-r--r--src/rust/protover/ffi.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs
index 539b6c0bac..23a289bd56 100644
--- a/src/rust/protover/ffi.rs
+++ b/src/rust/protover/ffi.rs
@@ -8,7 +8,7 @@ use std::ffi::CString;
use protover::*;
use smartlist::*;
-use tor_allocate::allocate_string;
+use tor_allocate::allocate_and_copy_string;
/// Translate C enums to Rust Proto enums, using the integer value of the C
/// enum to map to its associated Rust enum
@@ -124,17 +124,17 @@ pub extern "C" fn protover_compute_vote(
) -> *mut c_char {
if list.is_null() {
- let mut empty = String::new();
- return allocate_string(&mut empty);
+ let empty = String::new();
+ return allocate_and_copy_string(&empty);
}
// Dereference of raw pointer requires an unsafe block. The pointer is
// checked above to ensure it is not null.
let data: Vec<String> = unsafe { (*list).get_list() };
- let mut vote = compute_vote(data, threshold);
+ let vote = compute_vote(data, threshold);
- allocate_string(&mut vote)
+ allocate_and_copy_string(&vote)
}
/// Provide an interface for C to translate arguments and return types for
@@ -162,10 +162,10 @@ pub extern "C" fn protover_compute_for_old_tor(
) -> *mut c_char {
// Not handling errors when unwrapping as the content is controlled
// and is an empty string
- let mut empty = String::new();
+ let empty = String::new();
if version.is_null() {
- return allocate_string(&mut empty);
+ return allocate_and_copy_string(&empty);
}
// Require an unsafe block to read the version from a C string. The pointer
@@ -174,10 +174,10 @@ pub extern "C" fn protover_compute_for_old_tor(
let version = match c_str.to_str() {
Ok(n) => n,
- Err(_) => return allocate_string(&mut empty),
+ Err(_) => return allocate_and_copy_string(&empty),
};
- let mut supported = compute_for_old_tor(&version);
+ let supported = compute_for_old_tor(&version);
- allocate_string(&mut supported)
+ allocate_and_copy_string(&supported)
}