diff options
author | vnugent <public@vaughnnugent.com> | 2024-03-10 16:03:08 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-03-10 16:03:08 -0400 |
commit | dd0f384ec3b2fd86ec03aa0fb42387091b5430a7 (patch) | |
tree | 23f6e1c99fe2c0d1c0c12b0a40dba2d7f35e90c6 /lib/Utils | |
parent | b679ddd4e647ac915febd0d5a5e488a1e8e48842 (diff) |
Squashed commit of the following:
commit df1fed9e668d9e629354b209fd9dba18301db5d7
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 10 16:01:29 2024 -0400
refactor: primary constructor for HttpRequest
commit 795e7d307b5aa90321f9867d3b6b2630e3d8f29b
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 9 16:30:43 2024 -0500
package updates
commit c826c9f99d9ccd43e056bc7b7283146868733e85
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 9 14:58:58 2024 -0500
feat: Some docs, and updated clr string erasure functionality
commit cefe2c38d9093bff553aa46c2fcf08380c6e2aed
Author: vnugent <public@vaughnnugent.com>
Date: Wed Mar 6 21:37:59 2024 -0500
chore: removed bad oauth token function, abstracted HttpServer
commit d2ef0e78b27c68fb83d183d50beeeb7a5ba7cba8
Author: vnugent <public@vaughnnugent.com>
Date: Wed Mar 6 19:49:55 2024 -0500
chore: pluginbase logging, consitent proj files, some outdated readmes
commit b7537cd283431f684b16d3008d3b45f8b063d489
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 2 15:12:48 2024 -0500
feat: session handle, endpoints, and helper functions
Diffstat (limited to 'lib/Utils')
-rw-r--r-- | lib/Utils/src/IO/VnMemoryStream.cs | 3 | ||||
-rw-r--r-- | lib/Utils/src/Memory/MemoryUtil.cs | 21 | ||||
-rw-r--r-- | lib/Utils/src/Memory/PrivateStringManager.cs | 16 | ||||
-rw-r--r-- | lib/Utils/src/VNLib.Utils.csproj | 13 | ||||
-rw-r--r-- | lib/Utils/tests/VNLib.UtilsTests.csproj | 6 |
5 files changed, 38 insertions, 21 deletions
diff --git a/lib/Utils/src/IO/VnMemoryStream.cs b/lib/Utils/src/IO/VnMemoryStream.cs index ada2c64..f4bf970 100644 --- a/lib/Utils/src/IO/VnMemoryStream.cs +++ b/lib/Utils/src/IO/VnMemoryStream.cs @@ -58,7 +58,8 @@ namespace VNLib.Utils.IO /// <param name="readOnly">Should the stream be readonly?</param> /// <exception cref="ArgumentException"></exception> /// <returns>A <see cref="VnMemoryStream"/> wrapper to access the handle data</returns> - public static VnMemoryStream ConsumeHandle(IResizeableMemoryHandle<byte> handle, nint length, bool readOnly) => FromHandle(handle, true, length, readOnly); + public static VnMemoryStream ConsumeHandle(IResizeableMemoryHandle<byte> handle, nint length, bool readOnly) + => FromHandle(handle, true, length, readOnly); /// <summary> /// Creates a new <see cref="VnMemoryStream"/> from the supplied memory handle diff --git a/lib/Utils/src/Memory/MemoryUtil.cs b/lib/Utils/src/Memory/MemoryUtil.cs index ba25104..6efd5ba 100644 --- a/lib/Utils/src/Memory/MemoryUtil.cs +++ b/lib/Utils/src/Memory/MemoryUtil.cs @@ -356,14 +356,31 @@ namespace VNLib.Utils.Memory [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void InitializeBlock<T>(ref T block, int itemCount) where T : struct { + if (itemCount <= 0) + { + return; + } + + InitializeBlock(ref block, (uint)itemCount); + } + + /// <summary> + /// Zeroes a block of memory of the given unmanaged type + /// </summary> + /// <typeparam name="T">The unmanaged type to zero</typeparam> + /// <param name="block">A pointer to the block of memory to zero</param> + /// <param name="itemCount">The number of elements in the block to zero</param> + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] + public static void InitializeBlock<T>(ref T block, uint itemCount) where T : struct + { ThrowIfNullRef(in block, nameof(block)); - if (itemCount <= 0) + if (itemCount == 0) { return; } - ZeroByRef(ref block, (uint)itemCount); + ZeroByRef(ref block, itemCount); } /// <summary> diff --git a/lib/Utils/src/Memory/PrivateStringManager.cs b/lib/Utils/src/Memory/PrivateStringManager.cs index 073ee9e..2bc825c 100644 --- a/lib/Utils/src/Memory/PrivateStringManager.cs +++ b/lib/Utils/src/Memory/PrivateStringManager.cs @@ -65,9 +65,7 @@ namespace VNLib.Utils.Memory strRef.Erase(); //Set the new value and determine if it is interned - ProtectedElements[index] = value is null ? - new StringRef(null, false) - : new StringRef(value, string.IsInterned(value) != null); + ProtectedElements[index] = StringRef.Create(value); } /// <summary> @@ -105,6 +103,14 @@ namespace VNLib.Utils.Memory ///<inheritdoc/> protected override void Free() => Array.ForEach(ProtectedElements, static p => p.Erase()); + /// <summary> + /// Erases the contents of the supplied string if it + /// is safe to do so. If the string is interned, it will + /// not be erased, nor will a null string + /// </summary> + /// <param name="str">The reference to the string to zero</param> + public static void EraseString(string? str) => StringRef.Create(str).Erase(); + private readonly record struct StringRef(string? Value, bool IsInterned) { public readonly void Erase() @@ -118,6 +124,10 @@ namespace VNLib.Utils.Memory MemoryUtil.UnsafeZeroMemory<char>(Value); } } + + internal static StringRef Create(string? str) => str is null ? + new(null, false) + : new(str, string.IsInterned(str) != null); } } } diff --git a/lib/Utils/src/VNLib.Utils.csproj b/lib/Utils/src/VNLib.Utils.csproj index 54199e0..bda2164 100644 --- a/lib/Utils/src/VNLib.Utils.csproj +++ b/lib/Utils/src/VNLib.Utils.csproj @@ -17,6 +17,7 @@ <Company>Vaughn Nugent</Company> <Product>VNLib Utilities Library</Product> <Copyright>Copyright © 2024 Vaughn Nugent</Copyright> + <PackageTags>vnlib,utils,utilities,vnlib utils,utility</PackageTags> <Description>.NET/8.0 Utilities library for high-performance common operations. Utilities and abstractions for building and diagnosing native memory implementations. Dyanmic native library loading, IO, extensions, data encoding, resource access, and asynchronous cooperation primitives.</Description> <PackageProjectUrl>https://www.vaughnnugent.com/resources/software/modules/VNLib.Core</PackageProjectUrl> <RepositoryUrl>https://github.com/VnUgE/VNLib.Core/tree/main/lib/Utils</RepositoryUrl> @@ -36,18 +37,6 @@ <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> - - <PropertyGroup Condition="'$(Configuration)'=='Debug'"> - <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> - </PropertyGroup> - - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> - <Deterministic>False</Deterministic> - </PropertyGroup> - - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> - <Deterministic>False</Deterministic> - </PropertyGroup> <ItemGroup> <PackageReference Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2"> diff --git a/lib/Utils/tests/VNLib.UtilsTests.csproj b/lib/Utils/tests/VNLib.UtilsTests.csproj index 75093f8..9a8891e 100644 --- a/lib/Utils/tests/VNLib.UtilsTests.csproj +++ b/lib/Utils/tests/VNLib.UtilsTests.csproj @@ -17,9 +17,9 @@ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> - <PackageReference Include="MSTest.TestAdapter" Version="3.2.0" /> - <PackageReference Include="MSTest.TestFramework" Version="3.2.0" /> - <PackageReference Include="coverlet.collector" Version="6.0.0"> + <PackageReference Include="MSTest.TestAdapter" Version="3.2.2" /> + <PackageReference Include="MSTest.TestFramework" Version="3.2.2" /> + <PackageReference Include="coverlet.collector" Version="6.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> |