diff -r 57f4ba6b29bf Modules/_io/textio.c --- a/Modules/_io/textio.c Sun Oct 30 04:20:23 2016 +0000 +++ b/Modules/_io/textio.c Sun Oct 30 11:53:14 2016 +0200 @@ -1103,7 +1103,7 @@ static int } static int -_textiowrapper_clear(textio *self) +textiowrapper_clear(textio *self) { self->ok = 0; Py_CLEAR(self->buffer); @@ -1116,6 +1116,8 @@ static int Py_CLEAR(self->snapshot); Py_CLEAR(self->errors); Py_CLEAR(self->raw); + + Py_CLEAR(self->dict); return 0; } @@ -1125,11 +1127,11 @@ textiowrapper_dealloc(textio *self) self->finalizing = 1; if (_PyIOBase_finalize((PyObject *) self) < 0) return; - _textiowrapper_clear(self); + self->ok = 0; _PyObject_GC_UNTRACK(self); if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *)self); - Py_CLEAR(self->dict); + textiowrapper_clear(self); Py_TYPE(self)->tp_free((PyObject *)self); } @@ -1151,15 +1153,6 @@ textiowrapper_traverse(textio *self, vis return 0; } -static int -textiowrapper_clear(textio *self) -{ - if (_textiowrapper_clear(self) < 0) - return -1; - Py_CLEAR(self->dict); - return 0; -} - static PyObject * textiowrapper_closed_get(textio *self, void *context);