From b418dea3081395627d9b633cd0718983ea6db21f Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Tue, 17 Oct 2023 13:03:25 +0900 Subject: [PATCH] feat: add delete_by_name to imports/exports see: https://github.com/bytecodealliance/WASI-Virt/pull/24/files#r1359693450 Signed-off-by: Victor Adossi --- src/module/exports.rs | 13 +++++++++++++ src/module/imports.rs | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/module/exports.rs b/src/module/exports.rs index 682f170c..a1b13d35 100644 --- a/src/module/exports.rs +++ b/src/module/exports.rs @@ -135,6 +135,19 @@ impl ModuleExports { _ => false, }) } + + /// Delete an exported function by name from this module. + pub fn delete_func_by_name(&mut self, name: impl AsRef) -> Result<()> { + let fid = self + .get_func_by_name(name) + .context("failed to find exported func with name [{name}]")?; + self.delete( + self.get_exported_func(fid) + .context("failed to find exported func with ID [{fid:?}]")? + .id(), + ); + Ok(()) + } } impl Module { diff --git a/src/module/imports.rs b/src/module/imports.rs index 7e89821e..f460c1e2 100644 --- a/src/module/imports.rs +++ b/src/module/imports.rs @@ -130,6 +130,23 @@ impl ModuleImports { _ => None, }) } + + /// Delete an imported function by name from this module. + pub fn delete_func_by_name( + &mut self, + module: impl AsRef, + name: impl AsRef, + ) -> Result<()> { + let fid = self + .get_func_by_name(module, name) + .context("failed to find imported func with name [{name}]")?; + self.delete( + self.get_imported_func(fid) + .context("failed to find imported func with ID [{fid:?}]")? + .id(), + ); + Ok(()) + } } impl Module {