Skip to content

Commit

Permalink
Remove some unused memory management code in the adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Jun 28, 2024
1 parent e03f1d5 commit 455288a
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions crates/adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,22 +219,6 @@ enum ImportAlloc {
pointers: BumpAlloc,
},

/// An allocator specifically for getting the nth string allocation used
/// for preopens.
///
/// This will allocate everything into `alloc`. All strings other than the
/// `nth` string, however, will be discarded (the allocator's state is reset
/// after the allocation). This means that the pointer returned for the
/// `nth` string will be retained in `alloc` while all others will be
/// discarded.
///
/// The `cur` count starts at 0 and counts up per-string.
GetPreopenPath {
cur: u32,
nth: u32,
alloc: BumpAlloc,
},

/// No import allocator is configured and if an allocation happens then
/// this will abort.
None,
Expand Down Expand Up @@ -301,12 +285,6 @@ impl ImportAlloc {
// WASI doesn't say all the strings have to be adjacent, so this
// should work out in practice.
//
// * Finally for `GetPreopenPath` this works out only insofar that the
// `State::temporary_alloc` space is used to store the path. The
// WASI-provided buffer is precisely sized, not overly large, meaning
// that we're forced to copy from `temporary_alloc` into the
// destination buffer for this WASI call.
//
// Basically it's a case-by-case basis here that enables ignoring
// shrinking return calls here. Not robust.
if !old_ptr.is_null() {
Expand Down Expand Up @@ -338,18 +316,6 @@ impl ImportAlloc {
alloc.alloc(align, size)
}
}
ImportAlloc::GetPreopenPath { cur, nth, alloc } => {
if align == 1 {
let real_alloc = *nth == *cur;
if real_alloc {
alloc.alloc(align, size)
} else {
alloc.clone().alloc(align, size)
}
} else {
alloc.alloc(align, size)
}
}
ImportAlloc::None => {
unreachable!("no allocator configured")
}
Expand Down Expand Up @@ -1614,15 +1580,6 @@ impl State {
}
}

/// Configure that `cabi_import_realloc` will allocate once from
/// `self.temporary_data` for the duration of the closure `f`.
///
/// Panics if the import allocator is already configured.
fn with_one_temporary_alloc<T>(&self, f: impl FnOnce() -> T) -> T {
let alloc = unsafe { self.temporary_alloc() };
self.with_import_alloc(ImportAlloc::OneAlloc(alloc), f).0
}

/// Configure that `cabi_import_realloc` will allocate once from
/// `base` with at most `len` bytes for the duration of `f`.
///
Expand Down

0 comments on commit 455288a

Please sign in to comment.