Excellent job! I'll base my next patch submissions on this series, because that way I can resolve the conflicts now rather than after Anthony bounced my patches right back to me. Anthony, merging this sooner rather than later would help me. No need for undue haste, of course.
There are a few opportunities for cleanup after insertion of return (stuff like "return -1; } else {"), but that's best done separately, to keep the conversion obvious.