From: "byroot (Jean Boussier) via ruby-core" Date: 2024-02-12T11:28:44+00:00 Subject: [ruby-core:116674] [Ruby master Bug#20253] `Proc.dup` and `Proc#clone` don't preserve finalizers Issue #20253 has been updated by byroot (Jean Boussier). We just found yet another issue with @etienne: ```ruby >> Proc.new { }.freeze.clone (irb):1:in `initialize_copy': can't modify frozen Proc: # (FrozenError) from (irb):1:in `initialize_clone' from (irb):1:in `clone' from (irb):1:in `
' ``` This one was introduced in Ruby 3.3.0. ---------------------------------------- Bug #20253: `Proc.dup` and `Proc#clone` don't preserve finalizers https://bugs.ruby-lang.org/issues/20253#change-106688 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Backport: 3.0: WONTFIX, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- While reviewing the fix for [Bug #20250] @peterzhu2118 pointed that `FL_FINALIZE` should probably also be cleared. However after some extra testing, it appears `Object#dup` and `Object#clone` do copy over the finalizer (which makes sense). But for some reason `Proc` has its own `dup/clone` implementation, which does copy the `FL_FINALIZE` flag, but doesn't copy the finalizer: Test script: ```ruby def fin(sym) ->(_) { p sym } end obj = Object.new ObjectSpace.define_finalizer(obj, fin(:obj)) obj.dup obj.clone proc = Proc.new { } ObjectSpace.define_finalizer(proc, fin(:proc)) proc.dup proc.clone ``` Expected output: ``` :proc :proc :proc :obj :obj :obj ``` Actual output: ``` :proc :obj :obj :obj ``` This discrepancy is present all the way back to Ruby 1.9. It's so niche I'm not sure it's worth a backport though... -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/