N
Nathan Weston
I need to marshal and load cyclic data structures, and I need to write
custom marshalling routines because not all the fields of these
structures can be saved.
The default marshalling routines work fine on cyclic data, but when I
write my own, they go into an infinite loop.
Here is some simplified code that demonstrates the problem:
class Cons
def Cons._load(str)
hash = Marshal.load(str)
c = Cons.new()
c.value = hash["value"]
c.rest = hash["rest"]
return c
end
def _dump(depth)
return Marshal.dump({"value" => @value, "rest" => @rest})
end
attr_accessor :value, :rest
end
first = Cons.new
second = Cons.new
first.rest = second
second.rest = first
Marshal.dump(first)
This will hang on the call to Marshal.dump. Is the a simple way to
make this work?
Nathan
custom marshalling routines because not all the fields of these
structures can be saved.
The default marshalling routines work fine on cyclic data, but when I
write my own, they go into an infinite loop.
Here is some simplified code that demonstrates the problem:
class Cons
def Cons._load(str)
hash = Marshal.load(str)
c = Cons.new()
c.value = hash["value"]
c.rest = hash["rest"]
return c
end
def _dump(depth)
return Marshal.dump({"value" => @value, "rest" => @rest})
end
attr_accessor :value, :rest
end
first = Cons.new
second = Cons.new
first.rest = second
second.rest = first
Marshal.dump(first)
This will hang on the call to Marshal.dump. Is the a simple way to
make this work?
Nathan