Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using SQLite types in type signatures #43519

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using SQLitePCL;

namespace Microsoft.CodeAnalysis.SQLite.Interop
{
internal sealed class SafeSqliteBlobHandle : SafeSqliteChildHandle<sqlite3_blob>
internal sealed class SafeSqliteBlobHandle : SafeHandle
{
private readonly sqlite3_blob? _wrapper;
private readonly SafeHandleLease _lease;

public SafeSqliteBlobHandle(SafeSqliteHandle sqliteHandle, sqlite3_blob? wrapper)
: base(sqliteHandle, wrapper?.ptr ?? IntPtr.Zero, wrapper)
: base(invalidHandleValue: IntPtr.Zero, ownsHandle: true)
{
_wrapper = wrapper;
SetHandle(wrapper?.ptr ?? IntPtr.Zero);
_lease = sqliteHandle.Lease();
}

protected override bool ReleaseChildHandle()
public override bool IsInvalid => handle == IntPtr.Zero;

public new sqlite3_blob DangerousGetHandle()
=> _wrapper!;

protected override bool ReleaseHandle()
{
var result = (Result)raw.sqlite3_blob_close(Wrapper);
using var _ = _lease;
var result = (Result)raw.sqlite3_blob_close(_wrapper);
return result == Result.OK;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using SQLitePCL;

namespace Microsoft.CodeAnalysis.SQLite.Interop
{
internal sealed class SafeSqliteHandle : SafeSqliteHandle<sqlite3>
internal sealed class SafeSqliteHandle : SafeHandle
{
private readonly sqlite3? _wrapper;

public SafeSqliteHandle(sqlite3? wrapper)
: base(wrapper?.ptr ?? IntPtr.Zero, wrapper)
: base(invalidHandleValue: IntPtr.Zero, ownsHandle: true)
{
_wrapper = wrapper;
SetHandle(wrapper?.ptr ?? IntPtr.Zero);
}

public override bool IsInvalid => handle == IntPtr.Zero;

public new sqlite3 DangerousGetHandle()
=> _wrapper!;

protected override bool ReleaseHandle()
{
var result = (Result)raw.sqlite3_close(Wrapper);
var result = (Result)raw.sqlite3_close(_wrapper);
return result == Result.OK;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using SQLitePCL;

namespace Microsoft.CodeAnalysis.SQLite.Interop
{
internal sealed class SafeSqliteStatementHandle : SafeSqliteChildHandle<sqlite3_stmt>
internal sealed class SafeSqliteStatementHandle : SafeHandle
{
private readonly sqlite3_stmt? _wrapper;
private readonly SafeHandleLease _lease;

public SafeSqliteStatementHandle(SafeSqliteHandle sqliteHandle, sqlite3_stmt? wrapper)
: base(sqliteHandle, wrapper?.ptr ?? IntPtr.Zero, wrapper)
: base(invalidHandleValue: IntPtr.Zero, ownsHandle: true)
{
_wrapper = wrapper;
SetHandle(wrapper?.ptr ?? IntPtr.Zero);
_lease = sqliteHandle.Lease();
}

protected override bool ReleaseChildHandle()
public override bool IsInvalid => handle == IntPtr.Zero;

public new sqlite3_stmt DangerousGetHandle()
=> _wrapper!;

protected override bool ReleaseHandle()
{
var result = (Result)raw.sqlite3_finalize(Wrapper);
using var _ = _lease;
var result = (Result)raw.sqlite3_finalize(_wrapper);
return result == Result.OK;
}
}
Expand Down