Skip to content

Commit

Permalink
Added some linting fixes and fix for compile erors
Browse files Browse the repository at this point in the history
  • Loading branch information
john-sharratt committed Nov 27, 2023
1 parent d494348 commit a41c996
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
15 changes: 15 additions & 0 deletions lib/api/src/js/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ impl Memory {
Ok(Pages(new_pages))
}

pub fn grow_at_least(
&self,
store: &mut impl AsStoreMut,
min_size: u64,
) -> Result<(), MemoryError> {
let cur_size = self.view(store).data_size();
if min_size > cur_size {
let delta = min_size - cur_size;
let pages = ((delta - 1) / wasmer_types::WASM_PAGE_SIZE) + 1;

self.grow(store, Pages(pages))?;
}
Ok(())
}

pub fn reset(&self, _store: &mut impl AsStoreMut) -> Result<(), MemoryError> {
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions lib/wasix/src/journal/concrete/compacting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl State {
.chain(self.keep_descriptors.iter())
.chain(self.stdio_descriptors.iter())
{
if let Some(d) = self.descriptors.get(&l) {
if let Some(d) = self.descriptors.get(l) {
for e in d.events.iter() {
filter.add_event_to_whitelist(*e);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ impl WritableJournal for CompactingJournalTx {
let state = state
.descriptors
.entry(lookup)
.or_insert_with(|| Default::default());
.or_insert_with(Default::default);
state.events.push(event_index);
} else {
state.whitelist.insert(event_index);
Expand Down Expand Up @@ -330,7 +330,7 @@ impl WritableJournal for CompactingJournalTx {
let state = state
.descriptors
.entry(lookup)
.or_insert_with(|| Default::default());
.or_insert_with(Default::default);
if let JournalEntry::FileDescriptorWriteV1 { offset, data, .. } = &entry {
state.write_map.insert(
MemoryRange {
Expand Down
10 changes: 4 additions & 6 deletions lib/wasix/src/journal/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ pub enum SnapshotTrigger {

impl SnapshotTrigger {
pub fn only_once(&self) -> bool {
match self {
Self::FirstListen => true,
Self::FirstEnviron => true,
Self::FirstStdin => true,
_ => false,
}
matches!(
self,
Self::FirstListen | Self::FirstEnviron | Self::FirstStdin
)
}
}

Expand Down
10 changes: 2 additions & 8 deletions lib/wasix/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,7 @@ impl WasiEnvBuilder {

#[allow(clippy::result_large_err)]
pub fn build(self) -> Result<WasiEnv, WasiRuntimeError> {
let module_hash = self
.module_hash
.clone()
.unwrap_or_else(|| ModuleHash::random());
let module_hash = self.module_hash.unwrap_or_else(ModuleHash::random);
let init = self.build_init()?;
WasiEnv::from_init(init, module_hash)
}
Expand All @@ -885,10 +882,7 @@ impl WasiEnvBuilder {
self,
store: &mut impl AsStoreMut,
) -> Result<WasiFunctionEnv, WasiRuntimeError> {
let module_hash = self
.module_hash
.clone()
.unwrap_or_else(|| ModuleHash::random());
let module_hash = self.module_hash.unwrap_or_else(ModuleHash::random);
let init = self.build_init()?;
let env = WasiEnv::from_init(init, module_hash)?;
let func_env = WasiFunctionEnv::new(store, env);
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/state/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ impl WasiEnv {
/// (it must be initialized before it can be used)
/// This has been marked as unsafe as it will panic if its executed
/// on the wrong thread or before the inner is set
pub(crate) unsafe fn memory<'a>(&self) -> WasiInstanceGuardMemory<'_> {
pub(crate) unsafe fn memory(&self) -> WasiInstanceGuardMemory<'_> {
self.try_memory().expect(
"You must initialize the WasiEnv before using it and can not pass it between threads",
)
Expand Down

0 comments on commit a41c996

Please sign in to comment.