From ceb83d3378466c342bf9da0fde92fd8c4d9b28f2 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Sat, 21 Sep 2024 17:17:07 +0530 Subject: [PATCH] fix: RawTensor lifetimes should be bounded by session lifetime --- src/interpreter.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 79127fb..4517ba1 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -270,7 +270,7 @@ impl Interpreter { &self, session: &'s crate::Session, name: impl AsRef, - ) -> Result { + ) -> Result> { let name = name.as_ref(); let c_name = std::ffi::CString::new(name).change_context(ErrorKind::AsciiError)?; let input = unsafe { @@ -307,7 +307,7 @@ impl Interpreter { &self, session: &'s crate::Session, name: impl AsRef, - ) -> Result { + ) -> Result> { let name = name.as_ref(); let c_name = std::ffi::CString::new(name).change_context(ErrorKind::AsciiError)?; let output = unsafe { @@ -625,3 +625,14 @@ fn check_whether_sync_actually_works() { let time2 = time2.elapsed(); assert!((time - time2) > std::time::Duration::from_millis(50)); } + +#[test] +fn try_to_drop_interpreter_before_session() { + let file = Path::new("tests/assets/realesr.mnn") + .canonicalize() + .unwrap(); + let mut interpreter = Interpreter::from_file(&file).unwrap(); + let session = interpreter.create_session(ScheduleConfig::new()).unwrap(); + drop(interpreter); + drop(session); +}