From: eregontp@... Date: 2015-12-16T14:35:35+00:00 Subject: [ruby-core:72187] [Ruby trunk - Bug #11740] ObjectSpace.each_object exposes internal metaclasses Issue #11740 has been updated by Benoit Daloze. Thanks for looking at this! I tried, but I observed a few issues. First, when running the test above with -v: ~~~ ruby 2.3.0dev (2015-12-16 trunk 53152) [x86_64-linux] # [#, Array, Enumerable, Object, Kernel, BasicObject] objspace_expose_intern_meta.rb:10: warning: instance variable __attached__ not initialized objspace_expose_intern_meta.rb:10: warning: instance variable __attached__ not initialized nil ~~~ I think it would be better to hide this warning from the user. Second, while the patch now hides the internal class, it seems to also hide sclass exposed to the user. ~~~ p c = Class.new p i = c.new p s = i.singleton_class p s.is_a? c.singleton_class p ObjectSpace.each_object(c.singleton_class).to_a s.singleton_class p ObjectSpace.each_object(c.singleton_class).to_a ~~~ outputs: ~~~ ... [#] # c.singleton_class [#:0x00558227ca5748>>, #] # s, c.singleton_class ~~~ So `s` is not shown by each_object, even though the user already has a reference to it (with `s`, and it has a metaclass I believe). So it would seem the check is not correct, but I found no obvious fix. There is a difference between `HAVE_METACLASS_P()` and the check in gc.c though. This failure can also be found by running RubySpec core/objectspace/each_object_spec.rb. PS: How should I apply the patch? I tried `patch < x.patch` but I got a rejected hunk in gc.c ---------------------------------------- Bug #11740: ObjectSpace.each_object exposes internal metaclasses https://bugs.ruby-lang.org/issues/11740#change-55599 * Author: Benoit Daloze * Status: Open * Priority: Normal * Assignee: Koichi Sasada * ruby -v: ruby 2.3.0dev (2015-11-19 trunk 52672) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- ObjectSpace.each_object exposes internal metaclasses and this might result in assumptions being violated since the metaclass structure is not well preserved. See the attached script for an example. The #bla method should always be defined on the metaclass of "klass". See https://bugs.ruby-lang.org/issues/11360#note-2 as well in which I warned against this problem ;) ---Files-------------------------------- objspace_expose_intern_meta.rb (413 Bytes) -- https://bugs.ruby-lang.org/