This macro seems to contain enough logic, and not be all that performance-sensitive, that you could move its logic into a helper function that you pass a thunk, and have the macro expand to a call to that helper.