Skip to content

Commit

Permalink
Remove support for rust < 1.28
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 24, 2018
1 parent cfe691b commit fa47ad1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 85 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ dist: trusty
language: rust
matrix:
include:
- rust: 1.22.0
- rust: 1.26.0
env: ALLOCATOR_API=1
- rust: 1.28.0
- rust: stable
env: ALLOCATOR_API=1
- rust: beta
env: ALLOCATOR_API=1
- rust: nightly
env: ALLOCATOR_API=1
cache: cargo
script:
- cargo test --verbose
- if [ "$ALLOCATOR_API" ]; then cargo test --verbose --features allocator_api; fi
- if [ "$ALLOCATOR_API" ]; then cargo test --verbose --features allocator_api --no-default-features; fi
- cargo test --verbose --features allocator_api
- cargo test --verbose --features allocator_api --no-default-features
18 changes: 0 additions & 18 deletions build.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/allocator_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![cfg_attr(not(feature = "nonnull_cast"), allow(unstable_name_collision))]

use allocator_api::{Alloc, Box, Layout, handle_alloc_error};
#[cfg(not(feature = "nonnull_cast"))]
use allocator_api::NonNullCast;
use core::ptr::{self, NonNull};
use {BoxExt, Zero};

Expand Down
58 changes: 3 additions & 55 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,10 @@
//! `allocator_api` crate.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(all(feature = "std", not(feature = "global_alloc")), feature(allocator_api))]

#[cfg(all(feature = "std", feature = "global_alloc"))]
#[cfg(feature = "std")]
use std::alloc::{handle_alloc_error, alloc, alloc_zeroed, Layout};

#[cfg(all(feature = "std", not(feature = "global_alloc")))]
use std::heap::{Alloc, Layout};

#[cfg(all(feature = "std", not(feature = "global_alloc"), not(feature = "global_alloc27")))]
use std::heap::{AllocErr, Heap};

#[cfg(all(feature = "std", feature = "global_alloc27"))]
use std::heap::{oom, Global as Heap};

#[cfg(feature = "allocator_api")]
extern crate allocator_api;

Expand Down Expand Up @@ -292,7 +282,7 @@ pub trait BoxExt {
Self::Inner: Zero;
}

#[cfg(all(feature = "std", feature = "global_alloc"))]
#[cfg(feature = "std")]
unsafe fn try_new_box<T>(zeroed: bool) -> Result<Box<T>, Layout> {
let layout = Layout::new::<T>();
let raw = if layout.size() == 0 {
Expand All @@ -309,53 +299,11 @@ unsafe fn try_new_box<T>(zeroed: bool) -> Result<Box<T>, Layout> {
}
}

#[cfg(all(feature = "std", feature = "global_alloc"))]
#[cfg(feature = "std")]
unsafe fn new_box<T>(zeroed: bool) -> Box<T> {
try_new_box::<T>(zeroed).unwrap_or_else(|l| handle_alloc_error(l))
}

#[cfg(all(feature = "std", feature = "global_alloc27"))]
unsafe fn try_new_box<T>(zeroed: bool) -> Result<Box<T>, Layout> {
let layout = Layout::new::<T>();
let raw = if layout.size() == 0 {
Ok(ptr::NonNull::<T>::dangling().cast())
} else if zeroed {
Heap.alloc_zeroed(layout).map(|p| p.cast())
} else {
Heap.alloc(layout).map(|p| p.cast())
};
match raw {
Ok(raw) => Ok(Box::from_raw(raw.as_ptr())),
Err(_) => Err(layout),
}
}

#[cfg(all(feature = "std", feature = "global_alloc27"))]
unsafe fn new_box<T>(zeroed: bool) -> Box<T> {
try_new_box::<T>(zeroed).unwrap_or_else(|_| oom())
}

#[cfg(all(feature = "std", not(feature = "global_alloc"), not(feature = "global_alloc27")))]
unsafe fn try_new_box<T>(zeroed: bool) -> Result<Box<T>, Layout> {
let layout = Layout::new::<T>();
let raw = if layout.size() == 0 {
Ok(layout.align() as *mut u8)
} else if zeroed {
Heap.alloc_zeroed(layout.clone())
} else {
Heap.alloc(layout.clone())
};
match raw {
Ok(raw) => Ok(Box::from_raw(raw as *mut T)),
Err(_) => Err(layout),
}
}

#[cfg(all(feature = "std", not(feature = "global_alloc"), not(feature = "global_alloc27")))]
unsafe fn new_box<T>(zeroed: bool) -> Box<T> {
try_new_box::<T>(zeroed).unwrap_or_else(|l| Heap.oom(AllocErr::Exhausted { request: l }))
}

#[cfg(feature = "std")]
impl<T> BoxExt for Box<T> {
type Inner = T;
Expand Down

0 comments on commit fa47ad1

Please sign in to comment.