Merge pull request #696 from martindevans/safe_handle_constructor_refactor

Removed Unnecessary Constructor From Safe Handles
This commit is contained in:
Martin Evans 2024-04-26 16:14:42 +01:00 committed by GitHub
commit 18586cc43b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 42 deletions

View File

@ -13,7 +13,7 @@ namespace LLama.Native
/// <param name="start_rule_index"></param>
/// <returns></returns>
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe IntPtr llama_grammar_init(LLamaGrammarElement** rules, ulong n_rules, ulong start_rule_index);
public static extern unsafe SafeLLamaGrammarHandle llama_grammar_init(LLamaGrammarElement** rules, ulong n_rules, ulong start_rule_index);
/// <summary>
/// Free all memory from the given SafeLLamaGrammarHandle
@ -28,7 +28,7 @@ namespace LLama.Native
/// <param name="grammar"></param>
/// <returns></returns>
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr llama_grammar_copy(SafeLLamaGrammarHandle grammar);
public static extern SafeLLamaGrammarHandle llama_grammar_copy(SafeLLamaGrammarHandle grammar);
/// <summary>
/// Apply constraints from grammar

View File

@ -16,15 +16,6 @@ namespace LLama.Native
: SafeLLamaHandleBase
{
#region construction/destruction
/// <summary>
///
/// </summary>
/// <param name="handle"></param>
internal SafeLLamaGrammarHandle(IntPtr handle)
: base(handle, true)
{
}
/// <inheritdoc />
protected override bool ReleaseHandle()
{
@ -97,11 +88,11 @@ namespace LLama.Native
/// <exception cref="RuntimeError"></exception>
public static unsafe SafeLLamaGrammarHandle Create(LLamaGrammarElement** rules, ulong nrules, ulong start_rule_index)
{
var grammar_ptr = NativeApi.llama_grammar_init(rules, nrules, start_rule_index);
if (grammar_ptr == IntPtr.Zero)
var grammar = NativeApi.llama_grammar_init(rules, nrules, start_rule_index);
if (grammar is null)
throw new RuntimeError("Failed to create grammar from rules");
return new(grammar_ptr);
return grammar;
}
#endregion
@ -111,7 +102,7 @@ namespace LLama.Native
/// <returns></returns>
public SafeLLamaGrammarHandle Clone()
{
return new SafeLLamaGrammarHandle(NativeApi.llama_grammar_copy(this));
return NativeApi.llama_grammar_copy(this);
}
/// <summary>

View File

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using LLama;
using LLama.Exceptions;
namespace LLama.Native
@ -15,15 +10,6 @@ namespace LLama.Native
public sealed class SafeLlavaImageEmbedHandle
: SafeLLamaHandleBase
{
private SafeLlavaImageEmbedHandle(IntPtr handle)
: base(handle, true)
{
}
private SafeLlavaImageEmbedHandle()
{}
/// <summary>
/// Create an image embed from an image file
/// </summary>

View File

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using LLama;
using LLama.Exceptions;
@ -16,15 +12,6 @@ namespace LLama.Native
public sealed class SafeLlavaModelHandle
: SafeLLamaHandleBase
{
private SafeLlavaModelHandle(IntPtr handle)
: base(handle, true)
{
}
private SafeLlavaModelHandle()
{}
/// <inheritdoc />
protected override bool ReleaseHandle()
{