Skip to content

Commit

Permalink
fix: RawTensor lifetimes should be bounded by session lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
uttarayan21 committed Sep 21, 2024
1 parent 347b1d4 commit ceb83d3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl Interpreter {
&self,
session: &'s crate::Session,
name: impl AsRef<str>,
) -> Result<RawTensor> {
) -> Result<RawTensor<'s>> {
let name = name.as_ref();
let c_name = std::ffi::CString::new(name).change_context(ErrorKind::AsciiError)?;
let input = unsafe {
Expand Down Expand Up @@ -307,7 +307,7 @@ impl Interpreter {
&self,
session: &'s crate::Session,
name: impl AsRef<str>,
) -> Result<RawTensor> {
) -> Result<RawTensor<'s>> {
let name = name.as_ref();
let c_name = std::ffi::CString::new(name).change_context(ErrorKind::AsciiError)?;
let output = unsafe {
Expand Down Expand Up @@ -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);
}

0 comments on commit ceb83d3

Please sign in to comment.