From 2684aec4c6001f6ebd4b3c74ca7b2649d28b996a Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 2 Oct 2017 03:38:31 +0000 Subject: [PATCH] firmware: use read_unaligned instead of a hack. NFC. --- artiq/firmware/ksupport/eh.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/artiq/firmware/ksupport/eh.rs b/artiq/firmware/ksupport/eh.rs index ef2bf96cf..6138969a4 100644 --- a/artiq/firmware/ksupport/eh.rs +++ b/artiq/firmware/ksupport/eh.rs @@ -53,15 +53,6 @@ struct DwarfReader { pub ptr: *const u8, } -#[repr(C,packed)] -#[derive(Clone, Copy)] -struct Unaligned(T); - -// This contortion is required due to https://github.com/rust-lang/rust/issues/27060. -impl Unaligned { - fn get(self) -> T { self.0 } -} - impl DwarfReader { fn new(ptr: *const u8) -> DwarfReader { DwarfReader { ptr: ptr } @@ -72,9 +63,9 @@ impl DwarfReader { // alignment requirements. By wrapping data in a "packed" struct, we are // telling the backend to generate "misalignment-safe" code. unsafe fn read(&mut self) -> T { - let result = *(self.ptr as *const Unaligned); + let result = ptr::read_unaligned(self.ptr as *const T); self.ptr = self.ptr.offset(mem::size_of::() as isize); - result.get() + result } // ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable