trivially implement PassByValue for usize
This commit is contained in:
15
lib/src/atomic.rs
Normal file
15
lib/src/atomic.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//! Trait implementations for a few atomic types
|
||||||
|
|
||||||
|
use crate::traits::*;
|
||||||
|
|
||||||
|
impl PassByValue for usize {
|
||||||
|
type CType = usize;
|
||||||
|
|
||||||
|
unsafe fn from_ctype(arg: usize) -> usize {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_ctype(self) -> usize {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ mod traits;
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub mod arrays;
|
pub mod arrays;
|
||||||
|
pub mod atomic;
|
||||||
pub mod replica;
|
pub mod replica;
|
||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|||||||
@@ -248,15 +248,14 @@ pub extern "C" fn tc_string_content_with_len(
|
|||||||
// - lifetime of tcstring outlives the lifetime of this function
|
// - lifetime of tcstring outlives the lifetime of this function
|
||||||
// - lifetime of tcstring outlives the lifetime of the returned pointer (promised by caller)
|
// - lifetime of tcstring outlives the lifetime of the returned pointer (promised by caller)
|
||||||
let tcstring = unsafe { TCString::from_arg_ref(tcstring) };
|
let tcstring = unsafe { TCString::from_arg_ref(tcstring) };
|
||||||
debug_assert!(!len_out.is_null());
|
|
||||||
|
|
||||||
let bytes = tcstring.as_bytes();
|
let bytes = tcstring.as_bytes();
|
||||||
|
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - len_out is not NULL (checked by assertion, promised by caller)
|
// - len_out is not NULL (promised by caller)
|
||||||
// - len_out points to valid memory (promised by caller)
|
// - len_out points to valid memory (promised by caller)
|
||||||
// - len_out is properly aligned (C convention)
|
// - len_out is properly aligned (C convention)
|
||||||
unsafe { *len_out = bytes.len() };
|
unsafe { bytes.len().to_arg_out(len_out) };
|
||||||
bytes.as_ptr() as *const libc::c_char
|
bytes.as_ptr() as *const libc::c_char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user