Backport from paradise/macros

review @paulp

Supersedes #1831