From cb5d856e008409c8d1cb6ba74fa9f3917c13b655 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 14 Nov 2018 20:14:36 -0700 Subject: [PATCH] correctness --- src/core_extras.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/core_extras.rs b/src/core_extras.rs index 8322574..aaf6197 100644 --- a/src/core_extras.rs +++ b/src/core_extras.rs @@ -1,11 +1,13 @@ //! Things that I wish were in core, but aren't. -/// A simple wrapper to any `*mut T` so that the basic "read" and "write" -/// operations are volatile. +/// A simple wrapper for any `*mut T` to adjust the basic operations. /// -/// Accessing the GBA's IO registers and video ram and specific other places on -/// **must** be done with volatile operations. Having this wrapper makes that -/// more clear for all the const value IO registers. +/// Read and Write are made to be volatile. Offset is made to be +/// wrapping_offset. This makes it much easier to correctly work with IO +/// Registers and all display related memory on the GBA. +/// +/// As a bonus, use of this type is mostly `cargo test` safe. Reads will return +/// a `zeroed()` value instead, and writes will do nothing. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] pub struct VolatilePtr(pub *mut T); @@ -52,20 +54,13 @@ impl VolatilePtr { } } - /// Offsets this address by the amount given. + /// Performs a wrapping_offset by the number of slots given to a new position. /// /// # Safety /// - /// This is a standard offset, so all safety concerns of a normal raw pointer - /// offset apply. + /// This is a wrapping_offset, so all safety concerns of a normal raw pointer + /// wrapping_offset apply. pub unsafe fn offset(self, count: isize) -> Self { - #[cfg(not(test))] - { - VolatilePtr(self.0.offset(count)) - } - #[cfg(test)] - { - VolatilePtr(self.0.wrapping_offset(count)) - } + VolatilePtr(self.0.wrapping_offset(count)) } }