Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2132,16 +2132,12 @@ impl<'de, T: serde::Deserialize<'de>> serde::Deserialize<'de> for ThinVec<T> {
#[cfg(feature = "malloc_size_of")]
impl<T> MallocShallowSizeOf for ThinVec<T> {
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
if self.capacity() == 0 {
// If it's the singleton we might not be a heap pointer.
if self.capacity() == 0 || self.uses_stack_allocated_buffer() {
// We're not a heap pointer.
return 0;
}

assert_eq!(
core::mem::size_of::<Self>(),
core::mem::size_of::<*const ()>()
);
unsafe { ops.malloc_size_of(*(self as *const Self as *const *const ())) }
unsafe { ops.malloc_size_of(self.ptr() as _) }
}
}

Expand Down Expand Up @@ -4829,4 +4825,23 @@ mod std_tests {
v.push(PanicBomb("normal2"));
v.clear();
}

#[cfg(all(feature = "gecko-ffi", feature = "malloc_size_of"))]
#[test]
fn malloc_size_of_auto_array() {
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps};
use std::ffi::c_void;

extern "C" {
fn malloc_usable_size(ptr: *const c_void) -> usize;
}

unsafe extern "C" fn malloc_size_of(ptr: *const c_void) -> usize {
unsafe { malloc_usable_size(ptr) }
}

crate::auto_thin_vec!(let t: [u8; 4]);
let mut ops = MallocSizeOfOps::new(malloc_size_of, None, None);
let _ = MallocShallowSizeOf::shallow_size_of(&**t, &mut ops);
}
}
Loading