Skip to content

Commit

Permalink
Removing allocator-api support
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulstrackx committed Nov 5, 2020
1 parent b99a307 commit 944418c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 65 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,3 @@ jobs:
run: rustup update stable && rustup default stable && rustup target add wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown --release

alloc_api:
name: Allocator API
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo test --features 'allocator-api global'

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ global = []
# Enable very expensive debug checks in this crate
debug = []

# Enable experimental support for the standard library's unstable allocator API.
allocator-api = []
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std']
22 changes: 0 additions & 22 deletions src/global.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#[cfg(feature = "allocator-api")]
use core::alloc::{AllocErr, AllocRef};
use core::alloc::{GlobalAlloc, Layout};
use core::ops::{Deref, DerefMut};
#[cfg(feature = "allocator-api")]
use core::ptr::NonNull;

use Dlmalloc;

Expand Down Expand Up @@ -35,24 +31,6 @@ unsafe impl GlobalAlloc for GlobalDlmalloc {
}
}

#[cfg(feature = "allocator-api")]
unsafe impl AllocRef for GlobalDlmalloc {
#[inline]
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
unsafe { get().alloc(layout) }
}

#[inline]
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
get().dealloc(ptr, layout)
}

#[inline]
fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
unsafe { get().alloc_zeroed(layout) }
}
}

static mut DLMALLOC: Dlmalloc = Dlmalloc::new();

struct Instance;
Expand Down
30 changes: 0 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
//! Support for other platforms is largely untested and unused, but is used when
//! testing this crate.
#![cfg_attr(feature = "allocator-api", feature(allocator_api))]
#![cfg_attr(not(feature = "allocator-api"), allow(dead_code))]
#![no_std]
#![deny(missing_docs)]

#[cfg(feature = "allocator-api")]
use core::alloc::{AllocErr, AllocRef, Layout};
use core::cmp;
use core::ptr;
use sys::System;
Expand Down Expand Up @@ -174,29 +170,3 @@ impl<A: Allocator> Dlmalloc<A> {
}
}
}

#[cfg(feature = "allocator-api")]
unsafe impl AllocRef for Dlmalloc {
#[inline]
fn alloc(&mut self, layout: Layout) -> Result<ptr::NonNull<[u8]>, AllocErr> {
unsafe {
let ptr = <Dlmalloc>::malloc(self, layout.size(), layout.align());
let ptr = ptr::slice_from_raw_parts(ptr, layout.size());
ptr::NonNull::new(ptr as _).ok_or(AllocErr)
}
}

#[inline]
unsafe fn dealloc(&mut self, ptr: ptr::NonNull<u8>, layout: Layout) {
<Dlmalloc>::free(self, ptr.as_ptr(), layout.size(), layout.align())
}

#[inline]
fn alloc_zeroed(&mut self, layout: Layout) -> Result<ptr::NonNull<[u8]>, AllocErr> {
unsafe {
let ptr = <Dlmalloc>::calloc(self, layout.size(), layout.align());
let ptr = ptr::slice_from_raw_parts(ptr, layout.size());
ptr::NonNull::new(ptr as _).ok_or(AllocErr)
}
}
}
2 changes: 1 addition & 1 deletion tests/global.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(all(feature = "allocator-api", feature = "global"))]
#![cfg(feature = "global")]
#![feature(global_allocator)]

extern crate dlmalloc;
Expand Down

0 comments on commit 944418c

Please sign in to comment.