backport our own copy of the ref-counting extension