diff --git a/components/hashglobe/src/lib.rs b/components/hashglobe/src/lib.rs index 83012473b9e..6431d335031 100644 --- a/components/hashglobe/src/lib.rs +++ b/components/hashglobe/src/lib.rs @@ -29,12 +29,14 @@ trait Recover { #[derive(Debug)] pub struct FailedAllocationError { reason: &'static str, + /// The size we are allocating, if needed. + allocation_size: Option, } impl FailedAllocationError { #[inline] pub fn new(reason: &'static str) -> Self { - Self { reason } + Self { reason, allocation_size: None } } } @@ -46,6 +48,9 @@ impl error::Error for FailedAllocationError { impl fmt::Display for FailedAllocationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.reason.fmt(f) + match self.allocation_size { + Some(size) => write!(f, "{}, allocation size: {}", self.reason, size), + None => self.reason.fmt(f), + } } } diff --git a/components/hashglobe/src/table.rs b/components/hashglobe/src/table.rs index 45dcb2673fa..668b688dbac 100644 --- a/components/hashglobe/src/table.rs +++ b/components/hashglobe/src/table.rs @@ -757,7 +757,7 @@ impl RawTable { align_of::<(K, V)>()); if oflo { - return Err(FailedAllocationError { reason: "capacity overflow when allocating RawTable" }); + return Err(FailedAllocationError::new("capacity overflow when allocating RawTable" )); } // One check for overflow that covers calculation and rounding of size. @@ -767,21 +767,21 @@ impl RawTable { if let Some(cap_bytes) = cap_bytes { if size < cap_bytes { - return Err(FailedAllocationError { reason: "capacity overflow when allocating RawTable" }); + return Err(FailedAllocationError::new("capacity overflow when allocating RawTable")); } } else { - - return Err(FailedAllocationError { reason: "capacity overflow when allocating RawTable" }); + return Err(FailedAllocationError::new("capacity overflow when allocating RawTable")); } - // FORK NOTE: Uses alloc shim instead of Heap.alloc let buffer = alloc(size, alignment); - + if buffer.is_null() { - - return Err(FailedAllocationError { reason: "out of memory when allocating RawTable" }); + return Err(FailedAllocationError { + reason: "out of memory when allocating RawTable", + allocation_size: Some(size), + }); } let hashes = buffer.offset(hash_offset as isize) as *mut HashUint;