bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015) (GH-11020)

(cherry picked from commit 4c49da0cb7434c676d70b9ccf38aca82ac0d64a9)
16 files changed