From f873c42cbfbe68e4235824bba82aff245c4f8920 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Thu, 15 Aug 2024 22:26:47 -0700 Subject: [PATCH] fix(logging): Account for nullable value types This commit updates logging to handle nullable value types and parameters. The following changes were made: - Updated the Value record to use '!' instead of '?' for nullability. - Added '!' to the default Value. - Added '!= null' checks to conditional assignment. - Removed unnecessary nullable-disable compiler directives. --- Utilities.cs | 3 ++- ar/ArithmeticDecoder.cs | 10 +++++----- imm/Imm.cs | 4 ++-- logging/Log.cs | 2 +- prof/Program.cs | 2 +- res/Resource.cs | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Utilities.cs b/Utilities.cs index 3f3f10a..dc2a7cb 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -133,7 +133,8 @@ namespace lib } else { - log.debug( $"{path} already exists." ); + var cwd = Directory.GetCurrentDirectory(); + log.debug( $"Dir {path}/ already exists. {cwd}" ); } } diff --git a/ar/ArithmeticDecoder.cs b/ar/ArithmeticDecoder.cs index 8506b02..7ff1cf7 100644 --- a/ar/ArithmeticDecoder.cs +++ b/ar/ArithmeticDecoder.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -43,7 +43,7 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase code = 0; for (int i = 0; i < numStateBits; i++) { - code = code << 1 | readCodeBit(); + code = code << 1 | (long)readCodeBit(); } } @@ -123,7 +123,7 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase //ORIGINAL LINE: protected void shift() throws java.io.IOException protected internal override void shift() { - code = ((code << 1) & stateMask) | readCodeBit(); + code = ((code << 1) & stateMask) | (long)readCodeBit(); } @@ -131,7 +131,7 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase //ORIGINAL LINE: protected void underflow() throws java.io.IOException protected internal override void underflow() { - code = (code & halfRange) | ((code << 1) & ((long)((ulong)stateMask >> 1))) | readCodeBit(); + code = (code & halfRange) | ((code << 1) & ((long)((ulong)stateMask >> 1))) | (long)readCodeBit(); } diff --git a/imm/Imm.cs b/imm/Imm.cs index f26f36f..5985c9f 100644 --- a/imm/Imm.cs +++ b/imm/Imm.cs @@ -97,7 +97,7 @@ public record class Versioned : Imm where T : Versioned { - public delegate void ChangeDelegate( T old, T next ); + public delegate void ChangeDelegate( T? old, T next ); public record class MetaData : Meta { @@ -138,7 +138,7 @@ public record class Versioned : Imm [lib.Dont] [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public ChangeDelegate OnChange = (old, cur) => {}; + public ChangeDelegate OnChange = (T? old,T cur) => {}; /* public void AddOnChange( ChangeDelegate fn, diff --git a/logging/Log.cs b/logging/Log.cs index badb3da..fddd01f 100644 --- a/logging/Log.cs +++ b/logging/Log.cs @@ -34,7 +34,7 @@ N O T D O I N G : public record struct Value( T _val, string _exp = "" ) { - public static T Default = default; + public static T Default = default!; public static implicit operator T( Value v ) { diff --git a/prof/Program.cs b/prof/Program.cs index e6ae889..1403092 100644 --- a/prof/Program.cs +++ b/prof/Program.cs @@ -12,7 +12,7 @@ namespace Tracing { - static public async Task CreateTracingSession( bool noSampling, bool sortBySize, int topTypesLimit ) + static public int CreateTracingSession( bool noSampling, bool sortBySize, int topTypesLimit ) { ShowHeader(); diff --git a/res/Resource.cs b/res/Resource.cs index 28cbc80..86ff5fe 100644 --- a/res/Resource.cs +++ b/res/Resource.cs @@ -395,7 +395,7 @@ public class Mgr } } - return actualLoad( filename ); + //return actualLoad( filename ); } static object s_loadingLock = new object();