Project

General

Profile

Actions

Bug #21343

open

Namespace: singleton classes of root namespace leak between namespaces

Bug #21343: Namespace: singleton classes of root namespace leak between namespaces

Added by jhawthorn (John Hawthorn) 7 months ago. Updated 10 days ago.

Status:
Open
Target version:
-
[ruby-core:122132]
Tags:

Description

Ruby classes all have singleton classes, those singleton classes have singleton classes, and so on with infinite nesting. Since we don't have infinite resources, we create these lazily.

Because of this, only a certain number of singleton classes exist in the root namespace. At a certain depth, mutable singleton classes end up shared between namespaces.

File.write("/tmp/ntest.rb", <<~'RUBY')
  p String.singleton_class.singleton_class::Foo
  String.singleton_class.singleton_class::Bar = 456
RUBY

String.singleton_class.singleton_class::Foo = 123

ns = Namespace.new
ns.require("/tmp/ntest.rb")

p String.singleton_class.singleton_class::Bar
RUBY_NAMESPACE=1 ruby nstest2.rb
ruby: warning: Namespace is experimental, and the behavior may change in the future!
See doc/namespace.md for known issues, etc.
123
456

Updated by byroot (Jean Boussier) 7 months ago Actions #1 [ruby-core:122135]

Seems adjacent to https://bugs.ruby-lang.org/issues/21330.

The klass field like the flags one isn't part of the classext_t, so it's not effectively namespaced.

Updated by hsbt (Hiroshi SHIBATA) 7 months ago Actions #2

  • Tags set to namespace

Updated by tagomoris (Satoshi Tagomori) 10 days ago Actions #3 [ruby-core:124095]

  • Assignee set to tagomoris (Satoshi Tagomori)
Actions

Also available in: PDF Atom