Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#38, #40] Fix lifetime errors in
sub_self_call
This is a complicated fix. Here are the things it does: - Calculate the `ydb_buffer_t` references for the variable and subscripts on every loop iteration, not once per call. This is what avoids the unsoundness in #40, since the `buf_addr` will be updated if the variable is reallocated. - Drop `t` before calling `ydb_subscript_next`. This avoids the following borrow-check errors: ``` error[E0502]: cannot borrow `*self` as immutable because it is also borrowed as mutable --> src/simple_api/mod.rs:1163:41 | 1149 | let t = self.subscripts.last_mut().unwrap_or(unsafe { self.variable.as_mut_vec() }); | --------------- mutable borrow occurs here ... 1163 | let (varname, subscripts) = self.get_buffers(); | ^^^^ immutable borrow occurs here ... 1183 | t.reserve(last_self_buffer.len_used as usize - t.len()); | - mutable borrow later used here ``` See code comments for details. It's possible in theory that this could be avoided by using raw pointers instead of a `&mut`, but I don't feel confident enough in my knowledge of unsafe Rust to do that. I would feel more confident if [Miri](https://github.com/rust-lang/miri/) worked on YDBRust, but unfortunately it [doesn't support external FFI calls](rust-lang/miri#11). - Add a test for the previous undefined behavior. - Make `get_last_buffer` an unsafe function It is used correctly, but knowing that requires non-local reasoning. This found a clippy bug: rust-lang/rust-clippy#6675
- Loading branch information