3 days of hunting for a bug

I’ve spent 3 days on getting simple code to work. In exchange I’ve got more experience with xsltproc internals. But I’m not sure it’s a fair trade.

The task was simple. I wanted to apply templates to node in a certain mode. I found that xsltTransformContext contains mode and mode uri strings. I initialized these fields with my values, and … got nothing.

During the first day I was understanding why. The answer is simple. In some cases, xsltproc doesn’t use xmlStrCmp to compare string. Instead, xsltproc compares strings as pointers. Pointers comparation works because all XSLT-related strings are interned into one dictionary. One string in the dictionary is used for all strings with the same content.

Second day was lost on making lookups to dictionary. Instead of results I was getting core dumps.

On the third day I wrote a separated code to test only modes. It worked. So I returned to the step two to look more closely at the core dump problem.

And soon I was blaming myself.

I was using “ctxt->inst->doc->dict“, but ctxt was initializing only 20 lines below. Shame on me. Don’t work late in evenings.

Leave a Reply