From: ruby@herwinw.nl
To: ruby-core@ruby-lang.org
Subject: [ruby-core:80835] [Ruby trunk Bug#13498] Weakref, Weakmap and define_finalizer don't work on frozen objects
Date: Sun, 23 Apr 2017 07:16:53 +0000 [thread overview]
Message-ID: <redmine.issue-13498.20170423071652.7192e57049b491a9@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13498.20170423071652@ruby-lang.org
Issue #13498 has been reported by herwin (Herwin W).
----------------------------------------
Bug #13498: Weakref, Weakmap and define_finalizer don't work on frozen objects
https://bugs.ruby-lang.org/issues/13498
* Author: herwin (Herwin W)
* Status: Open
* Priority: Normal
* Assignee:
* 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/
next parent reply other threads:[~2017-04-23 6: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 [this message]
2017-06-16 2:36 ` [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] Weakref, Weakmap and define_finalizer don't work on frozen objects nobu
2017-10-24 18:53 ` [ruby-core:83547] [Ruby trunk Bug#13498] " 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.issue-13498.20170423071652.7192e57049b491a9@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).