Project

General

Profile

Feature #4893

Literal Instantiation breaks Object Model

Added by lazaridis.com (Lazaridis Ilias) about 9 years ago. Updated almost 9 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
[ruby-core:37170]

Description

#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.


Files

String_call_initialize.diff (1.73 KB) String_call_initialize.diff patch against branches/ruby_1_9_2 lazaridis.com (Lazaridis Ilias), 06/26/2011 11:01 AM
String_call_initialize.diff (1.73 KB) String_call_initialize.diff patch against branches/ruby_1_9_2 lazaridis.com (Lazaridis Ilias), 06/26/2011 11:01 AM
strings.rb (158 Bytes) strings.rb wishdev (John Higgins), 06/26/2011 12:43 PM
StringInit.rb (851 Bytes) StringInit.rb lazaridis.com (Lazaridis Ilias), 06/26/2011 04:54 PM
String_call_initialize_v2.diff (1.58 KB) String_call_initialize_v2.diff lazaridis.com (Lazaridis Ilias), 06/26/2011 08:06 PM
bootstraptest_runner_addition.diff (1.36 KB) bootstraptest_runner_addition.diff lazaridis.com (Lazaridis Ilias), 06/26/2011 08:06 PM
test_runner_String_initialize.diff (1.04 KB) test_runner_String_initialize.diff modification of ./test/runner.rb (for make test-all) lazaridis.com (Lazaridis Ilias), 07/03/2011 01:35 AM
String_call_initialize_v3.diff (1.9 KB) String_call_initialize_v3.diff patch using FL_USER18 as flag lazaridis.com (Lazaridis Ilias), 07/04/2011 09:02 PM
String_call_initialize_v3b.diff (1.62 KB) String_call_initialize_v3b.diff Corrected a merge-error in the patch v3 lazaridis.com (Lazaridis Ilias), 07/04/2011 09:11 PM
String_call_initialize_v4.diff (2.45 KB) String_call_initialize_v4.diff Without any manual access to the flag lazaridis.com (Lazaridis Ilias), 07/13/2011 08:18 AM
String_call_initialize_v5.diff (2.44 KB) String_call_initialize_v5.diff no use of callbacks, moved most code to vm_method.c lazaridis.com (Lazaridis Ilias), 07/17/2011 11:56 AM
String_call_initialize_v5b.diff (2.44 KB) String_call_initialize_v5b.diff corrected a polarity-error in patch v5 lazaridis.com (Lazaridis Ilias), 07/17/2011 12:01 PM
String_call_initialize_v6.diff (3.3 KB) String_call_initialize_v6.diff stable patch with some doc subjecting possible further processing lazaridis.com (Lazaridis Ilias), 07/21/2011 02:24 PM

Also available in: Atom PDF