Switch to more current version of sqlitepcl#50841
Conversation
| namespace Microsoft.CodeAnalysis.SQLite.Interop | ||
| { | ||
| internal sealed class SafeSqliteBlobHandle : SafeHandle | ||
| internal sealed class SafeSqliteBlobHandle : IDisposable |
There was a problem hiding this comment.
@sharwell was not sure how to handle converting these over. the main issue was that the sqlite core types (like sqlite3_blob) are now SafeHandles themselves, and do not expose the .ptr value.
There was a problem hiding this comment.
i thnik we still want these as your leasing pattern effectively means: as long as we create subhandles (i.e. blobs/statements, they should hold the outer sqlite3 instance alive).
| public static extern int sqlite3_bind_blob(SafeSqliteStatementHandle stmt, int index, byte[] val, int nSize, IntPtr nTransient); | ||
|
|
||
| internal byte[] GetBlobAt(int columnIndex) | ||
| => NativeMethods.sqlite3_column_blob(_rawStatement, columnIndex); |
| => _connection.ThrowIfNotOk(sqlite3_bind_blob(_rawStatement, parameterIndex, value, length, new IntPtr(-1))); | ||
|
|
||
| [DllImport("e_sqlite3.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int sqlite3_bind_blob(SafeSqliteStatementHandle stmt, int index, byte[] val, int nSize, IntPtr nTransient); |
There was a problem hiding this comment.
was able to get rid of this ugly hack.
src/Workspaces/Core/Portable/Storage/SQLite/v2/SQLitePersistentStorage.Accessor.cs
Outdated
Show resolved
Hide resolved
| public void WriteTo(Span<byte> span) | ||
| { | ||
| var localCopy = _checksum; | ||
| Contract.ThrowIfFalse(MemoryMarshal.TryWrite(span, ref localCopy)); |
There was a problem hiding this comment.
copy needed, because you can't pass a readonly field by-ref.
|
@sharwell I've redone how checksums are done entirely in the storage layer. Instead of using generalized paths that go through arbitrary reading/writing of streams, the checksum paths are optimized and can do all their work without an intermediary stream abstraction. |
|
Hey @CyrusNajmabadi, could #23424 be solved as part of this PR? |
|
Yes, quite possibly. I'll look into that next week. |
Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com>
| // can happen when rowId points to a row that hasn't been written to yet. | ||
| return null; | ||
| } | ||
| Contract.ThrowIfFalse(MemoryMarshal.TryRead(bytes, out Checksum.HashData hashData)); |
There was a problem hiding this comment.
❗ Need to use HashData.FromPointer here.
roslyn/src/Workspaces/Core/Portable/Workspace/Solution/Checksum.cs
Lines 98 to 102 in 230d0d0
| => _checksum.WriteTo(writer); | ||
|
|
||
| public void WriteTo(Span<byte> span) | ||
| => Contract.ThrowIfFalse(MemoryMarshal.TryWrite(span, ref Unsafe.AsRef(in _checksum))); |
There was a problem hiding this comment.
This line also suffers from the sizeof(HashData)/HashSize mismatch 😢
| { | ||
| fixed (byte* bytes = &span.GetPinnableReference()) | ||
| { | ||
| *(HashData*)bytes = _checksum; |
There was a problem hiding this comment.
📝 This should write each field individually rather than trying to copy the entire structure to a new location.
There was a problem hiding this comment.
tried that, but i get:
Severity Code Description File
Error CS0191 A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer) C:\github\roslyn\src\Workspaces\Core\Portable\Workspace\Solution\Checksum.cs
| public void WriteTo(Span<byte> span) | ||
| => Contract.ThrowIfFalse(MemoryMarshal.TryWrite(span, ref Unsafe.AsRef(in _checksum))); | ||
| { | ||
| unsafe |
There was a problem hiding this comment.
❗ Need to validate span.Length >= HashSize
05427f7 to
041f26c
Compare
Fixes #23424