From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,SPF_PASS, T_DKIM_INVALID shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 0777A1FF72 for ; Tue, 24 Oct 2017 18:53:49 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 287D3120924; Wed, 25 Oct 2017 03:53:46 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 7433B120922 for ; Wed, 25 Oct 2017 03:53:44 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=c61SHBtSNZROXt/xdTC7Sz/ll1o=; b=CKleAAjU+V1x5u+Tb7 gnApvae2sVd2BES4mgR/NPLN06L/wnTaGV3GGEodfl+GC81EZCXq8scMz12cyusq Fb1MsQoXJPXQkl/WuTFdZVpvCw8CWAe5vI+1FoKrZG1VRfTQL7RRmGBrpsFvxjX1 AKCMRXB/jc3gQGpUKFYXkXxjw= Received: by filter0019p3mdw1.sendgrid.net with SMTP id filter0019p3mdw1-1683-59EF8C34-A 2017-10-24 18:53:40.16295642 +0000 UTC Received: from herokuapp.com (ec2-54-90-85-45.compute-1.amazonaws.com [54.90.85.45]) by ismtpd0019p1iad2.sendgrid.net (SG) with ESMTP id HtskYQR1TWajDMuO2TRiLw Tue, 24 Oct 2017 18:53:40.049 +0000 (UTC) Date: Tue, 24 Oct 2017 18:53:41 +0000 (UTC) From: msiegel@riverdaletechinc.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 58664 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13498 X-Redmine-Issue-Author: herwin X-Redmine-Issue-Assignee: nobu X-Redmine-Sender: RubyBugs X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5tMBUM/BQUDBz3iGhLcLnhpg09+MmtV7QnEK DV9XjdhJoZj3TXG0Y5JKmqLbgpyZis0xKyaIMe4bqWVVtpdEh0aVcLkUR/lppWT1IVGlDcWZFCzrxM vrFbRBruidNo5pArMKMaARu0BpuiBAkR7HBJXuXTaZVRaTOmWd7HCx8pTg== X-ML-Name: ruby-core X-Mail-Count: 83547 Subject: [ruby-core:83547] [Ruby trunk Bug#13498] Weakref, Weakmap and define_finalizer don't work on frozen objects X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #13498 has been updated by RubyBugs (A Nonymous). nobu (Nobuyoshi Nakada) wrote: > Weakref is implemented by finalizer to notify that an object is collected, and you can't define finalizers on frozen objects. > Probably we need to move finalizer flags to a separate region (like bitmap marking). Yes please. I also came here having discovered this independently, and also see it as a bug. It makes designs using frozen objects difficult to this friction with a leaky abstraction in the language implementation. Unless I am mistaken, and mutating objects is an intentional part of the design of the GC system? ---------------------------------------- Bug #13498: Weakref, Weakmap and define_finalizer don't work on frozen objects https://bugs.ruby-lang.org/issues/13498#change-67575 * Author: herwin (Herwin W) * Status: Assigned * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: * ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] (but seen the same issue with 2.3 and 2.1) * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- I'm just creating a single ticket for these issues, I guess they're actually all the same (I've seen weakref uses weakmap, not sure about define_finalizer). ```ruby require 'weakref' map = ObjectSpace::WeakMap.new o = Object.new o.freeze begin WeakRef.new(o) rescue => e STDERR.puts e end begin map[o] = 'foo' rescue => e STDERR.puts e end begin map['bar'] = o rescue => e STDERR.puts e end begin ObjectSpace.define_finalizer(o, ->(id) { p id }) rescue => e STDERR.puts e end ``` Every statement here raises the runtime error "can't modify frozen Object". The documentation doesn't mention that frozen objects are not allowed, the closest reference we get is a short paragraph in WeakRef: "With this you will have to limit your self to String keys, otherwise you will get an ArgumentError because WeakRef cannot create a finalizer for a Symbol. Symbols are immutable and cannot be garbage collected" -- https://bugs.ruby-lang.org/