Skip to content

Commit b53d7c6

Browse files
authored
Fixes wasi (#524)
* fix
1 parent 1ac3c81 commit b53d7c6

File tree

1 file changed

+4
-15
lines changed
  • feather/plugin-host/src/context/wasm

1 file changed

+4
-15
lines changed

feather/plugin-host/src/context/wasm/bump.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ impl WasmBump {
4040
deallocate_function,
4141
chunks: Vec::new(),
4242
};
43-
let initial_chunk = this.allocate_chunk(None, None)?;
44-
this.chunks.push(initial_chunk);
4543
Ok(this)
4644
}
4745

@@ -94,25 +92,20 @@ impl WasmBump {
9492
.context("chunk overflows usize")?,
9593
None => INITIAL_CHUNK_SIZE,
9694
};
97-
9895
let mut align = CHUNK_ALIGN;
9996
if let Some(min_layout) = min_layout {
10097
align = align.max(min_layout.align());
10198
let requested_size =
10299
round_up_to(min_layout.size(), align).context("allocation too large")?;
103100
new_size = new_size.max(requested_size);
104101
}
105-
106102
assert_eq!(align % CHUNK_ALIGN, 0);
107103
assert_eq!(new_size % CHUNK_ALIGN, 0);
108104
let layout = Layout::from_size_align(new_size, align).context("size or align is 0")?;
109-
110105
assert!(new_size >= previous_size.unwrap_or(0) * 2);
111-
112106
let start = self
113107
.allocate_function
114108
.call(layout.size() as u32, layout.align() as u32)?;
115-
116109
Ok(Chunk {
117110
start,
118111
layout,
@@ -124,21 +117,17 @@ impl WasmBump {
124117
/// all allocated memory.
125118
pub fn reset(&mut self) -> anyhow::Result<()> {
126119
// Free all but the last chunk.
127-
for chunk in self.chunks.drain(..self.chunks.len() - 1) {
120+
for chunk in self.chunks.drain(..self.chunks.len()) {
128121
self.deallocate_function.call(
129122
chunk.start,
130123
chunk.layout.size() as u32,
131124
chunk.layout.align() as u32,
132125
)?;
133126
}
134127

135-
assert_eq!(self.chunks.len(), 1);
136-
137-
// Reset the last chunk's data pointer.
138-
let last_chunk = self.chunks.last_mut().unwrap();
139-
last_chunk
140-
.ptr
141-
.set(last_chunk.start + last_chunk.layout.size() as u32);
128+
// Allocate initial chunk
129+
let chunk = self.allocate_chunk(None, None)?;
130+
self.chunks.push(chunk);
142131

143132
Ok(())
144133
}

0 commit comments

Comments
 (0)