Skip to content

Commit

Permalink
Replace manual borrow_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 10, 2023
1 parent 704222a commit d173733
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 3 additions & 5 deletions esp-wifi/src/compat/malloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *const u8 {

let layout = Layout::from_size_align_unchecked(total_size, 4);
let ptr = critical_section::with(|cs| {
HEAP.borrow(cs)
.borrow_mut()
HEAP.borrow_ref_mut(cs)
.allocate_first_fit(layout)
.ok()
.map_or(core::ptr::null_mut(), |allocation| allocation.as_ptr())
Expand All @@ -21,7 +20,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *const u8 {
return ptr;
}

*(ptr as *mut _ as *mut usize) = total_size;
*(ptr as *mut usize) = total_size;
ptr.offset(4)
}

Expand All @@ -37,8 +36,7 @@ pub unsafe extern "C" fn free(ptr: *const u8) {

let layout = Layout::from_size_align_unchecked(total_size, 4);
critical_section::with(|cs| {
HEAP.borrow(cs)
.borrow_mut()
HEAP.borrow_ref_mut(cs)
.deallocate(core::ptr::NonNull::new_unchecked(ptr as *mut u8), layout)
});
}
Expand Down
3 changes: 1 addition & 2 deletions esp-wifi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ pub(crate) static HEAP: Mutex<RefCell<Heap>> = Mutex::new(RefCell::new(Heap::emp

fn init_heap() {
critical_section::with(|cs| {
HEAP.borrow(cs)
.borrow_mut()
HEAP.borrow_ref_mut(cs)
.init_from_slice(unsafe { &mut HEAP_DATA })
});
}
Expand Down

0 comments on commit d173733

Please sign in to comment.