Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/flatbuffers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flatbuffers"
version = "0.8.4"
version = "0.8.5"
edition = "2018"
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
license = "Apache-2.0"
Expand Down
22 changes: 11 additions & 11 deletions rust/flatbuffers/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ impl<'a, T: 'a, const N: usize> Array<'a, T, N> {
pub fn len(&self) -> usize {
N
}
pub fn as_ptr(&self) -> *const u8 {
self.0.as_ptr()
}
}

impl<'a, T: Follow<'a> + 'a, const N: usize> Array<'a, T, N> {
Expand All @@ -75,14 +78,7 @@ impl<'a, T: Follow<'a> + Debug, const N: usize> Into<[T::Inner; N]> for Array<'a
}
}

impl<'a, T: SafeSliceAccess + 'a, const N: usize> Array<'a, T, N> {
pub fn safe_slice(self) -> &'a [T] {
let sz = size_of::<T>();
debug_assert!(sz > 0);
let ptr = self.0.as_ptr() as *const T;
unsafe { from_raw_parts(ptr, N) }
}
}
// TODO(caspern): Implement some future safe version of SafeSliceAccess.

/// Implement Follow for all possible Arrays that have Follow-able elements.
impl<'a, T: Follow<'a> + 'a, const N: usize> Follow<'a> for Array<'a, T, N> {
Expand All @@ -98,12 +94,16 @@ pub fn emplace_scalar_array<T: EndianScalar, const N: usize>(
loc: usize,
src: &[T; N],
) {
let mut buf_ptr = buf[loc..].as_mut_ptr() as *mut T;
let mut buf_ptr = buf[loc..].as_mut_ptr();
for item in src.iter() {
let item_le = item.to_little_endian();
unsafe {
buf_ptr.write(item_le);
buf_ptr = buf_ptr.add(1);
core::ptr::copy_nonoverlapping(
&item_le as *const T as *const u8,
buf_ptr,
size_of::<T>(),
);
buf_ptr = buf_ptr.add(size_of::<T>());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/RustTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ fi
# RUST_NIGHTLY environment variable set in dockerfile.
if [[ $RUST_NIGHTLY == 1 ]]; then
rustup +nightly component add miri
cargo +nightly miri test -- -Zmiri-disable-isolation
MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
fi
11 changes: 3 additions & 8 deletions tests/rust_usage_test/tests/arrays_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ fn verify_struct_array_alignment() {
let array_table = root_as_array_table(buf).unwrap();
let array_struct = array_table.a().unwrap();
let struct_start_ptr = array_struct.0.as_ptr() as usize;
let b_start_ptr = array_struct.b().safe_slice().as_ptr() as usize;
let d_start_ptr = array_struct.d().safe_slice().as_ptr() as usize;
let b_start_ptr = array_struct.b().as_ptr() as usize;
let d_start_ptr = array_struct.d().as_ptr() as usize;
// The T type of b
let b_aln = ::std::mem::align_of::<i32>();
assert_eq!((b_start_ptr - struct_start_ptr) % b_aln, 0);
Expand Down Expand Up @@ -272,8 +272,6 @@ mod array_fuzz {
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
let got: [$ty; ARRAY_SIZE] = arr.into();
assert_eq!(got, xs.0);
#[cfg(target_endian = "little")]
assert_eq!(arr.safe_slice(), xs.0);
}
#[test]
fn $test_name() {
Expand Down Expand Up @@ -317,13 +315,10 @@ mod array_fuzz {
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
let got: [&NestedStruct; ARRAY_SIZE] = arr.into();
assert_eq!(got, native_struct_array);
let arr_slice = arr.safe_slice();
for i in 0..ARRAY_SIZE {
assert_eq!(arr_slice[i], *native_struct_array[i]);
}
}

#[test]
#[cfg(not(miri))] // slow.
fn test_struct() {
quickcheck::QuickCheck::new().max_tests(MAX_TESTS).quickcheck(prop_struct as fn(FakeArray<NestedStructWrapper, ARRAY_SIZE>));
}
Expand Down
1 change: 1 addition & 0 deletions tests/rust_usage_test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ mod roundtrip_byteswap {
// fn fuzz_f64() { quickcheck::QuickCheck::new().max_tests(N).quickcheck(prop_f64 as fn(f64)); }
}

#[cfg(not(miri))]
quickcheck! {
fn struct_of_structs(
a_id: u32,
Expand Down