Skip to content

Commit b2c4ae5

Browse files
committed
Updated .NET Core in CI and nullable option
1 parent c1407c6 commit b2c4ae5

82 files changed

Lines changed: 485 additions & 605 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ install:
1818
- powershell .build\setup_appveyor.ps1
1919
# The following can be used to install a custom version of .NET Core
2020
- ps: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1" -OutFile "install-dotnet.ps1"
21-
- ps: .\install-dotnet.ps1 -Version 3.0.100-preview6-012264 -InstallDir "dotnetcli"
21+
- ps: .\install-dotnet.ps1 -Version 3.0.100-preview8-013656 -InstallDir "dotnetcli"
2222
services:
2323
- postgresql111
2424
before_build:

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PropertyGroup>
2121
<LangVersion>8.0</LangVersion>
2222
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
23-
<NullableContextOptions>enable</NullableContextOptions>
23+
<Nullable>enable</Nullable>
2424
</PropertyGroup>
2525

2626
<!-- Siging configuration -->

global.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"sdk": {
3-
"version": "3.0.100-preview6-012264"
4-
}
2+
"sdk": {
3+
"version": "3.0.100-preview8-013656"
4+
}
55
}

src/Npgsql.Json.NET/JsonHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLength
6464
return base.ValidateAndGetLength(s, ref lengthCache, parameter);
6565
}
6666

67-
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
67+
protected override Task WriteObjectWithLength(object? value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
6868
{
6969
if (value == null || value is DBNull)
7070
return base.WriteObjectWithLength(DBNull.Value, buf, lengthCache, parameter, async);

src/Npgsql.Json.NET/JsonbHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLength
6565
return base.ValidateObjectAndGetLength(s, ref lengthCache, parameter);
6666
}
6767

68-
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
68+
protected override Task WriteObjectWithLength(object? value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
6969
{
7070
if (value == null || value is DBNull)
7171
return base.WriteObjectWithLength(DBNull.Value, buf, lengthCache, parameter, async);

src/Npgsql/BackendMessages/RowDescriptionMessage.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ sealed class RowDescriptionMessage : IBackendMessage
2121
public List<FieldDescription> Fields { get; }
2222
readonly Dictionary<string, int> _nameIndex;
2323
Dictionary<string, int>? _insensitiveIndex;
24-
bool _isInsensitiveIndexInitialized;
2524

2625
internal RowDescriptionMessage()
2726
{
@@ -35,21 +34,15 @@ internal RowDescriptionMessage()
3534
foreach (var f in source.Fields)
3635
Fields.Add(f.Clone());
3736
_nameIndex = new Dictionary<string, int>(source._nameIndex);
38-
if (source._insensitiveIndex != null)
37+
if (source._insensitiveIndex?.Count > 0)
3938
_insensitiveIndex = new Dictionary<string, int>(source._insensitiveIndex);
40-
_isInsensitiveIndexInitialized = source._isInsensitiveIndexInitialized;
4139
}
4240

4341
internal RowDescriptionMessage Load(NpgsqlReadBuffer buf, ConnectorTypeMapper typeMapper)
4442
{
4543
Fields.Clear();
4644
_nameIndex.Clear();
47-
if (_isInsensitiveIndexInitialized)
48-
{
49-
Debug.Assert(_insensitiveIndex != null);
50-
_insensitiveIndex.Clear();
51-
_isInsensitiveIndexInitialized = false;
52-
}
45+
_insensitiveIndex?.Clear();
5346

5447
var numFields = buf.ReadInt16();
5548
for (var i = 0; i != numFields; ++i)
@@ -101,19 +94,16 @@ internal bool TryGetFieldIndex(string name, out int fieldIndex)
10194
if (_nameIndex.TryGetValue(name, out fieldIndex))
10295
return true;
10396

104-
if (!_isInsensitiveIndexInitialized)
97+
if (_insensitiveIndex is null || _insensitiveIndex.Count == 0)
10598
{
10699
if (_insensitiveIndex == null)
107100
_insensitiveIndex = new Dictionary<string, int>(InsensitiveComparer.Instance);
108101

109102
foreach (var kv in _nameIndex)
110103
if (!_insensitiveIndex.ContainsKey(kv.Key))
111104
_insensitiveIndex[kv.Key] = kv.Value;
112-
113-
_isInsensitiveIndexInitialized = true;
114105
}
115106

116-
Debug.Assert(_insensitiveIndex != null);
117107
return _insensitiveIndex.TryGetValue(name, out fieldIndex);
118108
}
119109

src/Npgsql/ConnectorPool.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78
using System.Threading;
@@ -120,7 +121,7 @@ internal ConnectorPool(NpgsqlConnectionStringBuilder settings, string connString
120121
}
121122

122123
[MethodImpl(MethodImplOptions.AggressiveInlining)]
123-
internal bool TryAllocateFast(NpgsqlConnection conn, [NotNullWhenTrue] out NpgsqlConnector? connector)
124+
internal bool TryAllocateFast(NpgsqlConnection conn, [NotNullWhen(true)] out NpgsqlConnector? connector)
124125
{
125126
Counters.SoftConnectsPerSecond.Increment();
126127

@@ -313,7 +314,7 @@ internal async ValueTask<NpgsqlConnector> AllocateLong(NpgsqlConnection conn, Np
313314
// Use Task.Delay to implement the timeout, but cancel the timer if we actually
314315
// do complete successfully
315316
var delayCancellationToken = new CancellationTokenSource();
316-
using (cancellationToken.Register(s => ((CancellationTokenSource)s).Cancel(), delayCancellationToken))
317+
using (cancellationToken.Register(s => ((CancellationTokenSource)s!).Cancel(), delayCancellationToken))
317318
{
318319
var timeLeft = timeout.TimeLeft;
319320
if (timeLeft <= TimeSpan.Zero ||
@@ -328,7 +329,7 @@ await Task.WhenAny(tcs.Task, Task.Delay(timeLeft, delayCancellationToken.Token))
328329
}
329330
else
330331
{
331-
using (cancellationToken.Register(s => ((TaskCompletionSource<NpgsqlConnector?>)s).SetCanceled(), tcs))
332+
using (cancellationToken.Register(s => ((TaskCompletionSource<NpgsqlConnector?>)s!).SetCanceled(), tcs))
332333
await tcs.Task;
333334
}
334335
}
@@ -534,9 +535,9 @@ void CloseConnector(NpgsqlConnector connector, bool wasIdle)
534535
}
535536
}
536537

537-
static void PruneIdleConnectors(object state)
538+
static void PruneIdleConnectors(object? state)
538539
{
539-
var pool = (ConnectorPool)state;
540+
var pool = (ConnectorPool)state!;
540541
var idle = pool._idle;
541542
var now = DateTime.UtcNow;
542543
var idleLifetime = pool.Settings.ConnectionIdleLifetime;

src/Npgsql/Counters.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
2-
using System.Reflection;
32
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Reflection;
45
using Npgsql.Logging;
56

67
namespace Npgsql
@@ -10,39 +11,39 @@ static class Counters
1011
/// <summary>
1112
/// The number of connections per second that are being made to a database server.
1213
/// </summary>
13-
internal static Counter HardConnectsPerSecond;
14+
internal static readonly Counter HardConnectsPerSecond = new Counter(nameof(HardConnectsPerSecond));
1415
/// <summary>
1516
/// The number of disconnects per second that are being made to a database server.
1617
/// </summary>
17-
internal static Counter HardDisconnectsPerSecond;
18+
internal static readonly Counter HardDisconnectsPerSecond = new Counter(nameof(HardDisconnectsPerSecond));
1819
/// <summary>
1920
/// The total number of connection pools.
2021
/// </summary>
21-
internal static Counter NumberOfActiveConnectionPools;
22+
internal static readonly Counter NumberOfActiveConnectionPools = new Counter(nameof(NumberOfActiveConnectionPools));
2223
/// <summary>
2324
/// The number of (pooled) active connections that are currently in use.
2425
/// </summary>
25-
internal static Counter NumberOfActiveConnections;
26+
internal static readonly Counter NumberOfActiveConnections = new Counter(nameof(NumberOfActiveConnections));
2627
/// <summary>
2728
/// The number of connections available for use in the connection pools.
2829
/// </summary>
29-
internal static Counter NumberOfFreeConnections;
30+
internal static readonly Counter NumberOfFreeConnections = new Counter(nameof(NumberOfFreeConnections));
3031
/// <summary>
3132
/// The number of active connections that are not pooled.
3233
/// </summary>
33-
internal static Counter NumberOfNonPooledConnections;
34+
internal static readonly Counter NumberOfNonPooledConnections = new Counter(nameof(NumberOfNonPooledConnections));
3435
/// <summary>
3536
/// The number of active connections that are being managed by the connection pooling infrastructure.
3637
/// </summary>
37-
internal static Counter NumberOfPooledConnections;
38+
internal static readonly Counter NumberOfPooledConnections = new Counter(nameof(NumberOfPooledConnections));
3839
/// <summary>
3940
/// The number of active connections being pulled from the connection pool.
4041
/// </summary>
41-
internal static Counter SoftConnectsPerSecond;
42+
internal static readonly Counter SoftConnectsPerSecond = new Counter(nameof(SoftConnectsPerSecond));
4243
/// <summary>
4344
/// The number of active connections that are being returned to the connection pool.
4445
/// </summary>
45-
internal static Counter SoftDisconnectsPerSecond;
46+
internal static readonly Counter SoftDisconnectsPerSecond = new Counter(nameof(SoftDisconnectsPerSecond));
4647

4748
static bool _initialized;
4849
static readonly object InitLock = new object();
@@ -81,15 +82,15 @@ internal static void Initialize(bool usePerfCounters)
8182

8283
try
8384
{
84-
HardConnectsPerSecond = new Counter(enabled, nameof(HardConnectsPerSecond));
85-
HardDisconnectsPerSecond = new Counter(enabled, nameof(HardDisconnectsPerSecond));
86-
NumberOfActiveConnectionPools = new Counter(enabled, nameof(NumberOfActiveConnectionPools));
87-
NumberOfNonPooledConnections = new Counter(enabled, nameof(NumberOfNonPooledConnections));
88-
NumberOfPooledConnections = new Counter(enabled, nameof(NumberOfPooledConnections));
89-
SoftConnectsPerSecond = new Counter(expensiveEnabled, nameof(SoftConnectsPerSecond));
90-
SoftDisconnectsPerSecond = new Counter(expensiveEnabled, nameof(SoftDisconnectsPerSecond));
91-
NumberOfActiveConnections = new Counter(expensiveEnabled, nameof(NumberOfActiveConnections));
92-
NumberOfFreeConnections = new Counter(expensiveEnabled, nameof(NumberOfFreeConnections));
85+
HardConnectsPerSecond.Initialize(enabled);
86+
HardDisconnectsPerSecond.Initialize(enabled);
87+
NumberOfActiveConnectionPools.Initialize(enabled);
88+
NumberOfNonPooledConnections.Initialize(enabled);
89+
NumberOfPooledConnections.Initialize(enabled);
90+
SoftConnectsPerSecond.Initialize(expensiveEnabled);
91+
SoftDisconnectsPerSecond.Initialize(expensiveEnabled);
92+
NumberOfActiveConnections.Initialize(expensiveEnabled);
93+
NumberOfFreeConnections.Initialize(expensiveEnabled);
9394
}
9495
catch (Exception e)
9596
{
@@ -114,17 +115,19 @@ sealed class Counter : IDisposable
114115
#endif
115116
public string Name { get; }
116117

117-
internal Counter(bool enabled, string diagnosticsCounterName)
118+
internal Counter(string diagnosticsCounterName)
119+
=> Name = diagnosticsCounterName;
120+
121+
internal void Initialize(bool enabled)
118122
{
119-
Name = diagnosticsCounterName;
123+
#if NET461
120124
if (!enabled)
121125
return;
122126

123-
#if NET461
124127
DiagnosticsCounter = new PerformanceCounter
125128
{
126129
CategoryName = DiagnosticsCounterCategory,
127-
CounterName = diagnosticsCounterName,
130+
CounterName = Name,
128131
InstanceName = InstanceName,
129132
InstanceLifetime = PerformanceCounterInstanceLifetime.Process,
130133
ReadOnly = false,

src/Npgsql/KerberosUsernameProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Npgsql
1313
class KerberosUsernameProvider
1414
{
1515
static bool _performedDetection;
16-
static string _principalWithRealm;
17-
static string _principalWithoutRealm;
16+
static string? _principalWithRealm;
17+
static string? _principalWithoutRealm;
1818

1919
static readonly NpgsqlLogger Log = NpgsqlLogManager.CreateLogger(nameof(KerberosUsernameProvider));
2020

@@ -52,15 +52,15 @@ static void DetectUsername()
5252
return;
5353
}
5454

55-
var line = "";
55+
var line = default(string);
5656
for (var i = 0; i < 2; i++)
5757
if ((line = process.StandardOutput.ReadLine()) == null)
5858
{
5959
Log.Debug("Unexpected output from klist, aborting Kerberos username detection");
6060
return;
6161
}
6262

63-
var components = line.Split(':');
63+
var components = line!.Split(':');
6464
if (components.Length != 2)
6565
{
6666
Log.Debug("Unexpected output from klist, aborting Kerberos username detection");
@@ -79,8 +79,8 @@ static void DetectUsername()
7979
_principalWithoutRealm = components[0];
8080
}
8181

82-
static string FindInPath(string name) => Environment.GetEnvironmentVariable("PATH")
83-
.Split(Path.PathSeparator)
82+
static string? FindInPath(string name) => Environment.GetEnvironmentVariable("PATH")
83+
?.Split(Path.PathSeparator)
8484
.Select(p => Path.Combine(p, name))
8585
.FirstOrDefault(File.Exists);
8686
}

0 commit comments

Comments
 (0)