From: "make_now_just (Hiroya Fujinami) via ruby-core" Date: 2025-05-13T11:20:22+00:00 Subject: [ruby-core:122045] [Ruby Bug#21316] Namespaces leak with permanent names Issue #21316 has been updated by make_now_just (Hiroya Fujinami). I found an issue on `Marshal` and `Namespace` maybe related to this ticket. When dumping an object defined in a namespace using Marshal, the result will vary depending on whether the namespace is held as a variable or constant, and whether `Marshal.dump` is performed inside or outside the namespace. In other words, we have the following files: `ns.rb`: ```ruby class Foo def dump_in_ns = Marshal.dump(self) end ``` `main.rb`: ```ruby ns = Namespace.new ns.require("./ns.rb") NS = Namespace.new NS.require("./ns.rb") puts "var / in ns" begin ns::Foo.new.dump p :ok rescue => ex p :error p ex end puts puts "const / in ns" begin NS::Foo.new.dump p :ok rescue => ex p :error p ex end puts puts "var / out ns" begin Marshal.dump(ns::Foo.new) p :ok rescue => ex p :error p ex end puts puts "const / out ns" begin Marshal.dump(NS::Foo.new) p :ok rescue => ex p :error p ex end ``` Then, the result is as follows: ```console $ RUBY_NAMESPACE=1 ruby main.rb var / in ns :error #::Foo> const / in ns :error # var / out ns :error #::Foo> const / out ns :ok ``` I'm not sure this issue is completely related to this ticket, but `Marshal.dump` should work in any case. ---------------------------------------- Bug #21316: Namespaces leak with permanent names https://bugs.ruby-lang.org/issues/21316#change-113195 * Author: fxn (Xavier Noria) * Status: Open * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Namespaces are not transparent for this program ```ruby C = Class.new C.name == 'C' ``` because under a non-main user namespace, the name of `C` has the namespace as a prefix. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/