Skip to content

Commit

Permalink
More syntactic noise to work around unaligned ref warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Sep 2, 2021
1 parent 9c0bb84 commit 655d5e3
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions rts/motoko-rts/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::print::*;
use crate::types::*;

use core::fmt::Write;
use core::ptr::addr_of;

/// Print an object. The argument can be a skewed pointer to a boxed object, or a tagged scalar.
#[cfg(feature = "ic")]
Expand Down Expand Up @@ -157,7 +158,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_OBJ_IND => {
let obj_ind = obj as *const ObjInd;
let _ = write!(buf, "<ObjInd field={:#x}>", (*obj_ind).field.get_raw());
let _ = write!(
buf,
"<ObjInd field={:#x}>",
(&*addr_of!((*obj_ind).field)).get_raw()
);
}
TAG_ARRAY => {
let array = obj as *mut Array;
Expand All @@ -179,23 +184,31 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_MUTBOX => {
let mutbox = obj as *const MutBox;
let _ = write!(buf, "<MutBox field={:#x}>", (*mutbox).field.get_raw());
let _ = write!(
buf,
"<MutBox field={:#x}>",
(&*addr_of!((*mutbox).field)).get_raw()
);
}
TAG_CLOSURE => {
let closure = obj as *const Closure;
let _ = write!(buf, "<Closure size={:#x}>", { (*closure).size });
}
TAG_SOME => {
let some = obj as *const Some;
let _ = write!(buf, "<Some field={:#x}>", (*some).field.get_raw());
let _ = write!(
buf,
"<Some field={:#x}>",
(&*addr_of!((*some).field)).get_raw()
);
}
TAG_VARIANT => {
let variant = obj as *const Variant;
let _ = write!(
buf,
"<Variant tag={:#x} field={:#x}>",
{ (*variant).tag },
(*variant).field.get_raw()
(&*addr_of!((*variant).field)).get_raw()
);
}
TAG_BLOB => {
Expand All @@ -204,7 +217,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_FWD_PTR => {
let ind = obj as *const FwdPtr;
let _ = write!(buf, "<Forwarding to {:#x}>", (*ind).fwd.get_raw());
let _ = write!(
buf,
"<Forwarding to {:#x}>",
(&*addr_of!((*ind).fwd)).get_raw()
);
}
TAG_BITS32 => {
let bits32 = obj as *const Bits32;
Expand All @@ -220,8 +237,8 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
buf,
"<Concat n_bytes={:#x} obj1={:#x} obj2={:#x}>",
(*concat).n_bytes.0,
(*concat).text1.get_raw(),
(*concat).text2.get_raw(),
(&*addr_of!((*concat).text1)).get_raw(),
(&*addr_of!((*concat).text2)).get_raw(),
);
}
TAG_ONE_WORD_FILLER => {
Expand Down

0 comments on commit 655d5e3

Please sign in to comment.