From: Lazaridis Ilias Date: 2011-07-03T01:35:20+09:00 Subject: [ruby-core:37745] [Ruby 1.9 - Bug #4893] Literal Instantiation breaks Object Model Issue #4893 has been updated by Lazaridis Ilias. File test_runner_String_initialize.diff added Lazaridis Ilias wrote: [...] > I still need to verify that this draft implementation does not break existent behaviour. If assumed that passing all "make test" is not enough, and indeed "make test-all" uncovered some problems. Find attached the modification for test/runner.rb in order to run "make test-all". Five tests failed, all with the same message: "Insecure: can't set class variable." test_safe_04(TestERBCore): test_safe_04(TestERBCoreWOStrScan): test_safe4(TestException) [P:/sand/rubyi2/sandbox/ruby193/test/ruby/test_exception.rb:243]: test_exec_recursive(TestObject): test_taint(TestRegexp) [P:/sand/rubyi2/sandbox/ruby193/test/ruby/test_regexp.rb:495]: Seems to have to do with the "tainted" mechanism, not sure if the access to the class-variable should be disallowed (the class object String is *not* tainted, only it's instances). But that's not the issue, as it's a detail of the test code. - I'll move tomorrow on, implementing the final (production) version. Can someone inform me please about this: * is there a standard mechanism to detect "singleton-method created/deleted", which works on the C-level? [please note that the UI here does not allow me to reopen an issue by myself]. ---------------------------------------- Bug #4893: Literal Instantiation breaks Object Model http://redmine.ruby-lang.org/issues/4893 Author: Lazaridis Ilias Status: Rejected Priority: Normal Assignee: Yukihiro Matsumoto Category: Target version: ruby -v: 1.9.2 #String2.rb class String def initialize(val) self.replace(val) puts object_id end def my_method_test 'has method ' end end # command line $ irb irb(main):001:0> original = String.new("original") => "original" irb(main):002:0> load "String2.rb" => true irb(main):003:0> altered = String.new("altered") 21878604 => "altered" irb(main):004:0> altered.my_method_test => "has method " irb(main):005:0> literal = "literal" => "literal" irb(main):006:0> literal.my_method_test => "has method " irb(main):007:0> - The initialize method is an integral part of the class String. From the moment that "String2.rb" is loaded, the initialize method of class String has been validly redefined. (The behaviour of the String class within the "irb session" is altered) The altered initialize method is now an integral part of the class String. The altered String object behaves as expected (responds to "my_method_test, initialized via redefined initialize method). The String(Literal) object responds to "my_method_test", but it is was not initialized with the redefined initialize method. - The "Literal Instantiation" calls the original (core-C-level) String initialize method instead of the redefined one (user-language-level). This *breaks* the object model. -- http://redmine.ruby-lang.org