From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 7B7742D46AD; Sat, 28 Nov 2026 18:37:13 +1100 (AEDT) Date: Sat, 28 Nov 2026 18:37:14 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 01/02: store HookContext closures on the instance not the class MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179585143333.302910.18345502445563611855@bl2.djc.id.au> References: <179585143333.302910.18345502445563611855@bl2.djc.id.au> Thread-Index: AQAAEjRW9DBx9Y9ySomFNFlQQYMSYw== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup.git X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: 6a28d978d8975bfa6b5c9cf7505948760a3430ba X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261128073713.7B7742D46AD@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/6a28d978d8975bfa6b5c9cf7505948760a3430ba.html commit 6a28d978d8975bfa6b5c9cf7505948760a3430ba Author: Dan Callaghan AuthorDate: Sat Nov 28 17:59:14 2026 +1100 store HookContext closures on the instance not the class HookContext allows context variables to be Procs, which get injected into the hook context as methods. Currently only used for :filename in mime-decode to make it lazy. Define the method on the HookContext instance, rather than the class, and ensure it is cleaned up after evaluating the hook. This fixes several issues: 'filename' was being leaked into all other hook contexts after mime-decode was invoked the first time, and its Proc would live eternally for no good reason. And this also fixes a warning about redefining the method: lib/sup/hook.rb:60: warning: method redefined; discarding old filename lib/sup/hook.rb:60: warning: previous definition of filename was here --- lib/sup/hook.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb index 4e9cfd20..9e7757bb 100644 --- a/lib/sup/hook.rb +++ b/lib/sup/hook.rb @@ -56,16 +56,19 @@ class HookManager ## we have to do this via method calls, so you don't get all the ## semantics of a regular variable. not ideal. __lprocs.each do |k, v| - self.class.instance_eval do - define_method k do - @__cache[k] ||= v.call - end + define_singleton_method k do + @__cache[k] ||= v.call end end ret = eval __hook, __binding, __filename BufferManager.clear @__say_id if @__say_id - @__cache = {} ret + ensure + (__lprocs || []).each do |k, v| + next unless singleton_methods(false).include? k + singleton_class.send :remove_method, k + end + @__cache = {} end end