ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] Weakref, Weakmap and define_finalizer don't work on frozen objects
Date: Fri, 16 Jun 2017 02:36:03 +0000	[thread overview]
Message-ID: <redmine.journal-65385.20170616023602.d3a4eea04519358e@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13498.20170423071652@ruby-lang.org

Issue #13498 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Assigned
Assignee set to nobu (Nobuyoshi Nakada)

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

----------------------------------------
Bug #13498: Weakref, Weakmap and define_finalizer don't work on frozen objects
https://bugs.ruby-lang.org/issues/13498#change-65385

* 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/

  parent reply	other threads:[~2017-06-16  2:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-13498.20170423071652@ruby-lang.org>
2017-04-23  7:16 ` [ruby-core:80835] [Ruby trunk Bug#13498] Weakref, Weakmap and define_finalizer don't work on frozen objects ruby
2017-06-16  2:36 ` nobu [this message]
2017-10-24 18:53 ` [ruby-core:83547] " msiegel

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-list from there: mbox

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

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.journal-65385.20170616023602.d3a4eea04519358e@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).