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

View file

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

View file

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