diff options
author | Boris Chiou <boris.chiou@gmail.com> | 2017-12-19 17:00:20 -0500 |
---|---|---|
committer | Boris Chiou <boris.chiou@gmail.com> | 2018-01-02 11:31:03 +0800 |
commit | aebe2cfac213eb29744845ae3f87b25bed69c0dc (patch) | |
tree | a348fc697cd0ecccf8e0c5884fb215629df82ffc | |
parent | 2a139cebacc02b3ae04974e1e5b2b601df5b774c (diff) | |
download | servo-aebe2cfac213eb29744845ae3f87b25bed69c0dc.tar.gz servo-aebe2cfac213eb29744845ae3f87b25bed69c0dc.zip |
Dump the requested aligment if out of memory while allocating a table.
-rw-r--r-- | components/hashglobe/src/lib.rs | 20 | ||||
-rw-r--r-- | components/hashglobe/src/table.rs | 3 |
2 files changed, 17 insertions, 6 deletions
diff --git a/components/hashglobe/src/lib.rs b/components/hashglobe/src/lib.rs index 6431d335031..49038a51859 100644 --- a/components/hashglobe/src/lib.rs +++ b/components/hashglobe/src/lib.rs @@ -27,16 +27,24 @@ trait Recover<Q: ?Sized> { } #[derive(Debug)] +pub struct AllocationInfo { + /// The size we are requesting. + size: usize, + /// The alignment we are requesting. + alignment: usize, +} + +#[derive(Debug)] pub struct FailedAllocationError { reason: &'static str, - /// The size we are allocating, if needed. - allocation_size: Option<usize>, + /// The allocation info we are requesting, if needed. + allocation_info: Option<AllocationInfo>, } impl FailedAllocationError { #[inline] pub fn new(reason: &'static str) -> Self { - Self { reason, allocation_size: None } + Self { reason, allocation_info: None } } } @@ -48,8 +56,10 @@ impl error::Error for FailedAllocationError { impl fmt::Display for FailedAllocationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self.allocation_size { - Some(size) => write!(f, "{}, allocation size: {}", self.reason, size), + match self.allocation_info { + Some(ref info) => { + write!(f, "{}, allocation: (size: {}, alignment: {})", self.reason, info.size, info.alignment) + }, None => self.reason.fmt(f), } } diff --git a/components/hashglobe/src/table.rs b/components/hashglobe/src/table.rs index 668b688dbac..bd801b43544 100644 --- a/components/hashglobe/src/table.rs +++ b/components/hashglobe/src/table.rs @@ -778,9 +778,10 @@ impl<K, V> RawTable<K, V> { let buffer = alloc(size, alignment); if buffer.is_null() { + use AllocationInfo; return Err(FailedAllocationError { reason: "out of memory when allocating RawTable", - allocation_size: Some(size), + allocation_info: Some(AllocationInfo { size, alignment }), }); } |