lucifer1004 opened a new pull request, #818:
URL: https://github.com/apache/tvm-ffi/pull/818

   ## Why
   
   `with_stream` sets the device stream, runs the closure, and restores the 
previous stream:
   
   ```rust
   let result = f()?;
   // restore prev_stream
   ```
   
   When the closure returns an error, `?` returns before the restore, so the 
device keeps the temporary stream and later work on that thread runs on it. A 
panic in the closure skips the restore the same way.
   
   ## What
   
   - The previous stream is restored however the closure exits.
     - On return (value or error) it is restored explicitly, and a failed 
restore is still reported. The closure's own error takes precedence.
     - While unwinding, a drop guard restores it.
   - The doc comment states the guarantee.
   
   ## Tests
   
   - `tests/test_device.rs` adds two cases, a closure that returns an error and 
one that panics. Both check that `current_stream` is back to the previous 
(null) stream afterwards.
     - On `main` both fail: `2 passed; 2 failed`.
     - With this change all 4 device tests pass.
   - `cargo test` in `rust/` passes; all 24 suites pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to