From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 432B919E004A for ; Wed, 16 Dec 2015 16:34:33 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id DBCDDB5D8B3 for ; Wed, 16 Dec 2015 17:06:34 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 5FE4518CC7EB for ; Wed, 16 Dec 2015 17:06:35 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 02B551204EA; Wed, 16 Dec 2015 17:06:34 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id EDF421204D4 for ; Wed, 16 Dec 2015 17:06:29 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=TgRVogE+LxAn4Lb8gTAsIMijIQ4=; b=Qz2edwuGfdn+GzzDQ/ XsEHEImKACfLBG/CKTi0oabSyI9OS+hPBUvMy8w7ZsMQH1Qikerw0ASO7uDjINWS FJeSLyItHyf0/+CZkioCJmJ4i1IxjZQGlYskrAutAbkpaYFsWr2VpL0tL4LtDWND p0SIZefFI18+PNoSw+pNQV4F4= Received: by filter0560p1mdw1.sendgrid.net with SMTP id filter0560p1mdw1.16614.56711B7B3E 2015-12-16 08:06:19.757875199 +0000 UTC Received: from herokuapp.com (ec2-23-22-145-86.compute-1.amazonaws.com [23.22.145.86]) by ismtpd0003p1iad1.sendgrid.net (SG) with ESMTP id xTYdRfo-Rs6FduZsB13SGg for ; Wed, 16 Dec 2015 08:06:19.711 +0000 (UTC) Date: Wed, 16 Dec 2015 08:06:19 +0000 From: ko1@atdot.net To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46891 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11740 X-Redmine-Issue-Author: Eregon X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: ko1 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6czvDdSB4QKkfSFCJZDdV4F7uanod0GjpzBY KzFZ3KqZCeV1quvAEf0jMaRqa3dqmSCHZETs9ykImvdcToChm7NRp6D19d0hq7g+gShcEhgCPyu7gV U1lN+cVPe3Lwc+anDbr0LoThLHbyaiHg+AzZ X-ML-Name: ruby-core X-Mail-Count: 72180 Subject: [ruby-core:72180] [Ruby trunk - Bug #11740] ObjectSpace.each_object exposes internal metaclasses X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/