Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 01/02: store HookContext closures on the instance not the class
Date: Sat, 28 Nov 2026 18:37:14 +1100	[thread overview]
Message-ID: <20261128073713.7B7742D46AD@bl2.djc.id.au> (raw)
In-Reply-To: <179585143333.302910.18345502445563611855@bl2.djc.id.au>

New commit on branch develop:
https://supmua.dev/git/sup/commit/6a28d978d8975bfa6b5c9cf7505948760a3430ba.html

commit 6a28d978d8975bfa6b5c9cf7505948760a3430ba
Author: Dan Callaghan <djc@djc.id.au>
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
 

  reply	other threads:[~2026-11-28  7:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  7:37 [sup.git] branch develop updated (53f07beb -> cc601160) Dan Callaghan
2026-11-28  7:37 ` Dan Callaghan [this message]
2026-11-28  7:37 ` [sup.git] 02/02: tests: avoid Redwood::start Dan Callaghan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128073713.7B7742D46AD@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox