Skip to content

Commit

Permalink
Implemented free.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Dec 8, 2021
1 parent 564d539 commit 0a95e06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait Read<T> {
pub trait Write<T> {
fn alloc(value: &str, memory: &Env) -> anyhow::Result<Box<Self>>;
fn write(&mut self, value: &str, env: &Env) -> anyhow::Result<Box<Self>>;
fn free(memory: &Env) -> anyhow::Result<()>;
fn free(self, memory: &Env) -> anyhow::Result<()>;
}

#[derive(Debug)]
Expand Down
13 changes: 11 additions & 2 deletions src/string_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,17 @@ impl Write<String> for StringPtr {
}
}

fn free(_env: &Env) -> anyhow::Result<()> {
todo!("Release the memory from this string")
fn free(self, env: &Env) -> anyhow::Result<()> {
// unpin
let unpin = export_asr!(fn_pin, env);
unpin
.call(&[Value::I32(self.offset().try_into().unwrap())])
.expect("Failed to call __unpin");

// collect
let collect = export_asr!(fn_collect, env);
collect.call(&[]).expect("failed to call __collect");
Ok(())
}
}

Expand Down

0 comments on commit 0a95e06

Please sign in to comment.