diff --git a/DotnetCliVersion.txt b/DotnetCliVersion.txt index 2d3b63da..5dc9c8d9 100644 --- a/DotnetCliVersion.txt +++ b/DotnetCliVersion.txt @@ -1 +1 @@ -6.0.403 \ No newline at end of file +7.0.100 \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index ad7a64c7..66e84f4f 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -45,7 +45,7 @@ partial class Build : NukeBuild AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed"; AbsolutePath TempDirectory => RootDirectory / ".nuke" / "temp"; - AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net6.0"; + AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net7.0"; AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}"; AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}"; AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip"; @@ -229,7 +229,7 @@ partial class Build : NukeBuild DotNetPublish(s => publishSettings .SetProject(HactoolnetProject) - .SetFramework("net6.0") + .SetFramework("net7.0") .SetOutput(CliCoreDir) .SetNoBuild(true) .SetProperties(VersionProps)); @@ -279,7 +279,7 @@ partial class Build : NukeBuild .EnableNoBuild() .SetConfiguration(Configuration); - if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net6.0"); + if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net7.0"); DotNetTest(s => settings); }); @@ -596,7 +596,7 @@ partial class Build : NukeBuild SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray()); // Avoid having multiple signed versions of the same file - File.Copy(nupkgDir / "lib" / "net6.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true); + File.Copy(nupkgDir / "lib" / "net7.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList, CommitTime); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir, CommitTime); diff --git a/build/CodeGen/Common.cs b/build/CodeGen/Common.cs index e099466d..c1dbada8 100644 --- a/build/CodeGen/Common.cs +++ b/build/CodeGen/Common.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; -using Nuke.Common; namespace LibHacBuild.CodeGen; diff --git a/build/CodeGen/_buildCodeGen.csproj b/build/CodeGen/_buildCodeGen.csproj index 363300dd..af4efbca 100644 --- a/build/CodeGen/_buildCodeGen.csproj +++ b/build/CodeGen/_buildCodeGen.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 false LibHacBuild.CodeGen False diff --git a/build/_build.csproj b/build/_build.csproj index 8e47da71..d0dea435 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 false LibHacBuild False diff --git a/nuget.config b/nuget.config index f09c0be2..41b398ea 100644 --- a/nuget.config +++ b/nuget.config @@ -2,6 +2,5 @@ - diff --git a/src/LibHac/Account/Uid.cs b/src/LibHac/Account/Uid.cs index 17047878..49c16ad3 100644 --- a/src/LibHac/Account/Uid.cs +++ b/src/LibHac/Account/Uid.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; @@ -43,6 +44,7 @@ public struct Uid : IEquatable, IComparable, IComparable public void ToBytes(Span output) => Id.ToBytes(output); + [UnscopedRef] public ReadOnlySpan AsBytes() { return SpanHelpers.AsByteSpan(ref this); diff --git a/src/LibHac/Boot/KeyBlob.cs b/src/LibHac/Boot/KeyBlob.cs index 13394703..07596816 100644 --- a/src/LibHac/Boot/KeyBlob.cs +++ b/src/LibHac/Boot/KeyBlob.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Common.FixedArrays; @@ -13,8 +14,8 @@ public struct EncryptedKeyBlob public AesIv Counter; public Array144 Payload; - public Span Bytes => SpanHelpers.AsByteSpan(ref this); - public readonly ReadOnlySpan BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this); + [UnscopedRef] public Span Bytes => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public readonly ReadOnlySpan BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool IsZeros() @@ -41,8 +42,8 @@ public struct KeyBlob public Array112 Unused; public AesKey Package1Key; - public Span Bytes => SpanHelpers.AsByteSpan(ref this); - public readonly ReadOnlySpan BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this); + [UnscopedRef] public Span Bytes => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public readonly ReadOnlySpan BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool IsZeros() diff --git a/src/LibHac/Boot/Package1.cs b/src/LibHac/Boot/Package1.cs index 4f954a99..d8ea2b19 100644 --- a/src/LibHac/Boot/Package1.cs +++ b/src/LibHac/Boot/Package1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -35,8 +36,8 @@ public struct Package1MetaData public byte KeyGeneration; public byte Version; - public U8Span BuildDate => new U8Span(_buildDate); - public ReadOnlySpan Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10); + [UnscopedRef] public U8Span BuildDate => new U8Span(_buildDate); + [UnscopedRef] public ReadOnlySpan Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10); } public struct Package1Stage1Footer diff --git a/src/LibHac/Common/Buffer.cs b/src/LibHac/Common/Buffer.cs index cfaf233a..a1c37a96 100644 --- a/src/LibHac/Common/Buffer.cs +++ b/src/LibHac/Common/Buffer.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Util; @@ -22,7 +23,7 @@ public struct Buffer16 set => Bytes[i] = value; } - public Span Bytes => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public Span Bytes => SpanHelpers.AsByteSpan(ref this); // Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef() [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -37,7 +38,7 @@ public struct Buffer16 return SpanHelpers.AsReadOnlyByteSpan(in value); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T As() where T : unmanaged { if (Unsafe.SizeOf() > (uint)Unsafe.SizeOf()) @@ -48,13 +49,13 @@ public struct Buffer16 return ref MemoryMarshal.GetReference(AsSpan()); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan() where T : unmanaged { return SpanHelpers.AsSpan(ref this); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ReadOnlySpan AsReadOnlySpan() where T : unmanaged { return SpanHelpers.AsReadOnlySpan(in this); @@ -80,7 +81,7 @@ public struct Buffer32 set => Bytes[i] = value; } - public Span Bytes => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public Span Bytes => SpanHelpers.AsByteSpan(ref this); // Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef() [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -95,7 +96,7 @@ public struct Buffer32 return SpanHelpers.AsReadOnlyByteSpan(in value); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T As() where T : unmanaged { if (Unsafe.SizeOf() > (uint)Unsafe.SizeOf()) @@ -106,13 +107,13 @@ public struct Buffer32 return ref MemoryMarshal.GetReference(AsSpan()); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan() where T : unmanaged { return SpanHelpers.AsSpan(ref this); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ReadOnlySpan AsReadOnlySpan() where T : unmanaged { return SpanHelpers.AsReadOnlySpan(in this); diff --git a/src/LibHac/Common/FixedArrays/Array1.cs b/src/LibHac/Common/FixedArrays/Array1.cs index 2c82579a..b26a5a2d 100644 --- a/src/LibHac/Common/FixedArrays/Array1.cs +++ b/src/LibHac/Common/FixedArrays/Array1.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -10,10 +11,10 @@ public struct Array1 private T _0; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array1 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array1024.cs b/src/LibHac/Common/FixedArrays/Array1024.cs index 27895286..7773952a 100644 --- a/src/LibHac/Common/FixedArrays/Array1024.cs +++ b/src/LibHac/Common/FixedArrays/Array1024.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array1024 private Array512 _0; private Array512 _512; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array11.cs b/src/LibHac/Common/FixedArrays/Array11.cs index 55d19190..e3543171 100644 --- a/src/LibHac/Common/FixedArrays/Array11.cs +++ b/src/LibHac/Common/FixedArrays/Array11.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -20,10 +21,10 @@ public struct Array11 private T _9; private T _10; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array11 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array112.cs b/src/LibHac/Common/FixedArrays/Array112.cs index d0bf171e..33efc0d8 100644 --- a/src/LibHac/Common/FixedArrays/Array112.cs +++ b/src/LibHac/Common/FixedArrays/Array112.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array112 private Array80 _0; private Array32 _80; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array12.cs b/src/LibHac/Common/FixedArrays/Array12.cs index 5a262655..abcb9a1f 100644 --- a/src/LibHac/Common/FixedArrays/Array12.cs +++ b/src/LibHac/Common/FixedArrays/Array12.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -21,10 +22,10 @@ public struct Array12 private T _10; private T _11; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array12 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array128.cs b/src/LibHac/Common/FixedArrays/Array128.cs index 8d848188..83846199 100644 --- a/src/LibHac/Common/FixedArrays/Array128.cs +++ b/src/LibHac/Common/FixedArrays/Array128.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array128 private Array64 _0; private Array64 _64; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array14.cs b/src/LibHac/Common/FixedArrays/Array14.cs index 28263fd8..3891a881 100644 --- a/src/LibHac/Common/FixedArrays/Array14.cs +++ b/src/LibHac/Common/FixedArrays/Array14.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array14 private Array8 _0; private Array6 _8; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array144.cs b/src/LibHac/Common/FixedArrays/Array144.cs index ec10ebeb..f9866c7e 100644 --- a/src/LibHac/Common/FixedArrays/Array144.cs +++ b/src/LibHac/Common/FixedArrays/Array144.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array144 private Array128 _0; private Array16 _128; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array15.cs b/src/LibHac/Common/FixedArrays/Array15.cs index 8a21ab04..0c4f525b 100644 --- a/src/LibHac/Common/FixedArrays/Array15.cs +++ b/src/LibHac/Common/FixedArrays/Array15.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array15 private Array8 _0; private Array7 _8; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array16.cs b/src/LibHac/Common/FixedArrays/Array16.cs index 732ee8d0..03d99869 100644 --- a/src/LibHac/Common/FixedArrays/Array16.cs +++ b/src/LibHac/Common/FixedArrays/Array16.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array16 private Array8 _0; private Array8 _8; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array16384.cs b/src/LibHac/Common/FixedArrays/Array16384.cs index 0fccaec0..a1438ef2 100644 --- a/src/LibHac/Common/FixedArrays/Array16384.cs +++ b/src/LibHac/Common/FixedArrays/Array16384.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array16384 private Array8192 _0; private Array8192 _8192; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array18.cs b/src/LibHac/Common/FixedArrays/Array18.cs index 5343b47e..fc790594 100644 --- a/src/LibHac/Common/FixedArrays/Array18.cs +++ b/src/LibHac/Common/FixedArrays/Array18.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array18 private Array16 _0; private Array2 _16; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array192.cs b/src/LibHac/Common/FixedArrays/Array192.cs index 6c4d0c77..633ed43e 100644 --- a/src/LibHac/Common/FixedArrays/Array192.cs +++ b/src/LibHac/Common/FixedArrays/Array192.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array192 private Array128 _0; private Array64 _128; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array2.cs b/src/LibHac/Common/FixedArrays/Array2.cs index fcd67bd2..d2f27166 100644 --- a/src/LibHac/Common/FixedArrays/Array2.cs +++ b/src/LibHac/Common/FixedArrays/Array2.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -11,10 +12,10 @@ public struct Array2 private T _0; private T _1; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array2 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array20.cs b/src/LibHac/Common/FixedArrays/Array20.cs index 9d07fdfe..3b58eb24 100644 --- a/src/LibHac/Common/FixedArrays/Array20.cs +++ b/src/LibHac/Common/FixedArrays/Array20.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array20 private Array16 _0; private Array4 _16; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array2048.cs b/src/LibHac/Common/FixedArrays/Array2048.cs index 704c5957..77f762cc 100644 --- a/src/LibHac/Common/FixedArrays/Array2048.cs +++ b/src/LibHac/Common/FixedArrays/Array2048.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array2048 private Array1024 _0; private Array1024 _1024; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array24.cs b/src/LibHac/Common/FixedArrays/Array24.cs index 7df3e247..22eee51e 100644 --- a/src/LibHac/Common/FixedArrays/Array24.cs +++ b/src/LibHac/Common/FixedArrays/Array24.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array24 private Array16 _0; private Array8 _16; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array256.cs b/src/LibHac/Common/FixedArrays/Array256.cs index fbd9cddf..14a60957 100644 --- a/src/LibHac/Common/FixedArrays/Array256.cs +++ b/src/LibHac/Common/FixedArrays/Array256.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array256 private Array128 _0; private Array128 _128; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array26.cs b/src/LibHac/Common/FixedArrays/Array26.cs index 0d699aa2..f91d3982 100644 --- a/src/LibHac/Common/FixedArrays/Array26.cs +++ b/src/LibHac/Common/FixedArrays/Array26.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,14 +14,16 @@ public struct Array26 private Array8 _16; private Array2 _24; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array27.cs b/src/LibHac/Common/FixedArrays/Array27.cs index 3498a736..88d72eee 100644 --- a/src/LibHac/Common/FixedArrays/Array27.cs +++ b/src/LibHac/Common/FixedArrays/Array27.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -14,14 +15,16 @@ public struct Array27 private Array2 _24; private T _26; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array28.cs b/src/LibHac/Common/FixedArrays/Array28.cs index 2edb8d8c..76d44460 100644 --- a/src/LibHac/Common/FixedArrays/Array28.cs +++ b/src/LibHac/Common/FixedArrays/Array28.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,14 +14,16 @@ public struct Array28 private Array8 _16; private Array4 _24; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array3.cs b/src/LibHac/Common/FixedArrays/Array3.cs index 3a75362c..efab5fdf 100644 --- a/src/LibHac/Common/FixedArrays/Array3.cs +++ b/src/LibHac/Common/FixedArrays/Array3.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -12,10 +13,10 @@ public struct Array3 private T _1; private T _2; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array3 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array3000.cs b/src/LibHac/Common/FixedArrays/Array3000.cs index 63d99435..3f7dbc7f 100644 --- a/src/LibHac/Common/FixedArrays/Array3000.cs +++ b/src/LibHac/Common/FixedArrays/Array3000.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -15,14 +16,16 @@ public struct Array3000 private Array128 _2816; private Array56 _2944; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array32.cs b/src/LibHac/Common/FixedArrays/Array32.cs index 867c8baa..a59569b2 100644 --- a/src/LibHac/Common/FixedArrays/Array32.cs +++ b/src/LibHac/Common/FixedArrays/Array32.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array32 private Array16 _0; private Array16 _16; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array356.cs b/src/LibHac/Common/FixedArrays/Array356.cs index b8e392be..513107f0 100644 --- a/src/LibHac/Common/FixedArrays/Array356.cs +++ b/src/LibHac/Common/FixedArrays/Array356.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -14,14 +15,16 @@ public struct Array356 private Array32 _320; private Array4 _352; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array36.cs b/src/LibHac/Common/FixedArrays/Array36.cs index 1f4cf61b..3bcc8b72 100644 --- a/src/LibHac/Common/FixedArrays/Array36.cs +++ b/src/LibHac/Common/FixedArrays/Array36.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array36 private Array32 _0; private Array4 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array37.cs b/src/LibHac/Common/FixedArrays/Array37.cs index 7d2fba30..db7c5270 100644 --- a/src/LibHac/Common/FixedArrays/Array37.cs +++ b/src/LibHac/Common/FixedArrays/Array37.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array37 private Array32 _0; private Array5 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array38.cs b/src/LibHac/Common/FixedArrays/Array38.cs index 25be2f85..358ec291 100644 --- a/src/LibHac/Common/FixedArrays/Array38.cs +++ b/src/LibHac/Common/FixedArrays/Array38.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array38 private Array32 _0; private Array6 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array4.cs b/src/LibHac/Common/FixedArrays/Array4.cs index 2e15a502..9060b902 100644 --- a/src/LibHac/Common/FixedArrays/Array4.cs +++ b/src/LibHac/Common/FixedArrays/Array4.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -13,10 +14,10 @@ public struct Array4 private T _2; private T _3; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array4 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array400.cs b/src/LibHac/Common/FixedArrays/Array400.cs index 013bd114..29831cf3 100644 --- a/src/LibHac/Common/FixedArrays/Array400.cs +++ b/src/LibHac/Common/FixedArrays/Array400.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,14 +14,16 @@ public struct Array400 private Array128 _256; private Array16 _384; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array4096.cs b/src/LibHac/Common/FixedArrays/Array4096.cs index 5f2020cc..6743b875 100644 --- a/src/LibHac/Common/FixedArrays/Array4096.cs +++ b/src/LibHac/Common/FixedArrays/Array4096.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array4096 private Array2048 _0; private Array2048 _2048; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array452.cs b/src/LibHac/Common/FixedArrays/Array452.cs index 723f14a3..f43571fe 100644 --- a/src/LibHac/Common/FixedArrays/Array452.cs +++ b/src/LibHac/Common/FixedArrays/Array452.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -14,14 +15,16 @@ public struct Array452 private Array64 _384; private Array4 _448; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array464.cs b/src/LibHac/Common/FixedArrays/Array464.cs index beada3bf..ae31b74c 100644 --- a/src/LibHac/Common/FixedArrays/Array464.cs +++ b/src/LibHac/Common/FixedArrays/Array464.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -14,14 +15,16 @@ public struct Array464 private Array64 _384; private Array16 _448; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array48.cs b/src/LibHac/Common/FixedArrays/Array48.cs index b81e4ea3..2a72dc84 100644 --- a/src/LibHac/Common/FixedArrays/Array48.cs +++ b/src/LibHac/Common/FixedArrays/Array48.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array48 private Array32 _0; private Array16 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array5.cs b/src/LibHac/Common/FixedArrays/Array5.cs index 97928b7a..49aa4378 100644 --- a/src/LibHac/Common/FixedArrays/Array5.cs +++ b/src/LibHac/Common/FixedArrays/Array5.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -14,10 +15,10 @@ public struct Array5 private T _3; private T _4; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array5 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array512.cs b/src/LibHac/Common/FixedArrays/Array512.cs index 2caf57dc..04fdd0ff 100644 --- a/src/LibHac/Common/FixedArrays/Array512.cs +++ b/src/LibHac/Common/FixedArrays/Array512.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array512 private Array256 _0; private Array256 _256; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array56.cs b/src/LibHac/Common/FixedArrays/Array56.cs index fa94bbff..3b730c2d 100644 --- a/src/LibHac/Common/FixedArrays/Array56.cs +++ b/src/LibHac/Common/FixedArrays/Array56.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array56 private Array32 _0; private Array24 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array6.cs b/src/LibHac/Common/FixedArrays/Array6.cs index dff18fbc..8772c9df 100644 --- a/src/LibHac/Common/FixedArrays/Array6.cs +++ b/src/LibHac/Common/FixedArrays/Array6.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -15,10 +16,10 @@ public struct Array6 private T _4; private T _5; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array6 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array60.cs b/src/LibHac/Common/FixedArrays/Array60.cs index f66c3b4f..56051820 100644 --- a/src/LibHac/Common/FixedArrays/Array60.cs +++ b/src/LibHac/Common/FixedArrays/Array60.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,14 +14,16 @@ public struct Array60 private Array16 _32; private Array12 _48; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array64.cs b/src/LibHac/Common/FixedArrays/Array64.cs index a395eccd..439bca02 100644 --- a/src/LibHac/Common/FixedArrays/Array64.cs +++ b/src/LibHac/Common/FixedArrays/Array64.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array64 private Array32 _0; private Array32 _32; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array65.cs b/src/LibHac/Common/FixedArrays/Array65.cs index bdd5896d..069c60f5 100644 --- a/src/LibHac/Common/FixedArrays/Array65.cs +++ b/src/LibHac/Common/FixedArrays/Array65.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array65 private Array64 _0; private T _64; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array68.cs b/src/LibHac/Common/FixedArrays/Array68.cs index 2b4b9f43..e389f095 100644 --- a/src/LibHac/Common/FixedArrays/Array68.cs +++ b/src/LibHac/Common/FixedArrays/Array68.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array68 private Array64 _0; private Array4 _64; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array7.cs b/src/LibHac/Common/FixedArrays/Array7.cs index f87a13dc..90f8871e 100644 --- a/src/LibHac/Common/FixedArrays/Array7.cs +++ b/src/LibHac/Common/FixedArrays/Array7.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -16,10 +17,10 @@ public struct Array7 private T _5; private T _6; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array7 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array768.cs b/src/LibHac/Common/FixedArrays/Array768.cs index ded4c986..8f17fe3c 100644 --- a/src/LibHac/Common/FixedArrays/Array768.cs +++ b/src/LibHac/Common/FixedArrays/Array768.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array768 private Array512 _0; private Array256 _512; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array769.cs b/src/LibHac/Common/FixedArrays/Array769.cs index 0872ad7c..052db573 100644 --- a/src/LibHac/Common/FixedArrays/Array769.cs +++ b/src/LibHac/Common/FixedArrays/Array769.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,14 +14,16 @@ public struct Array769 private Array256 _512; private Array1 _768; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array8.cs b/src/LibHac/Common/FixedArrays/Array8.cs index d82bc02d..6b7b64b4 100644 --- a/src/LibHac/Common/FixedArrays/Array8.cs +++ b/src/LibHac/Common/FixedArrays/Array8.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace LibHac.Common.FixedArrays; @@ -17,10 +18,10 @@ public struct Array8 private T _6; private T _7; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; - public Span Items => SpanHelpers.CreateSpan(ref _0, Length); - public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); + [UnscopedRef] public Span Items => SpanHelpers.CreateSpan(ref _0, Length); + [UnscopedRef] public readonly ReadOnlySpan ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ReadOnlySpan(in Array8 value) => value.ItemsRo; diff --git a/src/LibHac/Common/FixedArrays/Array80.cs b/src/LibHac/Common/FixedArrays/Array80.cs index 7cb2c418..2aacc932 100644 --- a/src/LibHac/Common/FixedArrays/Array80.cs +++ b/src/LibHac/Common/FixedArrays/Array80.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array80 private Array64 _0; private Array16 _64; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array8192.cs b/src/LibHac/Common/FixedArrays/Array8192.cs index 92059b10..2669e3d9 100644 --- a/src/LibHac/Common/FixedArrays/Array8192.cs +++ b/src/LibHac/Common/FixedArrays/Array8192.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array8192 private Array4096 _0; private Array4096 _4096; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/FixedArrays/Array96.cs b/src/LibHac/Common/FixedArrays/Array96.cs index ca4fbad4..c388d00a 100644 --- a/src/LibHac/Common/FixedArrays/Array96.cs +++ b/src/LibHac/Common/FixedArrays/Array96.cs @@ -1,5 +1,6 @@ #pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,14 +13,16 @@ public struct Array96 private Array80 _0; private Array16 _80; - public ref T this[int i] => ref Items[i]; + [UnscopedRef] public ref T this[int i] => ref Items[i]; + [UnscopedRef] public Span Items { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length); } + [UnscopedRef] public readonly ReadOnlySpan ItemsRo { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Common/Id128.cs b/src/LibHac/Common/Id128.cs index 75a36e0f..9e92f73c 100644 --- a/src/LibHac/Common/Id128.cs +++ b/src/LibHac/Common/Id128.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Util; @@ -67,6 +68,7 @@ public struct Id128 : IEquatable, IComparable, IComparable longs[1] = Low; } + [UnscopedRef] public ReadOnlySpan AsBytes() { return SpanHelpers.AsByteSpan(ref this); diff --git a/src/LibHac/Common/InteropWin32.cs b/src/LibHac/Common/InteropWin32.cs index 7441f8d5..a294430d 100644 --- a/src/LibHac/Common/InteropWin32.cs +++ b/src/LibHac/Common/InteropWin32.cs @@ -57,7 +57,7 @@ public static unsafe class InteropWin32 public long LastWriteTime => (long)((ulong)_lastWriteHigh << 32 | _lastWriteLow); public long FileSize => (long)_fileSizeHigh << 32 | _fileSizeLow; - public Span FileName => MemoryMarshal.CreateSpan(ref _fileName[0], 260); - public Span AlternateFileName => MemoryMarshal.CreateSpan(ref _alternateFileName[0], 14); + public Span FileName => SpanHelpers.CreateSpan(ref _fileName[0], 260); + public Span AlternateFileName => SpanHelpers.CreateSpan(ref _alternateFileName[0], 14); } } \ No newline at end of file diff --git a/src/LibHac/Common/Key128.cs b/src/LibHac/Common/Key128.cs index f1171c2c..2587e988 100644 --- a/src/LibHac/Common/Key128.cs +++ b/src/LibHac/Common/Key128.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Util; @@ -10,7 +11,7 @@ public struct Key128 : IEquatable private readonly ulong _dummy1; private readonly ulong _dummy2; - public Span Value => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public Span Value => SpanHelpers.AsByteSpan(ref this); public Key128(ReadOnlySpan bytes) { diff --git a/src/LibHac/Common/Ref.cs b/src/LibHac/Common/Ref.cs index 3ad5eee7..2fc6368c 100644 --- a/src/LibHac/Common/Ref.cs +++ b/src/LibHac/Common/Ref.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace LibHac.Common; @@ -14,10 +12,7 @@ namespace LibHac.Common; /// The type of value to reference. public readonly ref struct Ref { - /// - /// The 1-length instance used to track the target value. - /// - private readonly Span _span; + private readonly ref T _ref; /// /// Initializes a new instance of the struct. @@ -26,7 +21,7 @@ public readonly ref struct Ref [MethodImpl(MethodImplOptions.AggressiveInlining)] public Ref(ref T value) { - _span = MemoryMarshal.CreateSpan(ref value, 1); + _ref = ref value; } /// @@ -40,11 +35,7 @@ public readonly ref struct Ref /// /// Gets the reference represented by the current instance. /// - public ref T Value - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref MemoryMarshal.GetReference(_span); - } + public ref T Value => ref _ref; /// /// Returns a value that indicates whether the current is . @@ -74,10 +65,7 @@ public readonly ref struct Ref /// The type of value to reference. public readonly ref struct ReadOnlyRef { - /// - /// The 1-length instance used to track the target value. - /// - private readonly ReadOnlySpan _span; + private readonly ref readonly T _ref; /// /// Initializes a new instance of the struct. @@ -86,7 +74,7 @@ public readonly ref struct ReadOnlyRef [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlyRef(in T value) { - _span = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in value), 1); + _ref = ref value; } /// @@ -103,7 +91,7 @@ public readonly ref struct ReadOnlyRef public ref readonly T Value { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref MemoryMarshal.GetReference(_span); + get => ref _ref; } /// diff --git a/src/LibHac/Common/SpanHelpers.cs b/src/LibHac/Common/SpanHelpers.cs index 49a93cd8..79d5a516 100644 --- a/src/LibHac/Common/SpanHelpers.cs +++ b/src/LibHac/Common/SpanHelpers.cs @@ -42,7 +42,7 @@ public static class SpanHelpers [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span AsSpan(ref T reference) where T : unmanaged { - return CreateSpan(ref reference, 1); + return new Span(ref reference); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -68,7 +68,7 @@ public static class SpanHelpers [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan AsReadOnlySpan(in T reference) where T : unmanaged { - return CreateReadOnlySpan(in reference, 1); + return new ReadOnlySpan(in reference); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Crypto/KeyTypes.cs b/src/LibHac/Crypto/KeyTypes.cs index 32c9817f..31a13fd1 100644 --- a/src/LibHac/Crypto/KeyTypes.cs +++ b/src/LibHac/Crypto/KeyTypes.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -16,10 +17,10 @@ public struct AesKey [FieldOffset(0)] private byte _byte; [FieldOffset(0)] private ulong _ulong; - public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); - public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); - public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); - public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); + [UnscopedRef] public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); + [UnscopedRef] public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); + [UnscopedRef] public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); + [UnscopedRef] public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0; @@ -31,7 +32,7 @@ public struct AesKey public readonly override string ToString() => DataRo.ToHexString(); #if DEBUG - [FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; + [FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; #endif } @@ -46,12 +47,12 @@ public struct AesXtsKey [FieldOffset(0)] public AesKey DataKey; [FieldOffset(0x10)] public AesKey TweakKey; - public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); - public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); - public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); - public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); + [UnscopedRef] public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); + [UnscopedRef] public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); + [UnscopedRef] public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); + [UnscopedRef] public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); - public Span SubKeys => SpanHelpers.CreateSpan(ref DataKey, Size / Unsafe.SizeOf()); + [UnscopedRef] public Span SubKeys => SpanHelpers.CreateSpan(ref DataKey, Size / Unsafe.SizeOf()); public static implicit operator Span(in AesXtsKey value) => Unsafe.AsRef(in value).Data; public static implicit operator ReadOnlySpan(in AesXtsKey value) => value.DataRo; @@ -70,10 +71,10 @@ public struct AesIv [FieldOffset(0)] private byte _byte; [FieldOffset(0)] private ulong _ulong; - public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); - public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); - public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); - public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); + [UnscopedRef] public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); + [UnscopedRef] public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); + [UnscopedRef] public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); + [UnscopedRef] public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0; @@ -84,7 +85,7 @@ public struct AesIv public readonly override string ToString() => DataRo.ToHexString(); #if DEBUG - [FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; + [FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; #endif } @@ -96,10 +97,10 @@ public struct AesCmac [FieldOffset(0)] private byte _byte; [FieldOffset(0)] private ulong _ulong; - public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); - public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); - public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); - public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); + [UnscopedRef] public Span Data => SpanHelpers.CreateSpan(ref _byte, Size); + [UnscopedRef] public readonly ReadOnlySpan DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size); + [UnscopedRef] public Span Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong)); + [UnscopedRef] public readonly ReadOnlySpan DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0; @@ -110,7 +111,7 @@ public struct AesCmac public readonly override string ToString() => DataRo.ToHexString(); #if DEBUG - [FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; + [FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; #endif } diff --git a/src/LibHac/Fs/AccessLog.cs b/src/LibHac/Fs/AccessLog.cs index 75c99441..c4809167 100644 --- a/src/LibHac/Fs/AccessLog.cs +++ b/src/LibHac/Fs/AccessLog.cs @@ -1,6 +1,7 @@ using System; using System.Buffers; using System.Buffers.Text; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; using System.Text.Unicode; @@ -163,6 +164,7 @@ namespace LibHac.Fs.Impl { private Buffer32 _buffer; + [UnscopedRef] private ReadOnlySpan ToValueString(int value) { bool success = Utf8Formatter.TryFormat(value, _buffer.Bytes, out int length); @@ -173,6 +175,7 @@ namespace LibHac.Fs.Impl return _buffer.Bytes; } + [UnscopedRef] public ReadOnlySpan ToString(Priority value) { switch (value) @@ -184,6 +187,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(PriorityRaw value) { switch (value) @@ -196,6 +200,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(ImageDirectoryId value) { switch (value) @@ -206,6 +211,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(ContentStorageId value) { switch (value) @@ -217,6 +223,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(GameCardPartition value) { switch (value) @@ -229,6 +236,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(SaveDataSpaceId value) { switch (value) @@ -241,6 +249,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(SaveDataFormatType value) { switch (value) @@ -251,6 +260,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(ContentType value) { switch (value) @@ -264,6 +274,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(BisPartitionId value) { switch (value) @@ -289,6 +300,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(DirectoryEntryType value) { switch (value) @@ -299,6 +311,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(MountHostOption value) { switch (value.Flags) @@ -308,6 +321,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(MemoryCapacity value) { switch (value) @@ -322,6 +336,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(SelSec value) { switch (value) @@ -332,6 +347,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(KekIndex value) { switch (value) @@ -342,6 +358,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(AccessControl1ClockRate value) { switch (value) @@ -352,6 +369,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(FwVersion value) { switch (value) @@ -366,6 +384,7 @@ namespace LibHac.Fs.Impl } } + [UnscopedRef] public ReadOnlySpan ToString(GameCardCompatibilityType value) { switch (value) diff --git a/src/LibHac/Fs/Common/DirectoryPathParser.cs b/src/LibHac/Fs/Common/DirectoryPathParser.cs index 9eedc20f..ab9a400e 100644 --- a/src/LibHac/Fs/Common/DirectoryPathParser.cs +++ b/src/LibHac/Fs/Common/DirectoryPathParser.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using LibHac.Common; using LibHac.Diag; using static LibHac.Fs.StringTraits; @@ -16,21 +17,19 @@ public ref struct DirectoryPathParser private Span _buffer; private byte _replacedChar; private int _position; - - // Todo: Make private so we can use the GetCurrentPath method once lifetime tracking is better - public Path CurrentPath; + private Path _currentPath; public DirectoryPathParser() { _buffer = Span.Empty; _replacedChar = 0; _position = 0; - CurrentPath = new Path(); + _currentPath = new Path(); } public void Dispose() { - CurrentPath.Dispose(); + _currentPath.Dispose(); } /// @@ -40,7 +39,7 @@ public ref struct DirectoryPathParser /// /// The to iterate. Must have an allocated write buffer. /// The of the operation. - public Result Initialize(ref Path path) + public Result Initialize(scoped ref Path path) { Span pathBuffer = path.GetWriteBufferLength() != 0 ? path.GetWriteBuffer() : Span.Empty; @@ -49,7 +48,7 @@ public ref struct DirectoryPathParser if (windowsSkipLength != 0) { - Result res = CurrentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1); + Result res = _currentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1); if (res.IsFailure()) return res.Miss(); _buffer = _buffer.Slice(1); @@ -60,7 +59,7 @@ public ref struct DirectoryPathParser if (!initialPath.IsEmpty) { - Result res = CurrentPath.InitializeWithNormalization(initialPath); + Result res = _currentPath.InitializeWithNormalization(initialPath); if (res.IsFailure()) return res.Miss(); } } @@ -68,11 +67,11 @@ public ref struct DirectoryPathParser return Result.Success; } - // Todo: Return reference when escape semantics are better - //public ref readonly Path GetCurrentPath() - //{ - // return ref CurrentPath; - //} + [UnscopedRef] + public ref readonly Path GetCurrentPath() + { + return ref _currentPath; + } public Result ReadNext(out bool isFinished) { @@ -86,7 +85,7 @@ public ref struct DirectoryPathParser return Result.Success; } - return CurrentPath.AppendChild(nextEntry); + return _currentPath.AppendChild(nextEntry); } private Span ReadNextImpl() diff --git a/src/LibHac/Fs/Common/Path.cs b/src/LibHac/Fs/Common/Path.cs index 97e37b12..353ffe8f 100644 --- a/src/LibHac/Fs/Common/Path.cs +++ b/src/LibHac/Fs/Common/Path.cs @@ -46,7 +46,7 @@ public static class PathExtensions /// The read-only reference to reinterpret. /// A reference to the given . // ReSharper disable once EntityNameCapturedOnly.Global - public static ref Path Ref(this in Path path) + public static ref Path Ref(this scoped in Path path) { Ldarg(nameof(path)); Ret(); @@ -122,7 +122,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Initialize(in Path path) + public Result Initialize(scoped in Path path) { if (!path._isNormalized) return ResultFs.NotNormalized.Log(); @@ -249,17 +249,17 @@ public ref struct Path /// The string to compare to this . /// The maximum number of characters to compare. /// if the strings are the same; otherwise . - public readonly bool IsMatchHead(ReadOnlySpan value, int length) + public readonly bool IsMatchHead(scoped ReadOnlySpan value, int length) { return StringUtils.Compare(GetString(), value, length) == 0; } - public static bool operator !=(in Path left, in Path right) + public static bool operator !=(scoped in Path left, scoped in Path right) { return !(left == right); } - public static bool operator !=(in Path left, ReadOnlySpan right) + public static bool operator !=(scoped in Path left, scoped ReadOnlySpan right) { return !(left == right); } @@ -397,7 +397,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Initialize(in Path other) + public Result Initialize(scoped in Path other) { if (!other._isNormalized) return ResultFs.NotNormalized.Log(); @@ -424,7 +424,7 @@ public ref struct Path /// because paths are always normalized upon initialization. /// The path used to initialize this . /// : The operation was successful. - public Result Initialize(in Stored other) + public Result Initialize(scoped in Stored other) { int otherLength = other.GetLength(); @@ -449,7 +449,7 @@ public ref struct Path /// The buffer containing the path to use. /// The length of the provided path. /// : The operation was successful. - private Result InitializeImpl(ReadOnlySpan path, int length) + private Result InitializeImpl(scoped ReadOnlySpan path, int length) { if (length == 0 || path.At(0) == NullTerminator) { @@ -476,7 +476,7 @@ public ref struct Path /// This function will always set the IsNormalized flag to . /// The buffer containing the path to use. /// : The operation was successful. - public Result Initialize(ReadOnlySpan path) + public Result Initialize(scoped ReadOnlySpan path) { Result res = InitializeImpl(path, StringUtils.GetLength(path)); if (res.IsFailure()) return res.Miss(); @@ -661,7 +661,7 @@ public ref struct Path /// /// The buffer containing the path to use. /// : The operation was successful. - public Result InitializeWithReplaceUnc(ReadOnlySpan path) + public Result InitializeWithReplaceUnc(scoped ReadOnlySpan path) { Result res = InitializeImpl(path, StringUtils.GetLength(path)); if (res.IsFailure()) return res.Miss(); @@ -720,7 +720,7 @@ public ref struct Path /// The buffer containing the path to insert. /// : The operation was successful.
/// : The path provided in is a Windows path.
- public Result InsertParent(ReadOnlySpan parent) + public Result InsertParent(scoped ReadOnlySpan parent) { if (parent.Length == 0 || parent[0] == NullTerminator) return Result.Success; @@ -832,7 +832,7 @@ public ref struct Path /// The to insert. /// : The operation was successful.
/// : The path provided in is a Windows path.
- public Result InsertParent(in Path parent) + public Result InsertParent(scoped in Path parent) { return InsertParent(parent.GetString()); } @@ -845,7 +845,7 @@ public ref struct Path /// path is not normalized yet the IsNormalized flag is still . /// The buffer containing the child path to append to the current path. /// : The operation was successful. - public Result AppendChild(ReadOnlySpan child) + public Result AppendChild(scoped ReadOnlySpan child) { ReadOnlySpan trimmedChild = child; @@ -925,7 +925,7 @@ public ref struct Path /// path is not normalized yet the IsNormalized flag is still . /// The child to append to the current path. /// : The operation was successful. - public Result AppendChild(in Path child) + public Result AppendChild(scoped in Path child) { return AppendChild(child.GetString()); } @@ -941,7 +941,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of either /// or is not .
- public Result Combine(in Path path1, in Path path2) + public Result Combine(scoped in Path path1, scoped in Path path2) { int path1Length = path1.GetLength(); int path2Length = path2.GetLength(); @@ -977,7 +977,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Combine(in Path path1, ReadOnlySpan path2) + public Result Combine(scoped in Path path1, scoped ReadOnlySpan path2) { int path1Length = path1.GetLength(); int path2Length = StringUtils.GetLength(path2); @@ -1002,7 +1002,7 @@ public ref struct Path /// The first path to combine. /// The second path to combine. /// : The operation was successful. - public Result Combine(ReadOnlySpan path1, in Path path2) + public Result Combine(scoped ReadOnlySpan path1, scoped in Path path2) { int path1Length = StringUtils.GetLength(path1); int path2Length = path2.GetLength(); @@ -1167,7 +1167,7 @@ public static class PathFunctions /// : The operation was successful.
/// : The path contains an invalid character.
/// : The path is in an invalid format or is not normalized.
- public static Result SetUpFixedPath(ref Path path, ReadOnlySpan pathBuffer) + public static Result SetUpFixedPath(scoped ref Path path, ReadOnlySpan pathBuffer) { Result res = PathNormalizer.IsNormalized(out bool isNormalized, out _, pathBuffer); if (res.IsFailure()) return res.Miss(); @@ -1192,7 +1192,7 @@ public static class PathFunctions /// The first entry in the generated path. /// : The operation was successful.
/// : was too small to contain the built path.
- internal static Result SetUpFixedPathSingleEntry(ref Path path, Span pathBuffer, + internal static Result SetUpFixedPathSingleEntry(scoped ref Path path, Span pathBuffer, ReadOnlySpan entryName) { var sb = new U8StringBuilder(pathBuffer); @@ -1214,8 +1214,8 @@ public static class PathFunctions /// The second entry in the generated path. /// : The operation was successful.
/// : was too small to contain the built path.
- internal static Result SetUpFixedPathDoubleEntry(ref Path path, Span pathBuffer, - ReadOnlySpan entryName1, ReadOnlySpan entryName2) + internal static Result SetUpFixedPathDoubleEntry(scoped ref Path path, Span pathBuffer, + scoped ReadOnlySpan entryName1, scoped ReadOnlySpan entryName2) { var sb = new U8StringBuilder(pathBuffer); sb.Append((byte)'/').Append(entryName1) @@ -1236,7 +1236,7 @@ public static class PathFunctions /// The save data ID to insert into the path. /// : The operation was successful.
/// : was too small to contain the built path.
- internal static Result SetUpFixedPathSaveId(ref Path path, Span pathBuffer, ulong saveDataId) + internal static Result SetUpFixedPathSaveId(scoped ref Path path, Span pathBuffer, ulong saveDataId) { var sb = new U8StringBuilder(pathBuffer); sb.Append((byte)'/').AppendFormat(saveDataId, 'x', 16); @@ -1256,7 +1256,7 @@ public static class PathFunctions /// The to insert into the path. /// : The operation was successful.
/// : was too small to contain the built path.
- internal static Result SetUpFixedPathSaveMetaName(ref Path path, Span pathBuffer, uint metaType) + internal static Result SetUpFixedPathSaveMetaName(scoped ref Path path, Span pathBuffer, uint metaType) { ReadOnlySpan metaExtension = new[] { (byte)'.', (byte)'m', (byte)'e', (byte)'t', (byte)'a' }; // ".meta" @@ -1278,7 +1278,7 @@ public static class PathFunctions /// The save data ID to insert into the path. /// : The operation was successful.
/// : was too small to contain the built path.
- internal static Result SetUpFixedPathSaveMetaDir(ref Path path, Span pathBuffer, ulong saveDataId) + internal static Result SetUpFixedPathSaveMetaDir(scoped ref Path path, Span pathBuffer, ulong saveDataId) { ReadOnlySpan metaDirectoryName = new[] { diff --git a/src/LibHac/Fs/Common/SaveDataTypes.cs b/src/LibHac/Fs/Common/SaveDataTypes.cs index e7f98453..22b82032 100644 --- a/src/LibHac/Fs/Common/SaveDataTypes.cs +++ b/src/LibHac/Fs/Common/SaveDataTypes.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using LibHac.Common; using LibHac.Common.FixedArrays; using LibHac.FsSrv.Impl; @@ -122,8 +123,8 @@ public struct HashSalt { private Array32 _value; - public Span Hash => _value.Items; - public readonly ReadOnlySpan HashRo => _value.ItemsRo; + [UnscopedRef] public Span Hash => _value.Items; + [UnscopedRef] public readonly ReadOnlySpan HashRo => _value.ItemsRo; } public struct SaveDataAttribute : IEquatable, IComparable diff --git a/src/LibHac/Fs/MountName.cs b/src/LibHac/Fs/MountName.cs index 152dfb41..cfd37d93 100644 --- a/src/LibHac/Fs/MountName.cs +++ b/src/LibHac/Fs/MountName.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using LibHac.Common; using LibHac.Common.FixedArrays; @@ -7,7 +8,7 @@ namespace LibHac.Fs; internal struct MountName { private Array16 _nameArray; - public Span Name => _nameArray.Items; + [UnscopedRef] public Span Name => _nameArray.Items; public override string ToString() => new U8Span(Name).ToString(); } \ No newline at end of file diff --git a/src/LibHac/Fs/UserId.cs b/src/LibHac/Fs/UserId.cs index 42bc16d0..616d59db 100644 --- a/src/LibHac/Fs/UserId.cs +++ b/src/LibHac/Fs/UserId.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; @@ -43,6 +44,7 @@ public struct UserId : IEquatable, IComparable, IComparable public void ToBytes(Span output) => Id.ToBytes(output); + [UnscopedRef] public ReadOnlySpan AsBytes() { return SpanHelpers.AsByteSpan(ref this); diff --git a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs index cff1f5c4..a3e79290 100644 --- a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs @@ -40,7 +40,7 @@ public class FileSystemProxyCoreImpl Result res = _baseFileSystemService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User); if (res.IsFailure()) return res.Miss(); - using var path = new Path(); + using scoped var path = new Path(); res = PathFunctions.SetUpFixedPathSingleEntry(ref path.Ref(), pathBuffer.Items, CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System)); if (res.IsFailure()) return res.Miss(); @@ -54,7 +54,7 @@ public class FileSystemProxyCoreImpl Result res = _baseFileSystemService.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); if (res.IsFailure()) return res.Miss(); - using var path = new Path(); + using scoped var path = new Path(); res = PathFunctions.SetUpFixedPathDoubleEntry(ref path.Ref(), pathBuffer.Items, CommonPaths.SdCardNintendoRootDirectoryName, CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System)); diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs index 9dbd7f5e..0f869cc9 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs @@ -46,7 +46,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator { Unsafe.SkipInit(out Array18 saveImageNameBuffer); - using var saveImageName = new Path(); + using scoped var saveImageName = new Path(); Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 002416aa..4f31102f 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -127,7 +127,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable // Get the path of the save data Unsafe.SkipInit(out Array18 saveImageNameBuffer); - using var saveImageName = new Path(); + using scoped var saveImageName = new Path(); res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -169,7 +169,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable { // Create the save data directory on the host if needed. Unsafe.SkipInit(out Array18 saveDirectoryNameBuffer); - using var saveDirectoryName = new Path(); + using scoped var saveDirectoryName = new Path(); res = PathFunctions.SetUpFixedPathSaveId(ref saveDirectoryName.Ref(), saveDirectoryNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -232,7 +232,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable { Unsafe.SkipInit(out Array27 saveDataMetaIdDirectoryNameBuffer); - using var saveDataMetaIdDirectoryName = new Path(); + using scoped var saveDataMetaIdDirectoryName = new Path(); Result res = PathFunctions.SetUpFixedPathSaveMetaDir(ref saveDataMetaIdDirectoryName.Ref(), saveDataMetaIdDirectoryNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -313,7 +313,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); - using var saveDataMetaName = new Path(); + using scoped var saveDataMetaName = new Path(); res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); if (res.IsFailure()) return res.Miss(); @@ -333,7 +333,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); - using var saveDataMetaName = new Path(); + using scoped var saveDataMetaName = new Path(); res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); if (res.IsFailure()) return res.Miss(); @@ -357,7 +357,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var fileSystem = new SharedRef(); - using var saveDataMetaDirectoryName = new Path(); + using scoped var saveDataMetaDirectoryName = new Path(); Result res = PathFunctions.SetUpFixedPath(ref saveDataMetaDirectoryName.Ref(), metaDirName); if (res.IsFailure()) return res.Miss(); @@ -365,7 +365,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable createIfMissing: false); if (res.IsFailure()) return res.Miss(); - using var saveDataIdDirectoryName = new Path(); + using scoped var saveDataIdDirectoryName = new Path(); PathFunctions.SetUpFixedPathSaveId(ref saveDataIdDirectoryName.Ref(), saveDataIdDirectoryNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -394,7 +394,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); - using var saveDataMetaName = new Path(); + using scoped var saveDataMetaName = new Path(); res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); if (res.IsFailure()) return res.Miss(); @@ -422,7 +422,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable allowEmulatedSave: false); if (res.IsFailure()) return res.Miss(); - using var saveImageName = new Path(); + using scoped var saveImageName = new Path(); res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -494,7 +494,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, false); if (res.IsFailure()) return res.Miss(); - using var saveImageName = new Path(); + using scoped var saveImageName = new Path(); res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); @@ -648,7 +648,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable public Result OpenSaveDataDirectoryFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId) { - using var rootPath = new Path(); + using scoped var rootPath = new Path(); return OpenSaveDataDirectoryFileSystem(ref outFileSystem, spaceId, in rootPath, allowEmulatedSave: true); } @@ -671,7 +671,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable if (res.IsFailure()) return res.Miss(); } - using var path = new Path(); + using scoped var path = new Path(); res = path.Initialize(in saveDataRootPath); if (res.IsFailure()) return res.Miss(); @@ -692,7 +692,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable return Result.Success; } - using var saveDataAreaDirectoryName = new Path(); + using scoped var saveDataAreaDirectoryName = new Path(); ReadOnlySpan saveDirName; if (spaceId == SaveDataSpaceId.Temporary) @@ -762,12 +762,12 @@ public class SaveDataFileSystemServiceImpl : IDisposable Unsafe.SkipInit(out Array64 pathParentBuffer); - using var pathParent = new Path(); + using scoped var pathParent = new Path(); res = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer.Items, CommonPaths.SdCardNintendoRootDirectoryName); if (res.IsFailure()) return res.Miss(); - using var pathSdRoot = new Path(); + using scoped var pathSdRoot = new Path(); res = pathSdRoot.Combine(in pathParent, in directoryPath); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs index 918d29b4..98d30464 100644 --- a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs +++ b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs @@ -336,7 +336,7 @@ public class SaveDataFileStorageHolder { Unsafe.SkipInit(out Array18 saveImageNameBuffer); - using var saveImageName = new Path(); + using scoped var saveImageName = new Path(); Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/Sf/FspPath.cs b/src/LibHac/FsSrv/Sf/FspPath.cs index 37e1c8ff..16d05788 100644 --- a/src/LibHac/FsSrv/Sf/FspPath.cs +++ b/src/LibHac/FsSrv/Sf/FspPath.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -15,7 +16,7 @@ public readonly struct FspPath private readonly Array769 _value; - public ReadOnlySpan Str => SpanHelpers.AsReadOnlyByteSpan(in _value); + [UnscopedRef] public ReadOnlySpan Str => SpanHelpers.AsReadOnlyByteSpan(in _value); public static Result FromSpan(out FspPath fspPath, ReadOnlySpan path) { diff --git a/src/LibHac/FsSrv/Sf/Path.cs b/src/LibHac/FsSrv/Sf/Path.cs index 111ed9e4..2f4504a6 100644 --- a/src/LibHac/FsSrv/Sf/Path.cs +++ b/src/LibHac/FsSrv/Sf/Path.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Common.FixedArrays; @@ -10,5 +11,5 @@ public readonly struct Path { private readonly Array769 _value; - public ReadOnlySpan Str => SpanHelpers.AsReadOnlyByteSpan(in _value); + [UnscopedRef] public ReadOnlySpan Str => SpanHelpers.AsReadOnlyByteSpan(in _value); } \ No newline at end of file diff --git a/src/LibHac/FsSystem/AesCtrStorage.cs b/src/LibHac/FsSystem/AesCtrStorage.cs index 595cb0a7..500a937b 100644 --- a/src/LibHac/FsSystem/AesCtrStorage.cs +++ b/src/LibHac/FsSystem/AesCtrStorage.cs @@ -133,7 +133,7 @@ public class AesCtrStorage : IStorage int writeSize = useWorkBuffer ? Math.Max(pooledBuffer.GetSize(), remaining) : remaining; Span writeBuffer = useWorkBuffer ? pooledBuffer.GetBuffer().Slice(0, writeSize) - : MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(source), source.Length).Slice(0, writeSize); + : SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(source), source.Length).Slice(0, writeSize); // Encrypt the data, with temporarily increased priority. using (new ScopedThreadPriorityChanger(1, ScopedThreadPriorityChanger.Mode.Relative)) diff --git a/src/LibHac/FsSystem/AesXtsStorageExternal.cs b/src/LibHac/FsSystem/AesXtsStorageExternal.cs index 8d94605f..23270f36 100644 --- a/src/LibHac/FsSystem/AesXtsStorageExternal.cs +++ b/src/LibHac/FsSystem/AesXtsStorageExternal.cs @@ -235,7 +235,7 @@ public class AesXtsStorageExternal : IStorage // const_cast the input buffer and encrypt in-place if it's a "device buffer". Span encryptDest = useWorkBuffer ? pooledBuffer.GetBuffer().Slice(encryptOffset, currentSize) - : MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(encryptSource), encryptSource.Length); + : SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(encryptSource), encryptSource.Length); res = _encryptFunction(encryptDest, _key[0], _key[1], counter, encryptSource); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index a38b2b1b..b084370c 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -192,7 +192,7 @@ internal static class Utility } public static Result CopyDirectoryRecursively(IFileSystem destinationFileSystem, IFileSystem sourceFileSystem, - in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) + in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) { static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { @@ -235,7 +235,7 @@ internal static class Utility } public static Result CopyDirectoryRecursively(IFileSystem fileSystem, in Path destinationPath, - in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) + in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) { var closure = new FsIterationTaskClosure(); closure.Buffer = workBuffer; @@ -333,7 +333,7 @@ internal static class Utility do { // Check if the path exists - res = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.CurrentPath); + res = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.GetCurrentPath()); if (!res.IsSuccess()) { // Something went wrong if we get a result other than PathNotFound @@ -341,12 +341,12 @@ internal static class Utility return res; // Create the directory - res = fileSystem.CreateDirectory(in parser.CurrentPath); + res = fileSystem.CreateDirectory(in parser.GetCurrentPath()); if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res)) return res; // Check once more if the path exists - res = fileSystem.GetEntryType(out type, in parser.CurrentPath); + res = fileSystem.GetEntryType(out type, in parser.GetCurrentPath()); if (res.IsFailure()) return res.Miss(); } diff --git a/src/LibHac/Kernel/KipHeader.cs b/src/LibHac/Kernel/KipHeader.cs index a2a413b9..70e93560 100644 --- a/src/LibHac/Kernel/KipHeader.cs +++ b/src/LibHac/Kernel/KipHeader.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -50,8 +51,9 @@ public struct KipHeader public Array32 Capabilities; + [UnscopedRef] public Span Segments => - SpanHelpers.CreateSpan(ref Unsafe.As(ref TextMemoryOffset), SegmentCount); + SpanHelpers.CreateSpan(ref Unsafe.As(ref TextMemoryOffset), SegmentCount); public bool IsValid => Magic == Kip1Magic; diff --git a/src/LibHac/Kvdb/BoundedString.cs b/src/LibHac/Kvdb/BoundedString.cs index d48afe6c..893f7c16 100644 --- a/src/LibHac/Kvdb/BoundedString.cs +++ b/src/LibHac/Kvdb/BoundedString.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -10,7 +11,7 @@ public struct BoundedString where TSize : unmanaged { private TSize _string; - public Span Get() => SpanHelpers.AsByteSpan(ref _string); + [UnscopedRef] public Span Get() => SpanHelpers.AsByteSpan(ref _string); public int GetLength() => StringUtils.GetLength(SpanHelpers.AsReadOnlyByteSpan(in _string), Unsafe.SizeOf()); diff --git a/src/LibHac/Kvdb/KeyValueArchive.cs b/src/LibHac/Kvdb/KeyValueArchive.cs index 936740fb..97844bcb 100644 --- a/src/LibHac/Kvdb/KeyValueArchive.cs +++ b/src/LibHac/Kvdb/KeyValueArchive.cs @@ -109,7 +109,7 @@ internal ref struct KeyValueArchiveBufferReader return Result.Success; } - public Result ReadKeyValue(Span keyBuffer, Span valueBuffer) + public Result ReadKeyValue(scoped Span keyBuffer, scoped Span valueBuffer) { // This should only be called after ReadEntryCount. Assert.SdkNotEqual(_offset, 0); @@ -136,7 +136,7 @@ internal ref struct KeyValueArchiveBufferReader return Result.Success; } - private Result Peek(Span destBuffer) + private Result Peek(scoped Span destBuffer) { // Bounds check. if (_offset + destBuffer.Length > _buffer.Length || @@ -149,7 +149,7 @@ internal ref struct KeyValueArchiveBufferReader return Result.Success; } - private Result Read(Span destBuffer) + private Result Read(scoped Span destBuffer) { Result res = Peek(destBuffer); if (res.IsFailure()) return res.Miss(); @@ -170,7 +170,7 @@ internal ref struct KeyValueArchiveBufferWriter _offset = 0; } - private void Write(ReadOnlySpan source) + private void Write(scoped ReadOnlySpan source) { // Bounds check. Abort.DoAbortUnless(_offset + source.Length <= _buffer.Length && @@ -189,7 +189,7 @@ internal ref struct KeyValueArchiveBufferWriter Write(SpanHelpers.AsByteSpan(ref header)); } - public void WriteEntry(ReadOnlySpan key, ReadOnlySpan value) + public void WriteEntry(scoped ReadOnlySpan key, scoped ReadOnlySpan value) { // This should only be called after writing header. Assert.SdkNotEqual(_offset, 0); diff --git a/src/LibHac/LibHac.csproj b/src/LibHac/LibHac.csproj index e7df0d52..3edda82e 100644 --- a/src/LibHac/LibHac.csproj +++ b/src/LibHac/LibHac.csproj @@ -3,7 +3,7 @@ Library 0.17.0 - net6.0 + net7.0 true diff --git a/src/LibHac/Loader/MetaLoader.cs b/src/LibHac/Loader/MetaLoader.cs index b2998d18..a13d70ae 100644 --- a/src/LibHac/Loader/MetaLoader.cs +++ b/src/LibHac/Loader/MetaLoader.cs @@ -67,7 +67,7 @@ public class MetaLoader return ResultLoader.InvalidMeta.Log(); } - npdm = GetNpdmFromBufferUnsafe(ref MemoryMarshal.GetArrayDataReference(_npdmBuffer)); + npdm = GetNpdmFromBufferUnsafe(_npdmBuffer); return Result.Success; } @@ -98,9 +98,9 @@ public class MetaLoader if (res.IsFailure()) return res.Miss(); // Set Npdm members. - npdm.Meta = new ReadOnlyRef(in meta); - npdm.Acid = new ReadOnlyRef(in acid); - npdm.Aci = new ReadOnlyRef(in aci); + npdm.Meta = ref meta; + npdm.Acid = ref acid; + npdm.Aci = ref aci; npdm.FsAccessControlDescriptor = acidBuffer.Slice(acid.FsAccessControlOffset, acid.FsAccessControlSize); npdm.ServiceAccessControlDescriptor = acidBuffer.Slice(acid.ServiceAccessControlOffset, acid.ServiceAccessControlSize); @@ -113,8 +113,10 @@ public class MetaLoader return Result.Success; } - private static Npdm GetNpdmFromBufferUnsafe(ref byte npdmBuffer) + private static Npdm GetNpdmFromBufferUnsafe(ReadOnlySpan npdmSpan) { + ref byte npdmBuffer = ref MemoryMarshal.GetReference(npdmSpan); + var npdm = new Npdm(); ref Meta meta = ref Unsafe.As(ref npdmBuffer); @@ -122,17 +124,17 @@ public class MetaLoader ref AciHeader aci = ref Unsafe.As(ref Unsafe.Add(ref npdmBuffer, meta.AciOffset)); // Set Npdm members. - npdm.Meta = new ReadOnlyRef(in meta); - npdm.Acid = new ReadOnlyRef(in acid); - npdm.Aci = new ReadOnlyRef(in aci); + npdm.Meta = ref meta; + npdm.Acid = ref acid; + npdm.Aci = ref aci; - npdm.FsAccessControlDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref acid), acid.FsAccessControlOffset), acid.FsAccessControlSize); - npdm.ServiceAccessControlDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref acid), acid.ServiceAccessControlOffset), acid.ServiceAccessControlSize); - npdm.KernelCapabilityDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref acid), acid.KernelCapabilityOffset), acid.KernelCapabilitySize); + npdm.FsAccessControlDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref acid), acid.FsAccessControlOffset), acid.FsAccessControlSize); + npdm.ServiceAccessControlDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref acid), acid.ServiceAccessControlOffset), acid.ServiceAccessControlSize); + npdm.KernelCapabilityDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref acid), acid.KernelCapabilityOffset), acid.KernelCapabilitySize); - npdm.FsAccessControlData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref aci), aci.FsAccessControlOffset), aci.FsAccessControlSize); - npdm.ServiceAccessControlData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref aci), aci.ServiceAccessControlOffset), aci.ServiceAccessControlSize); - npdm.KernelCapabilityData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As(ref aci), aci.KernelCapabilityOffset), aci.KernelCapabilitySize); + npdm.FsAccessControlData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref aci), aci.FsAccessControlOffset), aci.FsAccessControlSize); + npdm.ServiceAccessControlData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref aci), aci.ServiceAccessControlOffset), aci.ServiceAccessControlSize); + npdm.KernelCapabilityData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As(ref aci), aci.KernelCapabilityOffset), aci.KernelCapabilitySize); return npdm; } diff --git a/src/LibHac/Loader/NsoHeader.cs b/src/LibHac/Loader/NsoHeader.cs index 4529b86b..5bbc3810 100644 --- a/src/LibHac/Loader/NsoHeader.cs +++ b/src/LibHac/Loader/NsoHeader.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -53,12 +54,13 @@ public struct NsoHeader public Array32 RoHash; public Array32 DataHash; + [UnscopedRef] public Span Segments => SpanHelpers.CreateSpan(ref Unsafe.As(ref TextFileOffset), SegmentCount); - public Span CompressedSizes => SpanHelpers.CreateSpan(ref TextFileSize, SegmentCount); + [UnscopedRef] public Span CompressedSizes => SpanHelpers.CreateSpan(ref TextFileSize, SegmentCount); - public Span> SegmentHashes => SpanHelpers.CreateSpan(ref TextHash, SegmentCount); + [UnscopedRef] public Span> SegmentHashes => SpanHelpers.CreateSpan(ref TextHash, SegmentCount); [Flags] public enum Flag diff --git a/src/LibHac/Loader/Types.cs b/src/LibHac/Loader/Types.cs index a48a41e7..c5c0998c 100644 --- a/src/LibHac/Loader/Types.cs +++ b/src/LibHac/Loader/Types.cs @@ -1,5 +1,4 @@ using System; -using LibHac.Common; using LibHac.Common.FixedArrays; using LibHac.Ncm; @@ -9,9 +8,9 @@ namespace LibHac.Loader; public ref struct Npdm { - public ReadOnlyRef Meta; - public ReadOnlyRef Acid; - public ReadOnlyRef Aci; + public ref readonly Meta Meta; + public ref readonly AcidHeaderData Acid; + public ref readonly AciHeader Aci; public ReadOnlySpan FsAccessControlDescriptor; public ReadOnlySpan ServiceAccessControlDescriptor; diff --git a/src/LibHac/Ncm/ContentId.cs b/src/LibHac/Ncm/ContentId.cs index f2a03564..eaf7c156 100644 --- a/src/LibHac/Ncm/ContentId.cs +++ b/src/LibHac/Ncm/ContentId.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; @@ -36,6 +37,7 @@ public struct ContentId : IEquatable, IComparable, ICompar public void ToBytes(Span output) => Id.ToBytes(output); + [UnscopedRef] public ReadOnlySpan AsBytes() { return SpanHelpers.AsByteSpan(ref this); diff --git a/src/LibHac/Ncm/PlaceHolderId.cs b/src/LibHac/Ncm/PlaceHolderId.cs index 0a49f4c6..6ad33f2a 100644 --- a/src/LibHac/Ncm/PlaceHolderId.cs +++ b/src/LibHac/Ncm/PlaceHolderId.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; @@ -36,6 +37,7 @@ public struct PlaceHolderId : IEquatable, IComparable output) => Id.ToBytes(output); + [UnscopedRef] public ReadOnlySpan AsBytes() { return SpanHelpers.AsByteSpan(ref this); diff --git a/src/LibHac/Ns/ApplicationControlProperty.cs b/src/LibHac/Ns/ApplicationControlProperty.cs index d1de76d8..075e4f14 100644 --- a/src/LibHac/Ns/ApplicationControlProperty.cs +++ b/src/LibHac/Ns/ApplicationControlProperty.cs @@ -71,18 +71,18 @@ public struct ApplicationControlProperty public AccessibleLaunchRequiredVersionValue AccessibleLaunchRequiredVersion; public Array3000 Reserved3448; - public readonly U8Span IsbnString => new U8Span(Isbn.ItemsRo); - public readonly U8Span DisplayVersionString => new U8Span(DisplayVersion.ItemsRo); - public readonly U8Span ApplicationErrorCodeCategoryString => new U8Span(ApplicationErrorCodeCategory.ItemsRo); - public readonly U8Span BcatPassphraseString => new U8Span(BcatPassphrase.ItemsRo); + [UnscopedRef] public readonly U8Span IsbnString => new U8Span(Isbn.ItemsRo); + [UnscopedRef] public readonly U8Span DisplayVersionString => new U8Span(DisplayVersion.ItemsRo); + [UnscopedRef] public readonly U8Span ApplicationErrorCodeCategoryString => new U8Span(ApplicationErrorCodeCategory.ItemsRo); + [UnscopedRef] public readonly U8Span BcatPassphraseString => new U8Span(BcatPassphrase.ItemsRo); public struct ApplicationTitle { public Array512 Name; public Array256 Publisher; - public readonly U8Span NameString => new U8Span(Name.ItemsRo); - public readonly U8Span PublisherString => new U8Span(Publisher.ItemsRo); + [UnscopedRef] public readonly U8Span NameString => new U8Span(Name.ItemsRo); + [UnscopedRef] public readonly U8Span PublisherString => new U8Span(Publisher.ItemsRo); } public struct ApplicationNeighborDetectionClientConfiguration diff --git a/src/LibHac/Spl/AccessKey.cs b/src/LibHac/Spl/AccessKey.cs index 33586fd1..6cb7a009 100644 --- a/src/LibHac/Spl/AccessKey.cs +++ b/src/LibHac/Spl/AccessKey.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using LibHac.Common; @@ -9,7 +10,7 @@ public struct AccessKey : IEquatable { private readonly Key128 Key; - public ReadOnlySpan Value => SpanHelpers.AsByteSpan(ref this); + [UnscopedRef] public ReadOnlySpan Value => SpanHelpers.AsByteSpan(ref this); public AccessKey(ReadOnlySpan bytes) { diff --git a/src/LibHac/Util/CharacterEncoding.cs b/src/LibHac/Util/CharacterEncoding.cs index 2ef245bd..45ac4f28 100644 --- a/src/LibHac/Util/CharacterEncoding.cs +++ b/src/LibHac/Util/CharacterEncoding.cs @@ -1016,8 +1016,8 @@ public static class CharacterEncoding return CharacterEncodingResult.Success; } - public static CharacterEncodingResult PickOutCharacterFromUtf8String(Span destinationChar, - ref ReadOnlySpan source) + public static CharacterEncodingResult PickOutCharacterFromUtf8String(scoped Span destinationChar, + scoped ref ReadOnlySpan source) { Assert.SdkRequires(destinationChar.Length >= 4); Assert.SdkRequires(source.Length >= 1); diff --git a/src/LibHac/Util/Optional.cs b/src/LibHac/Util/Optional.cs index 6b825809..14f6a633 100644 --- a/src/LibHac/Util/Optional.cs +++ b/src/LibHac/Util/Optional.cs @@ -1,6 +1,5 @@ -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using LibHac.Common; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using LibHac.Diag; namespace LibHac.Util; @@ -14,20 +13,21 @@ public struct Optional public ref T Value { + [UnscopedRef] get { Assert.SdkRequires(_hasValue); - // It's beautiful, working around C# rules - return ref MemoryMarshal.GetReference(SpanHelpers.CreateSpan(ref _value, 1)); + return ref _value; } } public readonly ref readonly T ValueRo { + [UnscopedRef] get { Assert.SdkRequires(_hasValue); - return ref MemoryMarshal.GetReference(SpanHelpers.CreateReadOnlySpan(in _value, 1)); + return ref _value; } } diff --git a/src/hactoolnet/hactoolnet.csproj b/src/hactoolnet/hactoolnet.csproj index d6b4f3eb..dc1c9048 100644 --- a/src/hactoolnet/hactoolnet.csproj +++ b/src/hactoolnet/hactoolnet.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 @@ -23,10 +23,9 @@ - - - - + + true + true diff --git a/tests/LibHac.Tests/LibHac.Tests.csproj b/tests/LibHac.Tests/LibHac.Tests.csproj index a1f42e66..c8f2a861 100644 --- a/tests/LibHac.Tests/LibHac.Tests.csproj +++ b/tests/LibHac.Tests/LibHac.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 true false