From 5da2a2f64bc8569f3b03c01da1a8ddfd2f2a540a Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Wed, 31 Jan 2024 18:01:03 +0000 Subject: [PATCH] - Removed one of the constructors of `SafeLLamaHandleBase`, which implicitly states that memory is owned. Better to be explicit about this kind of thing! - Also fixed `ToString()` in `SafeLLamaHandleBase` --- LLama/LLamaContext.cs | 2 +- LLama/Native/SafeLLamaGrammarHandle.cs | 2 +- LLama/Native/SafeLLamaHandleBase.cs | 9 +-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/LLama/LLamaContext.cs b/LLama/LLamaContext.cs index 33c8d726..6d39a8f9 100644 --- a/LLama/LLamaContext.cs +++ b/LLama/LLamaContext.cs @@ -443,7 +443,7 @@ namespace LLama : SafeLLamaHandleBase { internal State(IntPtr memory) - : base(memory) + : base(memory, true) { } diff --git a/LLama/Native/SafeLLamaGrammarHandle.cs b/LLama/Native/SafeLLamaGrammarHandle.cs index 6277e594..962d0643 100644 --- a/LLama/Native/SafeLLamaGrammarHandle.cs +++ b/LLama/Native/SafeLLamaGrammarHandle.cs @@ -21,7 +21,7 @@ namespace LLama.Native /// /// internal SafeLLamaGrammarHandle(IntPtr handle) - : base(handle) + : base(handle, true) { } diff --git a/LLama/Native/SafeLLamaHandleBase.cs b/LLama/Native/SafeLLamaHandleBase.cs index 7171c803..7dcc4ef9 100644 --- a/LLama/Native/SafeLLamaHandleBase.cs +++ b/LLama/Native/SafeLLamaHandleBase.cs @@ -14,12 +14,6 @@ namespace LLama.Native { } - private protected SafeLLamaHandleBase(IntPtr handle) - : base(IntPtr.Zero, ownsHandle: true) - { - SetHandle(handle); - } - private protected SafeLLamaHandleBase(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { @@ -30,7 +24,6 @@ namespace LLama.Native public override bool IsInvalid => handle == IntPtr.Zero; /// - public override string ToString() - => $"0x{handle:x16}"; + public override string ToString() => handle.ToString(); } }