cgosqlite: add feature flag to always copy []bytes returned#123
Merged
cgosqlite: add feature flag to always copy []bytes returned#123
Conversation
bradfitz
reviewed
Jan 7, 2026
7034e6c to
58e2090
Compare
bradfitz
reviewed
Jan 7, 2026
| } | ||
| n := int(C.sqlite3_column_bytes(stmt.stmt, C.int(col))) | ||
| return unsafe.Slice((*byte)(unsafe.Pointer(res)), n) | ||
| slice := unsafe.Slice((*byte)(unsafe.Pointer(res)), n) |
Member
There was a problem hiding this comment.
I'm trying to remember/confirm what unsafe.Slice's behavior is when n == 0.
Maybe we don't want that pointer in the slice header even a 0 len and 0 cap?
Worth a if n == 0 { return nil } above this?
Oh, no, that'd change it to map to a NULL column, huh?
So I guess this is correct.
(sorry, thinking aloud)
bradfitz
approved these changes
Jan 7, 2026
Member
|
Want to add some tests that verify basic stuff still works with this enabled? |
When enabled, this ensures that sql.RawBytes values do not actually contain pointers to memory owned by SQLite. Also add some tests that verify the behaviour of ColumnBlob, both with and without this flag set. Updates tailscale/corp#35671 Signed-off-by: Andrew Dunham <andrew@tailscale.com>
58e2090 to
ca57704
Compare
Member
Author
Just added a basic test case; PTAL? |
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.
When enabled, this ensures that sql.RawBytes values do not actually contain pointers to memory owned by SQLite.
Updates tailscale/corp#35671