Project

General

Profile

Actions

Bug #20253

closed

`Proc.dup` and `Proc#clone` don't preserve finalizers

Added by byroot (Jean Boussier) 3 months ago. Updated 3 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116656]

Description

While reviewing the fix for [Bug #20250] @peterzhu2118 (Peter Zhu) 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:

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...


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #20250: Crash with "Object ID seen, but not in mapping table: proc" errorClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0