Closed
Conversation
This requires a new associated type for mapped regions which would break backward compatibility without default associated types, which is currently unstable in Rust. Instead, a new `ShmVfs` trait is introduced with alternate registration methods. Most of the code is shared between the two except for the open/close glue functions for `ShmVfs`, which must initialize and tear down a derived file handle structure. The lifetime semantics of returned mapped regions is a little odd: the region is only accessed once by sqlite immediately upon return, but we don't know for sure when it's done until it explicitly requests a new region, unmaps all regions, or closes the handle. Therefore the API glue obtains a region from the trait as an owned `AsMut<[u8]>` and holds on to it until its known to no longer be referenced, at which point its `Drop` impl can release resources. The previous code which cast the `sqlite3_file` directly to `&mut` looked like it could lead to undefined behavior (it's UB to create an `&mut` to uninitialized memory, and even if sqlite zeroes the memory first, if there were any embedded `NonZero` you're still in UB territory). I instead `ptr::write` and `ptr::read` the whole thing.
Contributor
|
Woof, this is a much larger change. I'd like to find time to connect and chat about this one before merging. Are you open to that? |
Contributor
Author
|
On Discord? Yeah, hold on. |
Contributor
Author
|
This can't work as designed since sqlite does hold multiple mapped regions at once, making a safe Rust interface very challenging. Needs a rework. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This requires a new associated type for mapped pages/regions which would break backward compatibility without default associated types, which is currently unstable in Rust. Instead, a new
ShmVfstrait is introduced with alternate registration methods. Most of the code is shared between the two except for the open/close glue functions forShmVfs, which must initialize and tear down a derived file handle structure.The lifetime semantics of returned mapped regions is a little odd: the region is only accessed once by sqlite immediately upon return, but we don't know for sure when it's done until it explicitly requests a new region, unmaps all regions, or closes the handle. Therefore the API glue obtains a region from the trait as an owned
AsMut<[u8]>and holds on to it until its known to no longer be referenced, at which point itsDropimpl can release resources.The previous code which cast the
sqlite3_filedirectly to&mutlooked like it could lead to undefined behavior (it's UB to create an&mutto uninitialized memory, and even if sqlite zeroes the memory first, if there were any embeddedNonZeroyou're still in UB territory). I insteadptr::writeandptr::readthe whole thing.