Well, that was embarrassing. Cf. Mercurial for the working version.
The macro is not compliant with the intended coding standard here; WRAPQUEUE_LEN is supposed to be a primary expression i.e. wrapped in parentheses. In this case, the actual effect is ugly: instead of doing a modulo 4*254+1 increment, we update to an index with uinitialized data. Oops.
Code:
#define WRAPQUEUE_LEN 4*254+1 .... trailing_edge = (trailing_edge+1)%WRAPQUEUE_LEN;