diff options
| author | bors <bors@rust-lang.org> | 2014-01-19 04:31:53 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-19 04:31:53 -0800 |
| commit | 52f1d905b0c7a0f99f4e2a7c330acc86b9700cb0 (patch) | |
| tree | 331d42fcdd57363310a543e1ebad20b1e0554189 /src/libextra | |
| parent | 53733c87b64855ac8f15ea3886e6a8ed6097545a (diff) | |
| parent | ae2a5ecbf600495a80ae4d99853a2ed2c8f6b5e9 (diff) | |
| download | rust-52f1d905b0c7a0f99f4e2a7c330acc86b9700cb0.tar.gz rust-52f1d905b0c7a0f99f4e2a7c330acc86b9700cb0.zip | |
auto merge of #11635 : thestinger/rust/zero-size-alloc, r=alexcrichton
The `malloc` family of functions may return a null pointer for a zero-size allocation, which should not be interpreted as an out-of-memory error. If the implementation does not return a null pointer, then handling this will result in memory savings for zero-size types. This also switches some code to `malloc_raw` in order to maintain a centralized point for handling out-of-memory in `rt::global_heap`. Closes #11634
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/c_vec.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libextra/c_vec.rs b/src/libextra/c_vec.rs index 68499cf7032..fc2caa13584 100644 --- a/src/libextra/c_vec.rs +++ b/src/libextra/c_vec.rs @@ -160,21 +160,19 @@ impl <T> Container for CVec<T> { #[cfg(test)] mod tests { - use super::*; use std::libc::*; use std::libc; use std::ptr; + use std::rt::global_heap::malloc_raw; fn malloc(n: uint) -> CVec<u8> { unsafe { - let mem = libc::malloc(n as size_t); - - assert!(mem as int != 0); + let mem = malloc_raw(n); CVec::new_with_dtor(mem as *mut u8, n, - proc() { libc::free(mem); }) + proc() { libc::free(mem as *c_void); }) } } |
