Skip to content

Commit 349f7de

Browse files
authored
Merge pull request #705 from nicholasbishop/bishop-alloc-api-changes
Rename `global_allocator` module and change scope of `global_allocator` feature
2 parents 77a7a32 + 8045d43 commit 349f7de

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## uefi - [Unreleased]
44

5+
### Changed
6+
7+
- The `global_allocator` module has been renamed to `allocator`, and is now
8+
available regardless of whether the `global_allocator` feature is enabled. The
9+
`global_allocator` feature now only controls whether `allocator::Allocator` is
10+
set as Rust's global allocator.
11+
512
## uefi-macros - [Unreleased]
613

714
## uefi-services - [Unreleased]

uefi-services/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result {
9393
init_logger(st);
9494

9595
let boot_services = st.boot_services();
96-
uefi::global_allocator::init(boot_services);
96+
uefi::allocator::init(boot_services);
9797

9898
// Schedule these tools to be disabled on exit from UEFI boot services
9999
boot_services
@@ -191,7 +191,7 @@ unsafe extern "efiapi" fn exit_boot_services(_e: Event, _ctx: Option<NonNull<c_v
191191
logger.disable();
192192
}
193193

194-
uefi::global_allocator::exit_boot_services();
194+
uefi::allocator::exit_boot_services();
195195
}
196196

197197
#[cfg(feature = "panic_handler")]

uefi/src/global_allocator.rs renamed to uefi/src/allocator.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module implements Rust's global allocator interface using UEFI's memory allocation functions.
22
//!
3-
//! Enabling the `alloc` optional feature in your app will allow you to use Rust's higher-level data structures,
4-
//! like boxes, vectors, hash maps, linked lists and so on.
3+
//! If the `global_allocator` feature is enabled, the [`Allocator`] will be used
4+
//! as the global Rust allocator.
55
//!
66
//! # Usage
77
//!
@@ -112,5 +112,6 @@ unsafe impl GlobalAlloc for Allocator {
112112
}
113113
}
114114

115+
#[cfg(feature = "global_allocator")]
115116
#[global_allocator]
116117
static ALLOCATOR: Allocator = Allocator;

uefi/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
//! `Vec` rather than filling a statically-sized array. This requires
4444
//! a global allocator; you can use the `global_allocator` feature or
4545
//! provide your own.
46-
//! - `global_allocator`: Implement a [global allocator] using UEFI
47-
//! functions. This is a simple allocator that relies on the UEFI pool
46+
//! - `global_allocator`: Set [`allocator::Allocator`] as the global Rust
47+
//! allocator. This is a simple allocator that relies on the UEFI pool
4848
//! allocator. You can choose to provide your own allocator instead of
4949
//! using this feature, or no allocator at all if you don't need to
5050
//! dynamically allocate any memory.
@@ -108,8 +108,7 @@ pub mod proto;
108108

109109
pub mod prelude;
110110

111-
#[cfg(feature = "global_allocator")]
112-
pub mod global_allocator;
111+
pub mod allocator;
113112

114113
#[cfg(feature = "logger")]
115114
pub mod logger;

uefi/src/table/system.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl SystemTable<Boot> {
194194
/// Once boot services are exited, the logger and allocator provided by
195195
/// this crate can no longer be used. The logger should be disabled using
196196
/// the [`Logger::disable`] method, and the allocator should be disabled by
197-
/// calling [`global_allocator::exit_boot_services`]. Note that if the logger and
197+
/// calling [`allocator::exit_boot_services`]. Note that if the logger and
198198
/// allocator were initialized with [`uefi_services::init`], they will be
199199
/// disabled automatically when `exit_boot_services` is called.
200200
///
@@ -208,7 +208,7 @@ impl SystemTable<Boot> {
208208
/// now in an undefined state. Rather than returning control to the
209209
/// caller, the system will be reset.
210210
///
211-
/// [`global_allocator::exit_boot_services`]: crate::global_allocator::exit_boot_services
211+
/// [`allocator::exit_boot_services`]: crate::allocator::exit_boot_services
212212
/// [`Logger::disable`]: crate::logger::Logger::disable
213213
/// [`uefi_services::init`]: https://docs.rs/uefi-services/latest/uefi_services/fn.init.html
214214
#[must_use]

0 commit comments

Comments
 (0)