the road to hell is paved with good intentions

I've spent the evening investigating why I was getting a core dump. It was not an easy task because the code was in a plugin (so it was hard to set a breakpoint) and the data structures were full of links (libxml) or the mess (Guile).

Well, suppose you have the empty element node par and two text nodes node1 and node2 with the content text1 and text1. You adds nodes node1 and node2 as children to the node par. What the structure do you get? A node with two text children? No, it's too boring. Excerpt from the xmlAddChild description:

Add a new node to @parent, at the end of the child (or property) list merging adjacent TEXT nodes (in which case @cur is freed)

It was my problem. I was reusing a freed node. It was a big problem because I had to reuse it, and the automatical merging broke the mapping between SCM values and xml nodes. Well, the solution is trivial: I don't map text nodes anymore, and now I see that it is the right way.

Conclusion: sometimes even the road to hell is useful.

By the way, I've implemented conversion of Scheme lists to XML nodesets. The problem above arose while working on the conversion.

Categories: Generative XML