STINNER Victor <vstin...@redhat.com> added the comment:

PR 13952 fix many errors, but not of all them.

test_io.PyBufferedWriterTest.test_misbehaved_io() logs a warning, whereas 
test_io.CBufferedWriterTest.test_misbehaved_io() doesn't. It seems like 
_pyio.BufferedWriter lacks bpo-32228 fix.

Extract of the C implementation:

static PyObject *
_bufferedwriter_flush_unlocked(buffered *self)
{
    ...

    if (!VALID_WRITE_BUFFER(self) || self->write_pos == self->write_end)
        goto end;

    /* First, rewind */
    rewind = RAW_OFFSET(self) + (self->pos - self->write_pos);
    if (rewind != 0) {
        n = _buffered_raw_seek(self, -rewind, 1);
        if (n < 0) {
            goto error;
        }
        self->raw_pos -= rewind;
    }
    ...


end:
    /* This ensures that after return from this function,
       VALID_WRITE_BUFFER(self) returns false.

       This is a required condition because when a tell() is called
       after flushing and if VALID_READ_BUFFER(self) is false, we need
       VALID_WRITE_BUFFER(self) to be false to have
       RAW_OFFSET(self) == 0.

       Issue: https://bugs.python.org/issue32228 */
    _bufferedwriter_reset_buf(self);
    Py_RETURN_NONE;

error:
    return NULL;
}

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37223>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to