Properly define the header_anchor helper function

Prevents all the various segfaults we've seen since 3.1.0

Fixes #349