Skip to content

Commit 0af58b7

Browse files
committed
Rename to embedded-alloc.
1 parent 2444b77 commit 0af58b7

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.5.0] - 2022-12-06
11+
12+
### Changed
13+
14+
- Renamed crate from `alloc-cortex-m` to `embedded-alloc`.
15+
- Renamed `CortexMHeap` to `Heap`.
16+
- Use `critical-section` to lock the heap, instead of `cortex_m::interrupt::free()`.
17+
This allows using this crate on non-Cortex-M systems, or on
18+
Cortex-M systems that require a custom critical section implementation.
19+
1020
## [v0.4.2] - 2022-01-04
1121

1222
### Changed
@@ -89,7 +99,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8999

90100
- Initial version of the allocator
91101

92-
[Unreleased]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.4.2...HEAD
102+
[Unreleased]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.5.0...HEAD
103+
[v0.5.0]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.4.2...v0.5.0
93104
[v0.4.2]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.4.1...v0.4.2
94105
[v0.4.1]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.4.0...v0.4.1
95106
[v0.4.0]: https://github.com/rust-embedded/alloc-cortex-m/compare/v0.3.5...v0.4.0

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ authors = [
66
"Sébastien Béchet <sebastien.bechet@osinix.com>",
77
]
88

9-
description = "A heap allocator for Cortex-M processors"
10-
repository = "https://github.com/rust-embedded/alloc-cortex-m"
11-
documentation = "https://docs.rs/alloc-cortex-m"
9+
description = "A heap allocator for embedded systems"
10+
repository = "https://github.com/rust-embedded/embedded-alloc"
11+
documentation = "https://docs.rs/embedded-alloc"
1212
readme = "README.md"
1313
edition = "2018"
1414

1515
keywords = [
1616
"allocator",
17+
"embedded",
1718
"arm",
19+
"riscv",
1820
"cortex-m",
1921
]
2022
license = "MIT OR Apache-2.0"
21-
name = "alloc-cortex-m"
22-
version = "0.4.2"
23+
name = "embedded-alloc"
24+
version = "0.5.0"
2325

2426
[dependencies]
2527
critical-section = "1.0"

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
# `alloc-cortex-m`
55

6-
> A heap allocator for Cortex-M processors
6+
> A heap allocator for embedded systems.
7+
8+
Note that using this as your global allocator requires nightly Rust.
79

810
This project is developed and maintained by the [Cortex-M team][team].
911

12+
## Example
13+
14+
For a usage example, see `examples/global_alloc.rs`.
15+
1016
## [Documentation](https://docs.rs/alloc-cortex-m)
1117

1218
## [Change log](CHANGELOG.md)

examples/global_alloc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
extern crate alloc;
66

77
use alloc::vec::Vec;
8-
use alloc_cortex_m::CortexMHeap;
98
use core::alloc::Layout;
109
use core::panic::PanicInfo;
1110
use cortex_m_rt::entry;
11+
use embedded_alloc::Heap;
1212

1313
#[global_allocator]
14-
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
14+
static HEAP: Heap = Heap::empty();
1515

1616
#[entry]
1717
fn main() -> ! {
1818
// Initialize the allocator BEFORE you use it
1919
{
2020
use core::mem::MaybeUninit;
2121
const HEAP_SIZE: usize = 1024;
22-
static mut HEAP: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
23-
unsafe { ALLOCATOR.init(HEAP.as_ptr() as usize, HEAP_SIZE) }
22+
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
23+
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
2424
}
2525

2626
let mut xs = Vec::new();

src/lib.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
//! A heap allocator for Cortex-M processors.
2-
//!
3-
//! Note that using this as your global allocator requires nightly Rust.
4-
//!
5-
//! # Example
6-
//!
7-
//! For a usage example, see `examples/global_alloc.rs`.
8-
1+
#![doc = include_str!("../README.md")]
92
#![no_std]
103

114
use core::alloc::{GlobalAlloc, Layout};
125
use core::cell::RefCell;
136
use core::ptr::{self, NonNull};
147

158
use critical_section::Mutex;
16-
use linked_list_allocator::Heap;
9+
use linked_list_allocator::Heap as LLHeap;
1710

18-
pub struct CortexMHeap {
19-
heap: Mutex<RefCell<Heap>>,
11+
pub struct Heap {
12+
heap: Mutex<RefCell<LLHeap>>,
2013
}
2114

22-
impl CortexMHeap {
15+
impl Heap {
2316
/// Crate a new UNINITIALIZED heap allocator
2417
///
2518
/// You must initialize this heap using the
2619
/// [`init`](struct.CortexMHeap.html#method.init) method before using the allocator.
27-
pub const fn empty() -> CortexMHeap {
28-
CortexMHeap {
29-
heap: Mutex::new(RefCell::new(Heap::empty())),
20+
pub const fn empty() -> Heap {
21+
Heap {
22+
heap: Mutex::new(RefCell::new(LLHeap::empty())),
3023
}
3124
}
3225

@@ -70,7 +63,7 @@ impl CortexMHeap {
7063
}
7164
}
7265

73-
unsafe impl GlobalAlloc for CortexMHeap {
66+
unsafe impl GlobalAlloc for Heap {
7467
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
7568
critical_section::with(|cs| {
7669
self.heap

0 commit comments

Comments
 (0)