fix windows tests (#16662)

From Robert Collins.
clear BufferedRWPair weakrefs on deallocation (closes #22517)
merge 3.3 (#22517)
merge 3.4 (#22517)
prevent overflow in unicode_repr (closes #22520)
merge 3.3 (#22520)
merge 3.4 (#22520)