-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Replace most uses of pointer::offset
with add
and sub
#100822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,8 +326,8 @@ where | |
unsafe { | ||
// Branchless comparison. | ||
*end_l = i as u8; | ||
end_l = end_l.offset(!is_less(&*elem, pivot) as isize); | ||
elem = elem.offset(1); | ||
end_l = end_l.add(!is_less(&*elem, pivot) as usize); | ||
elem = elem.add(1); | ||
} | ||
} | ||
} | ||
|
@@ -352,9 +352,9 @@ where | |
// Plus, `block_r` was asserted to be less than `BLOCK` and `elem` will therefore at most be pointing to the beginning of the slice. | ||
unsafe { | ||
// Branchless comparison. | ||
elem = elem.offset(-1); | ||
elem = elem.sub(1); | ||
*end_r = i as u8; | ||
end_r = end_r.offset(is_less(&*elem, pivot) as isize); | ||
end_r = end_r.add(is_less(&*elem, pivot) as usize); | ||
} | ||
} | ||
} | ||
|
@@ -365,12 +365,12 @@ where | |
if count > 0 { | ||
macro_rules! left { | ||
() => { | ||
l.offset(*start_l as isize) | ||
l.add(*start_l as usize) | ||
}; | ||
} | ||
macro_rules! right { | ||
() => { | ||
r.offset(-(*start_r as isize) - 1) | ||
r.sub((*start_r as usize) + 1) | ||
}; | ||
} | ||
|
||
|
@@ -398,16 +398,16 @@ where | |
ptr::copy_nonoverlapping(right!(), left!(), 1); | ||
|
||
for _ in 1..count { | ||
start_l = start_l.offset(1); | ||
start_l = start_l.add(1); | ||
ptr::copy_nonoverlapping(left!(), right!(), 1); | ||
start_r = start_r.offset(1); | ||
start_r = start_r.add(1); | ||
ptr::copy_nonoverlapping(right!(), left!(), 1); | ||
} | ||
|
||
ptr::copy_nonoverlapping(&tmp, right!(), 1); | ||
mem::forget(tmp); | ||
start_l = start_l.offset(1); | ||
start_r = start_r.offset(1); | ||
start_l = start_l.add(1); | ||
start_r = start_r.add(1); | ||
} | ||
} | ||
|
||
|
@@ -420,15 +420,15 @@ where | |
// safe. Otherwise, the debug assertions in the `is_done` case guarantee that | ||
// `width(l, r) == block_l + block_r`, namely, that the block sizes have been adjusted to account | ||
// for the smaller number of remaining elements. | ||
l = unsafe { l.offset(block_l as isize) }; | ||
l = unsafe { l.add(block_l) }; | ||
} | ||
|
||
if start_r == end_r { | ||
// All out-of-order elements in the right block were moved. Move to the previous block. | ||
|
||
// SAFETY: Same argument as [block-width-guarantee]. Either this is a full block `2*BLOCK`-wide, | ||
// or `block_r` has been adjusted for the last handful of elements. | ||
r = unsafe { r.offset(-(block_r as isize)) }; | ||
r = unsafe { r.sub(block_r) }; | ||
} | ||
|
||
if is_done { | ||
|
@@ -457,9 +457,9 @@ where | |
// - `offsets_l` contains valid offsets into `v` collected during the partitioning of | ||
// the last block, so the `l.offset` calls are valid. | ||
unsafe { | ||
end_l = end_l.offset(-1); | ||
ptr::swap(l.offset(*end_l as isize), r.offset(-1)); | ||
r = r.offset(-1); | ||
end_l = end_l.sub(1); | ||
ptr::swap(l.add(*end_l as usize), r.sub(1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this PR, but consider following along to use |
||
r = r.sub(1); | ||
} | ||
} | ||
width(v.as_mut_ptr(), r) | ||
|
@@ -470,9 +470,9 @@ where | |
while start_r < end_r { | ||
// SAFETY: See the reasoning in [remaining-elements-safety]. | ||
unsafe { | ||
end_r = end_r.offset(-1); | ||
ptr::swap(l, r.offset(-(*end_r as isize) - 1)); | ||
l = l.offset(1); | ||
end_r = end_r.sub(1); | ||
ptr::swap(l, r.sub((*end_r as usize) + 1)); | ||
l = l.add(1); | ||
} | ||
} | ||
width(v.as_mut_ptr(), l) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) -> Result | |
|
||
let call_site_encoding = reader.read::<u8>(); | ||
let call_site_table_length = reader.read_uleb128(); | ||
let action_table = reader.ptr.offset(call_site_table_length as isize); | ||
let action_table = reader.ptr.add(call_site_table_length as usize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this PR's problem, but it's interesting that this reads a |
||
let ip = context.ip; | ||
|
||
if !USING_SJLJ_EXCEPTIONS { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,12 @@ fn test_copy_function() { | |
dst.copy_from_enclave(&[0u8; 100]); | ||
|
||
// Copy src[0..size] to dst + offset | ||
unsafe { copy_to_userspace(src.as_ptr(), dst.as_mut_ptr().offset(offset), size) }; | ||
unsafe { copy_to_userspace(src.as_ptr(), dst.as_mut_ptr().add(offset), size) }; | ||
|
||
// Verify copy | ||
for byte in 0..size { | ||
unsafe { | ||
assert_eq!(*dst.as_ptr().offset(offset + byte as isize), src[byte as usize]); | ||
assert_eq!(*dst.as_ptr().add(offset + byte), src[byte as usize]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sneaky: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like (It would be nice to have a warning for T-to-T There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about linting T2T casts too, while doing these refactorings. It should probably be easy to add 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the problem is if you want to keep it -- say it's there to be resilient to For a clippy lint saying "hey, just allow it" is fine, but for rustc lints we generally want to be able to give a "or write ______ instead to make it obvious why you want to keep it like this" suggestion. Nothing jumped to mind to me for how to do that, but hopefully you'll come up with something clever to lint only in the valuable places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not linting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a second thought, would this still be useful as a allow-by-default lint? 🤔 |
||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.