From 3f5eb61fc7166674a5424d5f8e8c23a775c27614 Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 14 Aug 2023 11:43:35 -0400 Subject: Compression api exposed and tests updated --- .../VNLib.Net.Compression/LibraryWrapper.cs | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'lib/Net.Compression/VNLib.Net.Compression/LibraryWrapper.cs') 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. /// /// - 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 /// /// The path to the native library to load /// The native library wrapper - 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 { @@ -222,6 +222,14 @@ namespace VNLib.Net.Compression } } + /// + /// Frees the specified compressor instance without raising exceptions + /// + /// A pointer to the valid compressor instance to free + /// A value indicating the result of the free operation + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int FreeSafeCompressor(IntPtr compressor) => _methodTable.Free(compressor); + /// /// Determines the output size of a given input size and flush mode for the specified compressor /// @@ -255,6 +263,23 @@ namespace VNLib.Net.Compression return result; } + /// + ~LibraryWrapper() + { + _methodTable = default; + _lib.Dispose(); + } + + /// + /// Manually releases the library + /// + internal void ManualRelease() + { + _methodTable = default; + _lib.Dispose(); + GC.SuppressFinalize(this); + } + private readonly struct MethodTable { public GetSupportedMethodsDelegate GetMethods { get; init; } -- cgit