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 5287219E004A for ; Wed, 16 Dec 2015 23:03:45 +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 3085CB5D8D5 for ; Wed, 16 Dec 2015 23:35:47 +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 0C6F718CC7EB for ; Wed, 16 Dec 2015 23:35:47 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9D4AA1204A9; Wed, 16 Dec 2015 23:35:46 +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 9CB3D120485 for ; Wed, 16 Dec 2015 23:35:42 +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=WjaUwkQEsbX1FuO7/OwUO2Gk8Gc=; b=y+by22ojCNmHeacNHW ldCudl7hlfrE2qzrnsPFpmIoxBzQ9EjW22UUYTwnBVcIMw8fvWvlxq2+wXjZ3y9z n24he9EK27tZukAu1jSik1E/jnDTU+uUcNCdglv46V+htsOUH7wiFP/3bNawaBVE lwyKtfxJ9g8SvBJvhYsKg6uXQ= Received: by filter0447p1mdw1.sendgrid.net with SMTP id filter0447p1mdw1.13421.567176B73A 2015-12-16 14:35:35.868320155 +0000 UTC Received: from herokuapp.com (ec2-54-159-218-150.compute-1.amazonaws.com [54.159.218.150]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id EXaIRPdDTPOuByqB2tUvAA for ; Wed, 16 Dec 2015 14:35:35.849 +0000 (UTC) Date: Wed, 16 Dec 2015 14:35:35 +0000 From: eregontp@gmail.com 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: 46897 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11740 X-Redmine-Issue-Author: Eregon X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: Eregon 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS53bCbzRq5hszBszrqRwHQwc5CGsmvXUZDLCW Cd8SYr+u1luHNCgbVfJq5DBvC0KHIuovRCgoYCKJUFsswvsyrZyuy5Dx0Ra8iTSErH5B/5964Hl/SW t20Ry54Md4Nbc70pcFMu4Y5fATGPnZRekUJBFcf1Smwp0geY7BCnt2khZw== X-ML-Name: ruby-core X-Mail-Count: 72187 Subject: [ruby-core:72187] [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 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/