serialize function cannot deal with datastructures with loops

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

serialize function cannot deal with datastructures with loops

Steven Sagaert
Hi,
It seems the serialize function cannot deal with reference based datastructures (composite types) that have loops in them (it goes into stackoverflow due to infinite recursion). This seems like a bug. By simply tracking the already visited nodes one could avoid infinite recursion and correctly serialize such structures. 

Any chance this will be fixed in the future or is this considered "a feature"?
Reply | Threaded
Open this post in threaded view
|

Re: serialize function cannot deal with datastructures with loops

Stefan Karpinski
This feature has already been added in 0.4:

julia> x = []
0-element Array{Any,1}

julia> push!(x,x)
1-element Array{Any,1}:
 Any[#= circular reference =#]

julia> y = let io = IOBuffer()
           serialize(io, x)
           seek(io, 0)
           deserialize(io)
       end
1-element Array{Any,1}:
 Any[#= circular reference =#]

julia> x === y
false

On Mon, Sep 14, 2015 at 7:35 AM, Steven Sagaert <[hidden email]> wrote:
Hi,
It seems the serialize function cannot deal with reference based datastructures (composite types) that have loops in them (it goes into stackoverflow due to infinite recursion). This seems like a bug. By simply tracking the already visited nodes one could avoid infinite recursion and correctly serialize such structures. 

Any chance this will be fixed in the future or is this considered "a feature"?

Reply | Threaded
Open this post in threaded view
|

Re: serialize function cannot deal with datastructures with loops

Steven Sagaert
Ok thanks.

On Monday, September 14, 2015 at 4:38:43 PM UTC+2, Stefan Karpinski wrote:
This feature has already been added in 0.4:

julia> x = []
0-element Array{Any,1}

julia> push!(x,x)
1-element Array{Any,1}:
 Any[#= circular reference =#]

julia> y = let io = IOBuffer()
           serialize(io, x)
           seek(io, 0)
           deserialize(io)
       end
1-element Array{Any,1}:
 Any[#= circular reference =#]

julia> x === y
false

On Mon, Sep 14, 2015 at 7:35 AM, Steven Sagaert <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="cimyDOkJAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">steven....@...> wrote:
Hi,
It seems the serialize function cannot deal with reference based datastructures (composite types) that have loops in them (it goes into stackoverflow due to infinite recursion). This seems like a bug. By simply tracking the already visited nodes one could avoid infinite recursion and correctly serialize such structures. 

Any chance this will be fixed in the future or is this considered "a feature"?