Skip to content

Commit dba1792

Browse files
committed
let's call this progress on #321 but not a resolution. following up on investigation by @kpreisser I have changed the problematic overload of raw.sqlite3_prepare_v2() to call a different overload of same in the provider to avoid creating a span from a pointer. with this change, I can run the issue321 repro app at 20 iterations on net461 without a failure. so this seems to confirm with @kpreisser said, but now every case where I create a span from a pointer needs to be reviewed for this kind of lifetime issue.
1 parent 299ef4f commit dba1792

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<Copyright>Copyright 2014-2020 SourceGear, LLC</Copyright>
55
<Company>SourceGear</Company>
66
<Authors>Eric Sink</Authors>
7-
<Version>2.0.4-pre20200603163150</Version>
8-
<AssemblyVersion>2.0.4.884</AssemblyVersion>
9-
<FileVersion>2.0.4.884</FileVersion>
7+
<Version>2.0.4-pre20200604104406</Version>
8+
<AssemblyVersion>2.0.4.885</AssemblyVersion>
9+
<FileVersion>2.0.4.885</FileVersion>
1010
<Description>SQLitePCLRaw is a Portable Class Library (PCL) for low-level (raw) access to SQLite</Description>
1111
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1212
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

src/SQLitePCLRaw.core/raw.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,10 @@ static public int sqlite3_prepare_v2(sqlite3 db, utf8z sql, out sqlite3_stmt stm
736736

737737
static public int sqlite3_prepare_v2(sqlite3 db, string sql, out sqlite3_stmt stmt, out string tail)
738738
{
739-
int rc = sqlite3_prepare_v2(db, sql.to_utf8z(), out stmt, out var sp_tail);
740-
tail = sp_tail.utf8_to_string();
739+
var ba = sql.to_utf8_with_z();
740+
var sp = new ReadOnlySpan<byte>(ba);
741+
int rc = sqlite3_prepare_v2(db, sp, out stmt, out var sp_tail);
742+
tail = utf8_span_to_string(sp_tail.Slice(0, sp_tail.Length - 1));
741743
return rc;
742744
}
743745

test_nupkgs/issue321/repro.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static string RandomString(int length)
9494

9595
public static void Main()
9696
{
97-
var num = 10;
97+
var num = 20;
9898
for (var i = 0; i<num; i++)
9999
{
100100
Console.Write($"{i + 1} of {num}: ");

0 commit comments

Comments
 (0)