ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: ko1@atdot.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:72180] [Ruby trunk - Bug #11740] ObjectSpace.each_object exposes internal metaclasses
Date: Wed, 16 Dec 2015 08:06:19 +0000	[thread overview]
Message-ID: <redmine.journal-55594.20151216080616.357a5d6b937b590d@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11740.20151125102527@ruby-lang.org

Issue #11740 has been updated by Koichi Sasada.


```diff
Index: class.c
===================================================================
--- class.c	(revision 53150)
+++ class.c	(working copy)
@@ -442,6 +442,12 @@ rb_singleton_class_attached(VALUE klass,
  */
 #define META_CLASS_OF_CLASS_CLASS_P(k)  (METACLASS_OF(k) == (k))
 
+int
+rb_singleton_class_has_metaclass_p(VALUE sklass)
+{
+    return rb_ivar_get(METACLASS_OF(sklass), id_attached) == sklass;
+}
+
 /*!
  * whether k has a metaclass
  * @retval 1 if \a k has a metaclass
@@ -449,7 +455,13 @@ rb_singleton_class_attached(VALUE klass,
  */
 #define HAVE_METACLASS_P(k) \
     (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
-     rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
+     rb_singleton_class_has_metaclass_p(k))
+
+int
+rb_class_has_metaclass_p(VALUE klass)
+{
+    return HAVE_METACLASS_P(klass);
+}
 
 /*!
  * ensures \a klass belongs to its own eigenclass.
Index: gc.c
===================================================================
--- gc.c	(revision 53150)
+++ gc.c	(working copy)
@@ -2400,6 +2400,13 @@ internal_object_p(VALUE obj)
 	  case T_NODE:
 	  case T_ZOMBIE:
 	    break;
+	  case T_CLASS:
+	    {
+		if (FL_TEST(obj, FL_SINGLETON)) {
+		    int rb_singleton_class_has_metaclass_p(VALUE sklass);
+		    return rb_singleton_class_has_metaclass_p(obj) == 0;
+		}
+	    }
 	  default:
 	    if (!p->as.basic.klass) break;
 	    return 0;
```

This patch solves this problem.
Could you check it?


----------------------------------------
Bug #11740: ObjectSpace.each_object exposes internal metaclasses
https://bugs.ruby-lang.org/issues/11740#change-55594

* 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  7:34 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 ` ko1 [this message]
2015-12-16 14:35 ` [ruby-core:72187] " eregontp
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-55594.20151216080616.357a5d6b937b590d@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).