EzXML.jl icon indicating copy to clipboard operation
EzXML.jl copied to clipboard

`link!` and `unlink!` in a loop of `eachelement`

Open guo-yong-zhi opened this issue 3 years ago • 1 comments

I have a function to stack SVG images together. it is

function svg_stack(svgs::AbstractVector)
    @assert !isempty(svgs)
    bg, rest = Iterators.peel(svgs)
    rt = root(bg|>string|>parsexml)
    for svg in rest
        for c in collect(eachelement(root(svg|>string|>parsexml)))
            unlink!(c)
            link!(rt, c)
        end
    end
    string(rt)
end

You can think of the svg as a xml string. When I removed the collect before the eachelement, some elements are missed. It seems that the second and subsequent elements have never been traversed due to the existence of unlink!. When I kept the collect before the eachelement, however, a segmentation fault occurred occasionally. Like this one:

signal (11): Segmentation fault in expression starting at /home/runner/work/WordCloud.jl/WordCloud.jl/test/runtests.jl:9 unknown function (ip: 0x7f3954feb6a7) xmlOutputBufferWriteString__internal_alias at /workspace/srcdir/libxml2-2.9.10/xmlIO.c:3653 xmlNodeDumpOutputInternal at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:1042 xmlNodeListDumpOutput at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:820 xmlNodeDumpOutputInternal at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:1069 xmlNodeDumpOutput__internal_alias at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:2377 xmlBufNodeDump__internal_alias at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:2271 xmlNodeDump__internal_alias at /workspace/srcdir/libxml2-2.9.10/xmlsave.c:2207 macro expansion at /home/runner/.julia/packages/EzXML/ZNwhK/src/error.jl:50 [inlined] dump_node at /home/runner/.julia/packages/EzXML/ZNwhK/src/node.jl:335 print at /home/runner/.julia/packages/EzXML/ZNwhK/src/node.jl:310 print_to_string at ./strings/io.jl:135 string at ./strings/io.jl:174 [inlined] svg_stack at /home/runner/work/WordCloud.jl/WordCloud.jl/src/svg.jl:82

Did I miss anything? What is the right way to use them? Or is this a bug?

guo-yong-zhi avatar Dec 15 '21 15:12 guo-yong-zhi

Maybe related to this old bug

BenjaminGalliot avatar Apr 28 '22 12:04 BenjaminGalliot