ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:72187] [Ruby trunk - Bug #11740] ObjectSpace.each_object exposes internal metaclasses
Date: Wed, 16 Dec 2015 14:35:35 +0000	[thread overview]
Message-ID: <redmine.journal-55599.20151216143534.a8d34feeabbaf783@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11740.20151125102527@ruby-lang.org

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]
#<Class:0x0055cb4c0f3a58>
[#<Class:0x0055cb4c0f3a58>, 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:

~~~
...
[#<Class:0x00558227ca5f90>] # c.singleton_class
[#<Class:#<#<Class:0x00558227ca5f90>:0x00558227ca5748>>, #<Class:0x00558227ca5f90>] # 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/

  parent reply	other threads:[~2015-12-16 14:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11740.20151125102527@ruby-lang.org>
2015-11-25 10:25 ` [ruby-core:71682] [Ruby trunk - Bug #11740] [Open] ObjectSpace.each_object exposes internal metaclasses eregontp
2015-12-07  7:33 ` [ruby-core:71886] [Ruby trunk - Bug #11740] " ko1
2015-12-16  8:06 ` [ruby-core:72180] " ko1
2015-12-16 14:35 ` eregontp [this message]
2015-12-17  2:57 ` [ruby-core:72202] " nobu
2015-12-21 10:34 ` [ruby-core:72420] [Ruby trunk - Bug #11740] [Assigned] " ko1
2015-12-22  2:36 ` [ruby-core:72425] [Ruby trunk - Bug #11740] " shugo
2015-12-24 11:09 ` [ruby-core:72471] " eregontp
2016-02-03 10:56 ` [ruby-core:73681] [Ruby trunk Bug#11740] " usa

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-55599.20151216143534.a8d34feeabbaf783@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).