@@ -23,31 +23,14 @@ use {core::alloc::Allocator, core::ptr::NonNull};
23
23
/// buffer size is sufficient, and
24
24
/// - return a mutable typed reference that points to the same memory as the input buffer on
25
25
/// success.
26
- ///
27
- /// # Feature `unstable` / `allocator_api`
28
- /// By default, this function works with the allocator that is set as
29
- /// `#[global_allocator]`. This might be UEFI allocator but depends on your
30
- /// use case and how you set up the environment.
31
- ///
32
- /// If you activate the `unstable`-feature, all allocations uses the provided
33
- /// allocator (via `allocator_api`) instead. In that case, the function takes an
34
- /// additional parameter describing the specific [`Allocator`]. You can use
35
- /// [`alloc::alloc::Global`] which defaults to the `#[global_allocator]`.
36
- ///
37
- /// [`Allocator`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html
38
- /// [`alloc::alloc::Global`]: https://doc.rust-lang.org/alloc/alloc/struct.Global.html
39
26
pub ( crate ) fn make_boxed <
40
27
' a ,
41
28
// The UEFI data structure.
42
29
Data : Align + ?Sized + Debug + ' a ,
43
30
F : FnMut ( & ' a mut [ u8 ] ) -> Result < & ' a mut Data , Option < usize > > ,
44
- #[ cfg( feature = "unstable" ) ] A : Allocator ,
45
31
> (
46
32
// A function to read the UEFI data structure into a provided buffer.
47
33
mut fetch_data_fn : F ,
48
- #[ cfg( feature = "unstable" ) ]
49
- // Allocator of the `allocator_api` feature. You can use `Global` as default.
50
- allocator : A ,
51
34
) -> Result < Box < Data > > {
52
35
let required_size = match fetch_data_fn ( & mut [ ] ) . map_err ( Error :: split) {
53
36
// This is the expected case: the empty buffer passed in is too
@@ -70,21 +53,13 @@ pub(crate) fn make_boxed<
70
53
71
54
// Allocate the buffer on the heap.
72
55
let heap_buf: * mut u8 = {
73
- #[ cfg( not( feature = "unstable" ) ) ]
74
56
{
75
57
let ptr = unsafe { alloc ( layout) } ;
76
58
if ptr. is_null ( ) {
77
59
return Err ( Status :: OUT_OF_RESOURCES . into ( ) ) ;
78
60
}
79
61
ptr
80
62
}
81
-
82
- #[ cfg( feature = "unstable" ) ]
83
- allocator
84
- . allocate ( layout)
85
- . map_err ( |_| <Status as Into < Error > >:: into ( Status :: OUT_OF_RESOURCES ) ) ?
86
- . as_ptr ( )
87
- . cast :: < u8 > ( )
88
63
} ;
89
64
90
65
// Read the data into the provided buffer.
@@ -97,20 +72,12 @@ pub(crate) fn make_boxed<
97
72
let data: & mut Data = match data {
98
73
Ok ( data) => data,
99
74
Err ( err) => {
100
- #[ cfg( not( feature = "unstable" ) ) ]
101
- unsafe {
102
- dealloc ( heap_buf, layout)
103
- } ;
104
- #[ cfg( feature = "unstable" ) ]
105
- unsafe {
106
- allocator. deallocate ( NonNull :: new ( heap_buf) . unwrap ( ) , layout)
107
- }
75
+ unsafe { dealloc ( heap_buf, layout) } ;
108
76
return Err ( err) ;
109
77
}
110
78
} ;
111
79
112
80
let data = unsafe { Box :: from_raw ( data) } ;
113
-
114
81
Ok ( data)
115
82
}
116
83
0 commit comments