Skip to content

Commit 4786050

Browse files
committed
Removing allocator-api support
1 parent b99a307 commit 4786050

File tree

5 files changed

+4
-69
lines changed

5 files changed

+4
-69
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,3 @@ jobs:
3838
run: rustup update stable && rustup default stable && rustup target add wasm32-unknown-unknown
3939
- run: cargo build --target wasm32-unknown-unknown
4040
- run: cargo build --target wasm32-unknown-unknown --release
41-
42-
alloc_api:
43-
name: Allocator API
44-
runs-on: ubuntu-latest
45-
steps:
46-
- uses: actions/checkout@master
47-
- name: Install Rust
48-
run: rustup update nightly && rustup default nightly
49-
- run: cargo test --features 'allocator-api global'
50-

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ global = []
4040
# Enable very expensive debug checks in this crate
4141
debug = []
4242

43-
# Enable experimental support for the standard library's unstable allocator API.
44-
allocator-api = []
4543
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std']

src/global.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#[cfg(feature = "allocator-api")]
2-
use core::alloc::{AllocErr, AllocRef};
31
use core::alloc::{GlobalAlloc, Layout};
42
use core::ops::{Deref, DerefMut};
5-
#[cfg(feature = "allocator-api")]
6-
use core::ptr::NonNull;
73

84
use Dlmalloc;
95

@@ -35,24 +31,6 @@ unsafe impl GlobalAlloc for GlobalDlmalloc {
3531
}
3632
}
3733

38-
#[cfg(feature = "allocator-api")]
39-
unsafe impl AllocRef for GlobalDlmalloc {
40-
#[inline]
41-
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
42-
unsafe { get().alloc(layout) }
43-
}
44-
45-
#[inline]
46-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
47-
get().dealloc(ptr, layout)
48-
}
49-
50-
#[inline]
51-
fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
52-
unsafe { get().alloc_zeroed(layout) }
53-
}
54-
}
55-
5634
static mut DLMALLOC: Dlmalloc = Dlmalloc::new();
5735

5836
struct Instance;

src/lib.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@
1111
//! Support for other platforms is largely untested and unused, but is used when
1212
//! testing this crate.
1313
14-
#![cfg_attr(feature = "allocator-api", feature(allocator_api))]
15-
#![cfg_attr(not(feature = "allocator-api"), allow(dead_code))]
14+
#![allow(dead_code)]
1615
#![no_std]
1716
#![deny(missing_docs)]
1817

19-
#[cfg(feature = "allocator-api")]
20-
use core::alloc::{AllocErr, AllocRef, Layout};
2118
use core::cmp;
2219
use core::ptr;
2320
use sys::System;
2421

25-
#[cfg(all(feature = "global", not(test)))]
22+
#[cfg(feature = "global")]
2623
pub use self::global::GlobalDlmalloc;
2724

2825
mod dlmalloc;
29-
#[cfg(all(feature = "global", not(test)))]
26+
#[cfg(feature = "global")]
3027
mod global;
3128

3229
/// In order for this crate to efficiently manage memory, it needs a way to communicate with the
@@ -174,29 +171,3 @@ impl<A: Allocator> Dlmalloc<A> {
174171
}
175172
}
176173
}
177-
178-
#[cfg(feature = "allocator-api")]
179-
unsafe impl AllocRef for Dlmalloc {
180-
#[inline]
181-
fn alloc(&mut self, layout: Layout) -> Result<ptr::NonNull<[u8]>, AllocErr> {
182-
unsafe {
183-
let ptr = <Dlmalloc>::malloc(self, layout.size(), layout.align());
184-
let ptr = ptr::slice_from_raw_parts(ptr, layout.size());
185-
ptr::NonNull::new(ptr as _).ok_or(AllocErr)
186-
}
187-
}
188-
189-
#[inline]
190-
unsafe fn dealloc(&mut self, ptr: ptr::NonNull<u8>, layout: Layout) {
191-
<Dlmalloc>::free(self, ptr.as_ptr(), layout.size(), layout.align())
192-
}
193-
194-
#[inline]
195-
fn alloc_zeroed(&mut self, layout: Layout) -> Result<ptr::NonNull<[u8]>, AllocErr> {
196-
unsafe {
197-
let ptr = <Dlmalloc>::calloc(self, layout.size(), layout.align());
198-
let ptr = ptr::slice_from_raw_parts(ptr, layout.size());
199-
ptr::NonNull::new(ptr as _).ok_or(AllocErr)
200-
}
201-
}
202-
}

tests/global.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
#![cfg(all(feature = "allocator-api", feature = "global"))]
2-
#![feature(global_allocator)]
3-
41
extern crate dlmalloc;
52

63
use std::collections::HashMap;
74
use std::thread;
85

96
#[global_allocator]
7+
#[cfg(feature = "global")]
108
static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
119

1210
#[test]

0 commit comments

Comments
 (0)