Tuesday, 17 February 2009

Feeling Flushed

I just had a little bug fix to do on our embedded product

It uses python with pyrex extensions to drive a small screen in an embedded device. One of the dialogs was not working.

First I wrote a test program that tried to display the non working "DecisionDialog" dialog.
Next, from one of the classes that "DecisionDialog" was using I added print statements.
Fortunately the test program was crashing with an error message too so I kept adding more print statements to hop to the next part of the classes to see where it got confused. Normally this isn't the greatest way of proceeding but the classes have no unit testing or other features that might help.

However, at one point I seemed to be adding more print statements and not getting any extra output

I guessed that there was some problem brought on by the code suddenly stopping with the buffering of the print statements. The code was in a mixture of C, python and python pyrex to bind it together. The problem was in a C code segment so I added

fflush(NULL);

Just after the printf statements that I hoped would help me.

This worked and eventually I managed to find the problem, an unassigned string to a graphics resource.

The bug fix for the dialog was pretty simple (one line in a __init__() function) so I checked out a clean copy of the code, loosing all the print statement rubbish, fixed the clean copy, checked in again and that was that.

When using this crude print method to trace bugs it is worth remembering the buffering layer