From b5a5b34329f57a5aec74c1653e71ff1bedd270ec Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 1 Feb 2025 23:04:42 -0500 Subject: [PATCH] Use Cell for size in memoryio in place of unsafecell --- core/io/memory.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/core/io/memory.rs b/core/io/memory.rs index f95d82a75..18decf78a 100644 --- a/core/io/memory.rs +++ b/core/io/memory.rs @@ -3,7 +3,7 @@ use crate::Result; use log::debug; use std::{ - cell::{RefCell, UnsafeCell}, + cell::{Cell, RefCell, UnsafeCell}, collections::BTreeMap, rc::Rc, sync::Arc, @@ -11,7 +11,7 @@ use std::{ pub struct MemoryIO { pages: UnsafeCell>, - size: UnsafeCell, + size: Cell, } // TODO: page size flag @@ -41,15 +41,6 @@ impl MemoryIO { fn get_page(&self, page_no: usize) -> Option<&MemPage> { unsafe { (*self.pages.get()).get(&page_no) } } - - #[allow(clippy::mut_from_ref)] - fn get_size_mut(&self) -> &mut usize { - unsafe { &mut *self.size.get() } - } - - fn get_size(&self) -> usize { - unsafe { *self.size.get() } - } } impl IO for Arc { @@ -98,7 +89,7 @@ impl File for MemoryFile { return Ok(()); } - let file_size = self.io.get_size(); + let file_size = self.io.size.get(); if pos >= file_size { c.complete(0); return Ok(()); @@ -160,8 +151,9 @@ impl File for MemoryFile { remaining -= bytes_to_write; } - let size = self.io.get_size_mut(); - *size = (*size).max(pos + buf_len); + self.io + .size + .set(core::cmp::max(pos + buf_len, self.io.size.get())); c.complete(buf_len as i32); Ok(()) @@ -174,7 +166,7 @@ impl File for MemoryFile { } fn size(&self) -> Result { - Ok(self.io.get_size() as u64) + Ok(self.io.size.get() as u64) } }