Skip to content

Commit 6718c5c

Browse files
committed
trivial fixes addressing review comments
1 parent 4199b88 commit 6718c5c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Lib/test/test_io/test_bufferedio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ def test_append_write(self):
14901490
f.seek(0)
14911491

14921492
# This read previously returned b'tBst testA' but that is
1493-
# inccorect if the underlying raw file is in append mode;
1493+
# incorect if the underlying raw file is in append mode;
14941494
# see bpo-20082
14951495
self.assertEqual(f.read(), b'test testAB')
14961496
f.flush()

Modules/_io/bufferedio.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,26 +1354,30 @@ _io__Buffered_tell_impl(buffered *self)
13541354
static PyObject *
13551355
_buffered_seek_unlocked(buffered *self, Py_off_t target, int whence)
13561356
{
1357-
Py_off_t n;
13581357
PyObject *res = NULL;
13591358

13601359
if (self->writable) {
13611360
res = _bufferedwriter_flush_unlocked(self);
1362-
if (res == NULL)
1361+
if (res == NULL) {
13631362
return res;
1363+
}
13641364
Py_CLEAR(res);
13651365
}
13661366

13671367
/* TODO: align on block boundary and read buffer if needed? */
1368-
if (whence == 1)
1368+
if (whence == 1) {
13691369
target -= RAW_OFFSET(self);
1370-
n = _buffered_raw_seek(self, target, whence);
1371-
if (n == -1)
1370+
}
1371+
1372+
Py_off_t n = _buffered_raw_seek(self, target, whence);
1373+
if (n == -1) {
13721374
return res;
1375+
}
13731376
self->raw_pos = -1;
13741377
res = PyLong_FromOff_t(n);
1375-
if (res != NULL && self->readable)
1378+
if (res != NULL && self->readable) {
13761379
_bufferedreader_reset_buf(self);
1380+
}
13771381

13781382
return res;
13791383
}
@@ -1940,20 +1944,20 @@ _bufferedwriter_reset_buf(buffered *self)
19401944
static void
19411945
_bufferedwriter_set_append(buffered *self)
19421946
{
1943-
PyObject *mode;
1944-
1945-
mode = _PyObject_GetAttrId(self->raw, &PyId_mode);
1947+
PyObject *mode = _PyObject_GetAttrId(self->raw, &PyId_mode);
19461948
if (mode != NULL) {
1947-
/* Raw fileobj has no mode string so as far as we can know it has
1948-
normal write behavior */
1949-
if (PyUnicode_FindChar(mode, 'a', 0, PyUnicode_GET_LENGTH(mode), 1) != -1) {
1949+
if (PyUnicode_FindChar(mode, 'a', 0,
1950+
PyUnicode_GET_LENGTH(mode), 1) != -1) {
19501951
self->appending = 1;
1951-
} else {
1952+
}
1953+
else {
19521954
self->appending = 0;
19531955
}
19541956
Py_DECREF(mode);
1955-
} else {
1956-
PyErr_Clear();
1957+
}
1958+
else {
1959+
/* Raw fileobj has no mode string so as far as we can know it has
1960+
normal write behavior */
19571961
self->appending = 0;
19581962
}
19591963
}
@@ -2148,8 +2152,9 @@ _io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer)
21482152

21492153
if (self->appending) {
21502154
res = _buffered_seek_unlocked(self, 0, SEEK_END);
2151-
if (res == NULL)
2155+
if (res == NULL) {
21522156
goto error;
2157+
}
21532158
Py_DECREF(res);
21542159
}
21552160

0 commit comments

Comments
 (0)