Today's hacking was mixed, a bit like the weather! At lunch time I hung out at the beer festival with the Collabora crowd in the sun, and one of my arms got slightly burned. This evening I went to the pub as usual (since the beer festival gets impossibly rammed on Thursday and Friday evenings) and I'm now somewhat moist from the rain.
Non-conformant C compilers
My refactoring seems to have been successful! I only needed to fix a few silly mistakes to get the tests to pass, so I'm quite pleased.
But the last silly mistake was very annoying.
As part of eliminating the union, I replaced expressions like
t->branch.twigs with an accessor function
twigs was previously used as a variable name in a few places, and I
missed out one of the renames.
Re-using a name like this during a refactoring is asking for a cockup, but I thought the compiler would have my back because they had such different types.
So last night's messy crash bug was caused by a line vaguely like this:
memmove(nt, twigs + s, size);
twigs is a function pointer, this is clearly nonsense. And in
fact the C standard requires an error message for arithmetic on a
function pointer. (See the constraints in section 6.5.6 of
But my code compiled cleanly with
gcc's developers decided that pointer arithmetic is such a good idea
that it ignores this requirement in the standard unless you tell it to
-pedantic or you enable
-Wpointer-arith. And in the last year
or so I have lazily stopped using
$FANFCFLAGS since I foolishly
-Wall -Wextra covered all the important stuff.
Well, lesson learned. I should be
-pedantic and proud of it.
This afternoon I turned my prose description of how copy-on-write should work into code. It was remarkably straight-forward! The preparatory thinking and refactoring paid off nicely.
However, I forgot to implement the delete function, oops!
Rewrite the hacking branch commit history into something that makes sense. At the very least, I need a proper explanation of what happened during the refactoring.
There's still a lot of work needed to do copy-on-write in the DNS parts of Knot, but I am feeling more confident that this week I have laid down some plausible foundations.