[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: [ruby-core:27339] [Bug #1744](Open) Error with Marshal dump/load on a delegated class.
From: Marc-Andre Lafortune <redmine () ruby-lang ! org>
Date: 2009-12-28 2:32:32
Message-ID: 4b3818c059592_8bcf1cc8ca355d2 () redmine ! ruby-lang ! org
[Download RAW message or body]
Issue #1744 has been updated by Marc-Andre Lafortune.
Status changed from Closed to Open
On Sun, Dec 27, 2009 at 8:19 PM, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
> This change has broken marshal format comatibility.
Indeed.
I can't think of a way to make it backward compatible, but for forward compatibility, \
how about the following?
diff --git a/lib/delegate.rb b/lib/delegate.rb
index f8a71f1..1516dac 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -184,16 +184,21 @@ class Delegator
# Serialization support for the object returned by \_\_getobj\_\_.
def marshal_dump
[
+ :__v2__,
instance_variables,
instance_variables.map{|var| instance_variable_get(var)},
__getobj__
]
end
# Reinitializes delegation from a serialized object.
- def marshal_load(obj)
- vars, values, obj = obj
- vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
- __setobj__(obj)
+ def marshal_load(data)
+ version, vars, values, obj = data
+ if version == :__v2__
+ vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
+ __setobj__(obj)
+ else
+ __setobj__(data)
+ end
end
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1744
----------------------------------------
http://redmine.ruby-lang.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic