about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-02 21:22:14 +0000
committerbors <bors@rust-lang.org>2014-11-02 21:22:14 +0000
commita294b35060e069007ee46e190a6f0a19fa3eaab8 (patch)
tree4201a43fec3a750a6fb28e1fa67beddf7a3b249c /src/libstd
parent0c1268451b1f51fdaa31938707df8c56f08cfb31 (diff)
parentfea985a0b5008bc2f441866a80c0e3a16592eaab (diff)
downloadrust-a294b35060e069007ee46e190a6f0a19fa3eaab8.tar.gz
rust-a294b35060e069007ee46e190a6f0a19fa3eaab8.zip
auto merge of #18406 : thestinger/rust/oom, r=cmr
This makes the low-level allocation API suitable for use cases where
out-of-memory conditions need to be handled.

Closes #18292

[breaking-change]
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_vec.rs2
-rw-r--r--src/libstd/collections/hashmap/table.rs1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs
index fd605bb2b5c..771184df53d 100644
--- a/src/libstd/c_vec.rs
+++ b/src/libstd/c_vec.rs
@@ -170,7 +170,7 @@ mod tests {
     fn malloc(n: uint) -> CVec<u8> {
         unsafe {
             let mem = libc::malloc(n as libc::size_t);
-            if mem.is_null() { panic!("out of memory") }
+            if mem.is_null() { ::alloc::oom() }
 
             CVec::new_with_dtor(mem as *mut u8, n,
                 proc() { libc::free(mem as *mut libc::c_void); })
diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs
index faff68c75ff..4d73029b7b0 100644
--- a/src/libstd/collections/hashmap/table.rs
+++ b/src/libstd/collections/hashmap/table.rs
@@ -607,6 +607,7 @@ impl<K, V> RawTable<K, V> {
                 "capacity overflow");
 
         let buffer = allocate(size, malloc_alignment);
+        if buffer.is_null() { ::alloc::oom() }
 
         let hashes = buffer.offset(hash_offset as int) as *mut u64;