diff options
author | vnugent <public@vaughnnugent.com> | 2023-08-14 11:43:35 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-08-14 11:43:35 -0400 |
commit | 3f5eb61fc7166674a5424d5f8e8c23a775c27614 (patch) | |
tree | 55a759d2cb0906251ac2dd5aec5e8551b7fb7594 /lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs | |
parent | 692398494aa9dc49738da3a12e0b884ee4e56287 (diff) |
Compression api exposed and tests updated
Diffstat (limited to 'lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs')
-rw-r--r-- | lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs b/lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs index 0f86107..2ee6018 100644 --- a/lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs +++ b/lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs @@ -85,10 +85,10 @@ namespace VNLib.Net.Compression /// and used for the lifetime of the application. /// </para> /// </summary> - internal sealed class LibraryWrapper + internal sealed class LibraryWrapper { private readonly SafeLibraryHandle _lib; - private readonly MethodTable _methodTable; + private MethodTable _methodTable; public string LibFilePath { get; } @@ -104,10 +104,10 @@ namespace VNLib.Net.Compression /// </summary> /// <param name="filePath">The path to the native library to load</param> /// <returns>The native library wrapper</returns> - public static LibraryWrapper LoadLibrary(string filePath) + public static LibraryWrapper LoadLibrary(string filePath, DllImportSearchPath searchType) { //Load the library into the current process - SafeLibraryHandle lib = SafeLibraryHandle.LoadLibrary(filePath, DllImportSearchPath.SafeDirectories); + SafeLibraryHandle lib = SafeLibraryHandle.LoadLibrary(filePath, searchType); try { @@ -223,6 +223,14 @@ namespace VNLib.Net.Compression } /// <summary> + /// Frees the specified compressor instance without raising exceptions + /// </summary> + /// <param name="compressor">A pointer to the valid compressor instance to free</param> + /// <returns>A value indicating the result of the free operation</returns> + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int FreeSafeCompressor(IntPtr compressor) => _methodTable.Free(compressor); + + /// <summary> /// Determines the output size of a given input size and flush mode for the specified compressor /// </summary> /// <param name="compressor">A pointer to the compressor instance</param> @@ -255,6 +263,23 @@ namespace VNLib.Net.Compression return result; } + ///<inheritdoc/> + ~LibraryWrapper() + { + _methodTable = default; + _lib.Dispose(); + } + + /// <summary> + /// Manually releases the library + /// </summary> + internal void ManualRelease() + { + _methodTable = default; + _lib.Dispose(); + GC.SuppressFinalize(this); + } + private readonly struct MethodTable { public GetSupportedMethodsDelegate GetMethods { get; init; } |