Switch to alloc shim

This commit is contained in:
Manish Goregaokar 2017-08-25 17:42:18 -07:00
parent d1c0eb9f2c
commit 96b3d0a735
3 changed files with 12 additions and 15 deletions

View file

@ -1,3 +1,7 @@
// FORK NOTE: Copied from libsystem_alloc, removed unnecessary APIs,
// APIs take size/align directly instead of Layout
// The minimum alignment guaranteed by the architecture. This value is used to // The minimum alignment guaranteed by the architecture. This value is used to

View file

@ -1,16 +1,9 @@
#![feature(allocator_api)]
#![feature(alloc)]
extern crate alloc;
pub use std::*; pub use std::*;
mod bench; mod bench;
mod table; mod table;
mod shim; mod shim;
#[path="alloc.rs"] mod alloc;
mod alloc2;
pub mod hash_map; pub mod hash_map;
pub mod hash_set; pub mod hash_set;

View file

@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use alloc::heap::{Heap, Alloc, Layout}; use alloc::{alloc, dealloc};
use cmp; use cmp;
use hash::{BuildHasher, Hash, Hasher}; use hash::{BuildHasher, Hash, Hasher};
use marker; use marker;
@ -756,8 +755,10 @@ impl<K, V> RawTable<K, V> {
.expect("capacity overflow"), .expect("capacity overflow"),
"capacity overflow"); "capacity overflow");
let buffer = Heap.alloc(Layout::from_size_align(size, alignment).unwrap()) // FORK NOTE: Uses alloc shim instead of Heap.alloc
.unwrap_or_else(|e| Heap.oom(e)); let buffer = alloc(size, alignment);
// FORK NOTE: Should handle null
debug_assert!(!buffer.is_null());
let hashes = buffer.offset(hash_offset as isize) as *mut HashUint; let hashes = buffer.offset(hash_offset as isize) as *mut HashUint;
@ -1162,7 +1163,7 @@ impl<K, V> Drop for RawTable<K, V> {
let hashes_size = self.capacity() * size_of::<HashUint>(); let hashes_size = self.capacity() * size_of::<HashUint>();
let pairs_size = self.capacity() * size_of::<(K, V)>(); let pairs_size = self.capacity() * size_of::<(K, V)>();
let (align, _, size, oflo) = calculate_allocation(hashes_size, let (align, _, _, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(), align_of::<HashUint>(),
pairs_size, pairs_size,
align_of::<(K, V)>()); align_of::<(K, V)>());
@ -1170,8 +1171,7 @@ impl<K, V> Drop for RawTable<K, V> {
debug_assert!(!oflo, "should be impossible"); debug_assert!(!oflo, "should be impossible");
unsafe { unsafe {
Heap.dealloc(self.hashes.ptr() as *mut u8, dealloc(self.hashes.ptr() as *mut u8, align);
Layout::from_size_align(size, align).unwrap());
// Remember how everything was allocated out of one buffer // Remember how everything was allocated out of one buffer
// during initialization? We only need one call to free here. // during initialization? We only need one call to free here.
} }