Skip to content

Commit 411508a

Browse files
committed
fix for nightly-2020-09-24, give up backward compatibility
1 parent de6cf88 commit 411508a

File tree

3 files changed

+8
-74
lines changed

3 files changed

+8
-74
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
rust:
16-
- nightly-2020-02-01
17-
- nightly-2020-02-03
18-
- nightly-2020-03-01
19-
- nightly-2020-03-04
20-
- nightly-2020-03-10
21-
- nightly-2020-03-11
22-
- nightly-2020-04-01
23-
- nightly-2020-04-02
16+
- nightly-2020-09-24
2417

2518
steps:
2619
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ documentation = "https://docs.rs/buddy_system_allocator"
55
homepage = "https://github.com/rcore-os/buddy_system_allocator"
66
repository = "https://github.com/rcore-os/buddy_system_allocator"
77
keywords = ["allocator", "no_std", "heap"]
8-
version = "0.4.0"
8+
version = "0.5.0"
99
authors = ["Jiajie Chen <noc@jiegec.ac.cn>"]
1010
edition = "2018"
1111
license = "MIT"
@@ -17,6 +17,3 @@ use_spin = ["spin"]
1717
[dependencies.spin]
1818
version = "0.5"
1919
optional = true
20-
21-
[dependencies]
22-
rustversion = "1.0"

src/lib.rs

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(const_fn)]
2-
#![feature(alloc, allocator_api)]
1+
#![feature(const_mut_refs, const_fn_fn_ptr_basics)]
32
#![no_std]
4-
#![allow(stable_features)]
53

64
#[cfg(test)]
75
#[macro_use]
@@ -12,14 +10,7 @@ extern crate spin;
1210

1311
extern crate alloc;
1412

15-
#[rustversion::before(2020-02-02)]
16-
use alloc::alloc::Alloc;
17-
#[rustversion::since(2020-02-02)]
18-
use alloc::alloc::AllocRef;
19-
use alloc::alloc::{AllocErr, Layout};
20-
#[rustversion::since(2020-04-02)]
21-
use alloc::alloc::{AllocInit, MemoryBlock};
22-
use core::alloc::GlobalAlloc;
13+
use core::alloc::{GlobalAlloc, Layout};
2314
use core::cmp::{max, min};
2415
use core::fmt;
2516
use core::mem::size_of;
@@ -109,7 +100,7 @@ impl Heap {
109100
}
110101

111102
/// Alloc a range of memory from the heap satifying `layout` requirements
112-
pub fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
103+
pub fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, ()> {
113104
let size = max(
114105
layout.size().next_power_of_two(),
115106
max(layout.align(), size_of::<usize>()),
@@ -127,7 +118,7 @@ impl Heap {
127118
self.free_list[j - 1].push(block);
128119
}
129120
} else {
130-
return Err(AllocErr {});
121+
return Err(());
131122
}
132123
}
133124

@@ -142,11 +133,11 @@ impl Heap {
142133
self.allocated += size;
143134
return Ok(result);
144135
} else {
145-
return Err(AllocErr {});
136+
return Err(());
146137
}
147138
}
148139
}
149-
Err(AllocErr {})
140+
Err(())
150141
}
151142

152143
/// Dealloc a range of memory from the heap
@@ -217,53 +208,6 @@ impl fmt::Debug for Heap {
217208
}
218209
}
219210

220-
#[rustversion::before(2020-02-02)]
221-
unsafe impl Alloc for Heap {
222-
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
223-
self.alloc(layout)
224-
}
225-
226-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
227-
self.dealloc(ptr, layout)
228-
}
229-
}
230-
231-
#[rustversion::since(2020-02-02)]
232-
unsafe impl AllocRef for Heap {
233-
#[rustversion::before(2020-03-03)]
234-
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
235-
self.alloc(layout)
236-
}
237-
238-
#[rustversion::all(since(2020-03-03), before(2020-03-10))]
239-
unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
240-
self.alloc(layout).map(|p| (p, layout.size()))
241-
}
242-
243-
#[rustversion::all(since(2020-03-10), before(2020-04-02))]
244-
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
245-
self.alloc(layout).map(|p| (p, layout.size()))
246-
}
247-
248-
#[rustversion::since(2020-04-02)]
249-
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
250-
self.alloc(layout).map(|p| {
251-
let block = MemoryBlock {
252-
ptr: p,
253-
size: layout.size(),
254-
};
255-
unsafe {
256-
init.init(block);
257-
}
258-
block
259-
})
260-
}
261-
262-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
263-
self.dealloc(ptr, layout)
264-
}
265-
}
266-
267211
/// A locked version of `Heap`
268212
///
269213
/// # Usage

0 commit comments

Comments
 (0)