ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:80835] [Ruby trunk Bug#13498] Weakref, Weakmap and define_finalizer don't work on frozen objects
       [not found] <redmine.issue-13498.20170423071652@ruby-lang.org>
@ 2017-04-23  7:16 ` ruby
  2017-06-16  2:36 ` [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] " nobu
  2017-10-24 18:53 ` [ruby-core:83547] [Ruby trunk Bug#13498] " msiegel
  2 siblings, 0 replies; 3+ messages in thread
From: ruby @ 2017-04-23  7:16 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] Weakref, Weakmap and define_finalizer don't work on frozen objects
       [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
  2017-10-24 18:53 ` [ruby-core:83547] [Ruby trunk Bug#13498] " msiegel
  2 siblings, 0 replies; 3+ messages in thread
From: nobu @ 2017-06-16  2:36 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:83547] [Ruby trunk Bug#13498] Weakref, Weakmap and define_finalizer don't work on frozen objects
       [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 ` [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] " nobu
@ 2017-10-24 18:53 ` msiegel
  2 siblings, 0 replies; 3+ messages in thread
From: msiegel @ 2017-10-24 18:53 UTC (permalink / raw)
  To: 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-24 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 ` [ruby-core:81697] [Ruby trunk Bug#13498][Assigned] " nobu
2017-10-24 18:53 ` [ruby-core:83547] [Ruby trunk Bug#13498] " msiegel

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