write function call _io_BufferedWriter_write_impl twice?

Windson Yang wiwindson at gmail.com
Wed May 29 23:01:51 EDT 2019


My script looks like this:

    f = open('myfile', 'a+b')
    f.write(b'abcde')

And I also add a `printf` statement in the _io_BufferedWriter_write_impl
<https://github.com/python/cpython/blob/ada319bb6d0ebcc68d3e0ef2b4279ea061877ac8/Modules/_io/bufferedio.c#L1910>
function.

    static PyObject * _io_BufferedWriter_write_impl(buffered *self,
Py_buffer *buffer)
    /*[clinic end generated code: output=7f8d1365759bfc6b
input=dd87dd85fc7f8850]*/
    {
        printf("call write_impl\n");
        PyObject *res = NULL;
        Py_ssize_t written, avail, remaining;
        Py_off_t offset;
       ...

After I compiled then run my script. I found _io_BufferedWriter_write_impl
<https://github.com/python/cpython/blob/ada319bb6d0ebcc68d3e0ef2b4279ea061877ac8/Modules/_io/bufferedio.c#L1910>
had
been called twice which I expected only once. The second time it changed
self->pos to an unexpected value too.


More information about the Python-list mailing list