From ed12f3de03204a62b367e524abc92bd2cd053644 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Sat, 21 Sep 2024 17:35:46 +0530 Subject: [PATCH] feat: impl drop for interpreter --- flake.nix | 2 +- src/interpreter.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 6e9c73e..f15a525 100644 --- a/flake.nix +++ b/flake.nix @@ -171,8 +171,8 @@ cargo-nextest cargo-hakari cargo-deny - rust-cbindgen cargo-semver-checks + rust-bindgen ] ++ (lib.optionals pkgs.stdenv.isDarwin [ darwin.apple_sdk.frameworks.OpenCL diff --git a/src/interpreter.rs b/src/interpreter.rs index 4517ba1..b68610b 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -129,6 +129,12 @@ pub struct Interpreter { unsafe impl Send for Interpreter {} +impl Drop for Interpreter { + fn drop(&mut self) { + unsafe { mnn_sys::Interpreter_destroy(self.inner) } + } +} + impl Interpreter { pub fn from_file(path: impl AsRef) -> Result { let path = path.as_ref(); @@ -636,3 +642,4 @@ fn try_to_drop_interpreter_before_session() { drop(interpreter); drop(session); } +