From 47860503a980e40cdb5a0c9015c5a4838a180587 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Thu, 5 Nov 2020 16:46:58 +0100 Subject: [PATCH] Removing allocator-api support --- .github/workflows/main.yml | 10 ---------- Cargo.toml | 2 -- src/global.rs | 22 ---------------------- src/lib.rs | 35 +++-------------------------------- tests/global.rs | 4 +--- 5 files changed, 4 insertions(+), 69 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 13ae0cb..4b93671 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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' - diff --git a/Cargo.toml b/Cargo.toml index 8deb197..a86999f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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'] diff --git a/src/global.rs b/src/global.rs index bd4214b..fbac315 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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; @@ -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, AllocErr> { - unsafe { get().alloc(layout) } - } - - #[inline] - unsafe fn dealloc(&mut self, ptr: NonNull, layout: Layout) { - get().dealloc(ptr, layout) - } - - #[inline] - fn alloc_zeroed(&mut self, layout: Layout) -> Result, AllocErr> { - unsafe { get().alloc_zeroed(layout) } - } -} - static mut DLMALLOC: Dlmalloc = Dlmalloc::new(); struct Instance; diff --git a/src/lib.rs b/src/lib.rs index a743816..22a43c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,22 +11,19 @@ //! 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))] +#![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; -#[cfg(all(feature = "global", not(test)))] +#[cfg(feature = "global")] pub use self::global::GlobalDlmalloc; mod dlmalloc; -#[cfg(all(feature = "global", not(test)))] +#[cfg(feature = "global")] mod global; /// In order for this crate to efficiently manage memory, it needs a way to communicate with the @@ -174,29 +171,3 @@ impl Dlmalloc { } } } - -#[cfg(feature = "allocator-api")] -unsafe impl AllocRef for Dlmalloc { - #[inline] - fn alloc(&mut self, layout: Layout) -> Result, AllocErr> { - unsafe { - let ptr = ::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, layout: Layout) { - ::free(self, ptr.as_ptr(), layout.size(), layout.align()) - } - - #[inline] - fn alloc_zeroed(&mut self, layout: Layout) -> Result, AllocErr> { - unsafe { - let ptr = ::calloc(self, layout.size(), layout.align()); - let ptr = ptr::slice_from_raw_parts(ptr, layout.size()); - ptr::NonNull::new(ptr as _).ok_or(AllocErr) - } - } -} diff --git a/tests/global.rs b/tests/global.rs index c803ccc..1e9bc66 100644 --- a/tests/global.rs +++ b/tests/global.rs @@ -1,12 +1,10 @@ -#![cfg(all(feature = "allocator-api", feature = "global"))] -#![feature(global_allocator)] - extern crate dlmalloc; use std::collections::HashMap; use std::thread; #[global_allocator] +#[cfg(feature = "global")] static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; #[test]