mark FIXMES for all the places found that are probably offset_from

This commit is contained in:
Aria Beingessner 2022-03-28 00:43:18 -04:00
parent 5f720fa55e
commit 28576e9c51
3 changed files with 10 additions and 0 deletions

View File

@ -217,6 +217,8 @@ impl<T> TypedArena<T> {
#[inline]
fn can_allocate(&self, additional: usize) -> bool {
// FIXME: this should *likely* use `offset_from`, but more
// investigation is needed (including running tests in miri).
let available_bytes = self.end.get().addr() - self.ptr.get().addr();
let additional_bytes = additional.checked_mul(mem::size_of::<T>()).unwrap();
available_bytes >= additional_bytes
@ -263,6 +265,8 @@ impl<T> TypedArena<T> {
// If a type is `!needs_drop`, we don't need to keep track of how many elements
// the chunk stores - the field will be ignored anyway.
if mem::needs_drop::<T>() {
// FIXME: this should *likely* use `offset_from`, but more
// investigation is needed (including running tests in miri).
let used_bytes = self.ptr.get().addr() - last_chunk.start().addr();
last_chunk.entries = used_bytes / mem::size_of::<T>();
}
@ -300,6 +304,8 @@ impl<T> TypedArena<T> {
// Recall that `end` was incremented for each allocated value.
end - start
} else {
// FIXME: this should *likely* use `offset_from`, but more
// investigation is needed (including running tests in miri).
(end - start) / mem::size_of::<T>()
};
// Pass that to the `destroy` method.

View File

@ -269,6 +269,8 @@ where
// Returns the number of elements between pointers `l` (inclusive) and `r` (exclusive).
fn width<T>(l: *mut T, r: *mut T) -> usize {
assert!(mem::size_of::<T>() > 0);
// FIXME: this should *likely* use `offset_from`, but more
// investigation is needed (including running tests in miri).
(r.addr() - l.addr()) / mem::size_of::<T>()
}

View File

@ -26,6 +26,8 @@ pub fn memrchr(needle: u8, haystack: &[u8]) -> Option<usize> {
haystack.len(),
)
};
// FIXME: this should *likely* use `offset_from`, but more
// investigation is needed (including running tests in miri).
if p.is_null() { None } else { Some(p.addr() - haystack.as_ptr().addr()) }
}