mirror of
https://github.com/servo/servo.git
synced 2025-07-01 20:43:39 +01:00
Dump the requested aligment if out of memory while allocating a table.
This commit is contained in:
parent
2a139cebac
commit
aebe2cfac2
2 changed files with 17 additions and 6 deletions
|
@ -26,17 +26,25 @@ trait Recover<Q: ?Sized> {
|
||||||
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
|
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AllocationInfo {
|
||||||
|
/// The size we are requesting.
|
||||||
|
size: usize,
|
||||||
|
/// The alignment we are requesting.
|
||||||
|
alignment: usize,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FailedAllocationError {
|
pub struct FailedAllocationError {
|
||||||
reason: &'static str,
|
reason: &'static str,
|
||||||
/// The size we are allocating, if needed.
|
/// The allocation info we are requesting, if needed.
|
||||||
allocation_size: Option<usize>,
|
allocation_info: Option<AllocationInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailedAllocationError {
|
impl FailedAllocationError {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(reason: &'static str) -> Self {
|
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 {
|
impl fmt::Display for FailedAllocationError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self.allocation_size {
|
match self.allocation_info {
|
||||||
Some(size) => write!(f, "{}, allocation size: {}", self.reason, size),
|
Some(ref info) => {
|
||||||
|
write!(f, "{}, allocation: (size: {}, alignment: {})", self.reason, info.size, info.alignment)
|
||||||
|
},
|
||||||
None => self.reason.fmt(f),
|
None => self.reason.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -778,9 +778,10 @@ impl<K, V> RawTable<K, V> {
|
||||||
let buffer = alloc(size, alignment);
|
let buffer = alloc(size, alignment);
|
||||||
|
|
||||||
if buffer.is_null() {
|
if buffer.is_null() {
|
||||||
|
use AllocationInfo;
|
||||||
return Err(FailedAllocationError {
|
return Err(FailedAllocationError {
|
||||||
reason: "out of memory when allocating RawTable",
|
reason: "out of memory when allocating RawTable",
|
||||||
allocation_size: Some(size),
|
allocation_info: Some(AllocationInfo { size, alignment }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue