From 0239df15d4879a3ca2a6fc075316a74387371344 Mon Sep 17 00:00:00 2001 From: Jacob Emil Ulvedal Rosborg Date: Thu, 20 Jan 2022 20:07:11 +0100 Subject: [PATCH 1/2] fix --- feather/plugin-host/src/context/wasm/bump.rs | 25 ++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/feather/plugin-host/src/context/wasm/bump.rs b/feather/plugin-host/src/context/wasm/bump.rs index 054725956..607c82f07 100644 --- a/feather/plugin-host/src/context/wasm/bump.rs +++ b/feather/plugin-host/src/context/wasm/bump.rs @@ -40,8 +40,6 @@ impl WasmBump { deallocate_function, chunks: Vec::new(), }; - let initial_chunk = this.allocate_chunk(None, None)?; - this.chunks.push(initial_chunk); Ok(this) } @@ -88,13 +86,14 @@ impl WasmBump { min_layout: Option, previous_size: Option, ) -> anyhow::Result { + println!("barbar"); let mut new_size = match previous_size { Some(previous_size) => previous_size .checked_mul(2) .context("chunk overflows usize")?, None => INITIAL_CHUNK_SIZE, }; - + println!("barbar"); let mut align = CHUNK_ALIGN; if let Some(min_layout) = min_layout { align = align.max(min_layout.align()); @@ -102,17 +101,17 @@ impl WasmBump { round_up_to(min_layout.size(), align).context("allocation too large")?; new_size = new_size.max(requested_size); } - + println!("barbar"); assert_eq!(align % CHUNK_ALIGN, 0); assert_eq!(new_size % CHUNK_ALIGN, 0); let layout = Layout::from_size_align(new_size, align).context("size or align is 0")?; - + println!("barbar"); assert!(new_size >= previous_size.unwrap_or(0) * 2); - + println!("barbar"); let start = self .allocate_function .call(layout.size() as u32, layout.align() as u32)?; - + println!("barbar"); Ok(Chunk { start, layout, @@ -124,7 +123,7 @@ impl WasmBump { /// all allocated memory. pub fn reset(&mut self) -> anyhow::Result<()> { // Free all but the last chunk. - for chunk in self.chunks.drain(..self.chunks.len() - 1) { + for chunk in self.chunks.drain(..self.chunks.len()) { self.deallocate_function.call( chunk.start, chunk.layout.size() as u32, @@ -132,13 +131,9 @@ impl WasmBump { )?; } - assert_eq!(self.chunks.len(), 1); - - // Reset the last chunk's data pointer. - let last_chunk = self.chunks.last_mut().unwrap(); - last_chunk - .ptr - .set(last_chunk.start + last_chunk.layout.size() as u32); + // Allocate initial chunk + let chunk = self.allocate_chunk(None, None)?; + self.chunks.push(chunk); Ok(()) } From 386ff3c568a2831d2caa13d4b7fcf715f601698b Mon Sep 17 00:00:00 2001 From: Jacob Emil Ulvedal Rosborg Date: Thu, 20 Jan 2022 20:16:26 +0100 Subject: [PATCH 2/2] fix --- feather/plugin-host/src/context/wasm/bump.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/feather/plugin-host/src/context/wasm/bump.rs b/feather/plugin-host/src/context/wasm/bump.rs index 607c82f07..6c97db69a 100644 --- a/feather/plugin-host/src/context/wasm/bump.rs +++ b/feather/plugin-host/src/context/wasm/bump.rs @@ -86,14 +86,12 @@ impl WasmBump { min_layout: Option, previous_size: Option, ) -> anyhow::Result { - println!("barbar"); let mut new_size = match previous_size { Some(previous_size) => previous_size .checked_mul(2) .context("chunk overflows usize")?, None => INITIAL_CHUNK_SIZE, }; - println!("barbar"); let mut align = CHUNK_ALIGN; if let Some(min_layout) = min_layout { align = align.max(min_layout.align()); @@ -101,17 +99,13 @@ impl WasmBump { round_up_to(min_layout.size(), align).context("allocation too large")?; new_size = new_size.max(requested_size); } - println!("barbar"); assert_eq!(align % CHUNK_ALIGN, 0); assert_eq!(new_size % CHUNK_ALIGN, 0); let layout = Layout::from_size_align(new_size, align).context("size or align is 0")?; - println!("barbar"); assert!(new_size >= previous_size.unwrap_or(0) * 2); - println!("barbar"); let start = self .allocate_function .call(layout.size() as u32, layout.align() as u32)?; - println!("barbar"); Ok(Chunk { start, layout,