Skip to content

Commit 6d57ded

Browse files
dzfranklindwrensha
authored andcommitted
Use raw pointer instead of reference to fix miri
This changes the signature of a public function but that function is in capnp::private so I don't think it's a breaking change.
1 parent 9678a7c commit 6d57ded

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

capnp/src/private/layout.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ impl WirePointer {
159159
}
160160

161161
#[inline]
162-
pub fn target(&self) -> *const u8 {
163-
let this_addr: *const u8 = self as *const _ as *const _;
164-
unsafe { this_addr.offset(8 * (1 + ((self.offset_and_kind.get() as i32) >> 2)) as isize) }
162+
pub fn target(ptr: *const Self) -> *const u8 {
163+
let this_addr: *const u8 = ptr as *const _;
164+
unsafe { this_addr.offset(8 * (1 + (((*ptr).offset_and_kind.get() as i32) >> 2)) as isize) }
165165
}
166166

167167
// At one point, we had `&self` here instead of `ptr: *const Self`, but miri
@@ -874,7 +874,7 @@ mod wire_helpers {
874874
ptr::write_bytes(dst, 0, 1);
875875
(ptr::null_mut(), dst, segment_id)
876876
} else {
877-
let src_ptr = (*src).target();
877+
let src_ptr = WirePointer::target(src);
878878
let (dst_ptr, dst, segment_id) = allocate(
879879
arena,
880880
dst,
@@ -909,7 +909,7 @@ mod wire_helpers {
909909
u64::from((*src).list_element_count())
910910
* u64::from(data_bits_per_element((*src).list_element_size())),
911911
);
912-
let src_ptr = (*src).target();
912+
let src_ptr = WirePointer::target(src);
913913
let (dst_ptr, dst, segment_id) =
914914
allocate(arena, dst, segment_id, word_count, WirePointerKind::List);
915915
ptr::copy_nonoverlapping(
@@ -925,7 +925,7 @@ mod wire_helpers {
925925
}
926926

927927
ElementSize::Pointer => {
928-
let src_refs: *const WirePointer = (*src).target() as _;
928+
let src_refs: *const WirePointer = WirePointer::target(src) as _;
929929
let (dst_refs, dst, segment_id) = allocate(
930930
arena,
931931
dst,
@@ -947,7 +947,7 @@ mod wire_helpers {
947947
(dst_refs, dst, segment_id)
948948
}
949949
ElementSize::InlineComposite => {
950-
let src_ptr = (*src).target();
950+
let src_ptr = WirePointer::target(src);
951951
let (dst_ptr, dst, segment_id) = allocate(
952952
arena,
953953
dst,

0 commit comments

Comments
 (0)