Join GitHub today
Add initialize_dup and initialize_clone #1910
This pull request isn't complete yet.
I opened because I need some feedback on how to change
Copy the code for
The same question is valid for other classes that need to add specific behavior to
P.S.: This will fix #1889.
This post has a discussion of language version-specific changes http://rubini.us/2011/10/18/contributing-to-rubinius/. Generally, you do put the methods in different files. However, we don't want to duplicate code unnecessarily.
In this case, it's a little bit complicated by having those methods defined in alpha.rb. That file has the bare minimum necessary to start loading code. However, we have analogous cases of dealing with this sort of version-specific behavior. When it involves things like the "kind" of objects or critical object reflection capabilities, we use the Rubinius::Type module. I'd suggest doing something like this:
diff --git a/kernel/alpha.rb b/kernel/alpha.rb index fb59d54..4c2522a 100644 --- a/kernel/alpha.rb +++ b/kernel/alpha.rb @@ -206,9 +206,7 @@ module Kernel Rubinius.invoke_primitive :object_copy_object, copy, self - Rubinius.privately do - copy.initialize_copy self - end + Rubinius::Type.object_initialize_dup self, copy copy end @@ -236,9 +234,7 @@ module Kernel Rubinius.invoke_primitive :object_copy_object, copy, self Rubinius.invoke_primitive :object_copy_singleton_class, copy, self - Rubinius.privately do - copy.initialize_copy self - end + Rubinius::Type.object_initialize_clone self, copy copy.freeze if frozen? copy @@ -344,6 +340,20 @@ module Rubinius raise PrimitiveFailure, "MethodTable#alias primitive failed" end end + + module Type + def self.object_initialize_dup(obj, copy) + Rubinius.privately do + copy.initialize_copy obj + end + end + + def self.object_initialize_clone(obj, copy) + Rubinius.privately do + copy.initialize_copy obj + end + end + end end @@ -734,4 +744,3 @@ end class Object include Kernel end -
Define appropriate versions of Rubinius::Type.object_initialize_dup, etc. in bootstrap/type19.rb and add the appropriate Kernel, etc. methods for 1.9 mode.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
Unfortunately I got busy last week and couldn't take a look on this.
I intend to take a look this week, though.
On Thursday, September 27, 2012 at 5:21 AM, Dirkjan Bussink wrote: