Skip to content

Commit d7f14fc

Browse files
committed
PEP-7: Move to shorter function names, reformat arg lists
1 parent 150fcee commit d7f14fc

1 file changed

Lines changed: 39 additions & 44 deletions

File tree

Modules/_io/textio.c

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ struct textio
737737
leading to NULL pointer dereferences (see gh-143008, gh-142594). Protect against
738738
that by using helpers to check self->buffer validity at callsites. */
739739
static PyObject *
740-
_textiowrapper_buffer_safe(textio *self)
740+
buffer_access_safe(textio *self)
741741
{
742742
/* Check self->buffer directly but match errors of CHECK_ATTACHED since this
743743
is called during construction and destruction where self->ok which
@@ -757,9 +757,9 @@ _textiowrapper_buffer_safe(textio *self)
757757
}
758758

759759
static PyObject *
760-
_textiowrapper_buffer_get_attr(textio *self, PyObject *attr_name)
760+
buffer_getattr(textio *self, PyObject *attr_name)
761761
{
762-
PyObject *buffer = _textiowrapper_buffer_safe(self);
762+
PyObject *buffer = buffer_access_safe(self);
763763

764764
if (buffer == NULL) {
765765
return NULL;
@@ -768,9 +768,9 @@ _textiowrapper_buffer_get_attr(textio *self, PyObject *attr_name)
768768
}
769769

770770
static PyObject *
771-
_textiowrapper_buffer_callmethod_noargs(textio *self, PyObject *name)
771+
buffer_callmethod_noargs(textio *self, PyObject *name)
772772
{
773-
PyObject *buffer = _textiowrapper_buffer_safe(self);
773+
PyObject *buffer = buffer_access_safe(self);
774774

775775
if (buffer == NULL) {
776776
return NULL;
@@ -779,9 +779,9 @@ _textiowrapper_buffer_callmethod_noargs(textio *self, PyObject *name)
779779
}
780780

781781
static PyObject *
782-
_textiowrapper_buffer_callmethod_onearg(textio *self, PyObject *name, PyObject *arg)
782+
buffer_callmethod_onearg(textio *self, PyObject *name, PyObject *arg)
783783
{
784-
PyObject *buffer = _textiowrapper_buffer_safe(self);
784+
PyObject *buffer = buffer_access_safe(self);
785785

786786
if (buffer == NULL) {
787787
return NULL;
@@ -958,7 +958,7 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info,
958958
PyObject *res;
959959
int r;
960960

961-
res = _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(readable));
961+
res = buffer_callmethod_noargs(self, &_Py_ID(readable));
962962
if (res == NULL)
963963
return -1;
964964

@@ -1014,7 +1014,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
10141014
PyObject *res;
10151015
int r;
10161016

1017-
res = _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(writable));
1017+
res = buffer_callmethod_noargs(self, &_Py_ID(writable));
10181018
if (res == NULL)
10191019
return -1;
10201020

@@ -1060,14 +1060,13 @@ _textiowrapper_fix_encoder_state(textio *self)
10601060

10611061
self->encoding_start_of_stream = 1;
10621062

1063-
PyObject *cookie = _textiowrapper_buffer_callmethod_noargs(self,
1064-
&_Py_ID(tell));
1065-
if (cookie == NULL) {
1063+
PyObject *cookieObj = buffer_callmethod_noargs(self, &_Py_ID(tell));
1064+
if (cookieObj == NULL) {
10661065
return -1;
10671066
}
10681067

1069-
int cmp = PyObject_RichCompareBool(cookie, _PyLong_GetZero(), Py_EQ);
1070-
Py_DECREF(cookie);
1068+
int cmp = PyObject_RichCompareBool(cookieObj, _PyLong_GetZero(), Py_EQ);
1069+
Py_DECREF(cookieObj);
10711070
if (cmp < 0) {
10721071
return -1;
10731072
}
@@ -1701,7 +1700,7 @@ _textiowrapper_writeflush(textio *self)
17011700

17021701
PyObject *ret;
17031702
do {
1704-
ret = _textiowrapper_buffer_callmethod_onearg(self, &_Py_ID(write), b);
1703+
ret = buffer_callmethod_onearg(self, &_Py_ID(write), b);
17051704
} while (ret == NULL && _PyIO_trap_eintr());
17061705
Py_DECREF(b);
17071706
// NOTE: We cleared buffer but we don't know how many bytes are actually written
@@ -1847,7 +1846,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
18471846
}
18481847

18491848
if (needflush) {
1850-
PyObject *buffer = _textiowrapper_buffer_safe(self);
1849+
PyObject *buffer = buffer_access_safe(self);
18511850
if (buffer == NULL || _PyFile_Flush(buffer) < 0) {
18521851
return NULL;
18531852
}
@@ -1978,12 +1977,10 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
19781977
if (chunk_size == NULL)
19791978
goto fail;
19801979

1981-
input_chunk = _textiowrapper_buffer_callmethod_onearg(self,
1982-
(self->has_read1 ?
1983-
&_Py_ID(read1):
1984-
&_Py_ID(read)
1985-
),
1986-
chunk_size);
1980+
input_chunk = buffer_callmethod_onearg(self,
1981+
(self->has_read1 ? &_Py_ID(read1) :
1982+
&_Py_ID(read)),
1983+
chunk_size);
19871984
Py_DECREF(chunk_size);
19881985
if (input_chunk == NULL)
19891986
goto fail;
@@ -2067,8 +2064,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
20672064

20682065
if (n < 0) {
20692066
/* Read everything */
2070-
PyObject *bytes = _textiowrapper_buffer_callmethod_noargs(self,
2071-
&_Py_ID(read));
2067+
PyObject *bytes = buffer_callmethod_noargs(self, &_Py_ID(read));
20722068
PyObject *decoded;
20732069
if (bytes == NULL)
20742070
goto fail;
@@ -2665,7 +2661,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
26652661
Py_DECREF(res);
26662662
}
26672663

2668-
PyObject *buf = _textiowrapper_buffer_safe(self);
2664+
PyObject *buf = buffer_access_safe(self);
26692665
if (buf == NULL) {
26702666
goto fail;
26712667
}
@@ -2717,7 +2713,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
27172713
posobj = PyLong_FromOff_t(cookie.start_pos);
27182714
if (posobj == NULL)
27192715
goto fail;
2720-
res = _textiowrapper_buffer_callmethod_onearg(self, &_Py_ID(seek), posobj);
2716+
res = buffer_callmethod_onearg(self, &_Py_ID(seek), posobj);
27212717
Py_DECREF(posobj);
27222718
if (res == NULL)
27232719
goto fail;
@@ -2738,8 +2734,9 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
27382734
if (bytes_to_feed == NULL) {
27392735
goto fail;
27402736
}
2741-
PyObject *input_chunk = _textiowrapper_buffer_callmethod_onearg(self,
2742-
&_Py_ID(read), bytes_to_feed);
2737+
PyObject *input_chunk = buffer_callmethod_onearg(self,
2738+
&_Py_ID(read),
2739+
bytes_to_feed);
27432740
Py_DECREF(bytes_to_feed);
27442741

27452742
PyObject *decoded;
@@ -2840,7 +2837,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
28402837
goto fail;
28412838
}
28422839

2843-
posobj = _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(tell));
2840+
posobj = buffer_callmethod_noargs(self, &_Py_ID(tell));
28442841
if (posobj == NULL)
28452842
goto fail;
28462843

@@ -3050,9 +3047,7 @@ _io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos)
30503047
return NULL;
30513048
}
30523049

3053-
return _textiowrapper_buffer_callmethod_onearg(self,
3054-
&_Py_ID(truncate),
3055-
pos);
3050+
return buffer_callmethod_onearg(self, &_Py_ID(truncate), pos);
30563051
}
30573052

30583053
static PyObject *
@@ -3134,7 +3129,7 @@ static PyObject *
31343129
_io_TextIOWrapper_fileno_impl(textio *self)
31353130
/*[clinic end generated code: output=21490a4c3da13e6c input=515e1196aceb97ab]*/
31363131
{
3137-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(fileno));
3132+
return buffer_callmethod_noargs(self, &_Py_ID(fileno));
31383133
}
31393134

31403135
/*[clinic input]
@@ -3146,7 +3141,7 @@ static PyObject *
31463141
_io_TextIOWrapper_seekable_impl(textio *self)
31473142
/*[clinic end generated code: output=ab223dbbcffc0f00 input=71c4c092736c549b]*/
31483143
{
3149-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(seekable));
3144+
return buffer_callmethod_noargs(self, &_Py_ID(seekable));
31503145
}
31513146

31523147
/*[clinic input]
@@ -3158,7 +3153,7 @@ static PyObject *
31583153
_io_TextIOWrapper_readable_impl(textio *self)
31593154
/*[clinic end generated code: output=72ff7ba289a8a91b input=80438d1f01b0a89b]*/
31603155
{
3161-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(readable));
3156+
return buffer_callmethod_noargs(self, &_Py_ID(readable));
31623157
}
31633158

31643159
/*[clinic input]
@@ -3170,7 +3165,7 @@ static PyObject *
31703165
_io_TextIOWrapper_writable_impl(textio *self)
31713166
/*[clinic end generated code: output=a728c71790d03200 input=9d6c22befb0c340a]*/
31723167
{
3173-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(writable));
3168+
return buffer_callmethod_noargs(self, &_Py_ID(writable));
31743169
}
31753170

31763171
/*[clinic input]
@@ -3182,7 +3177,7 @@ static PyObject *
31823177
_io_TextIOWrapper_isatty_impl(textio *self)
31833178
/*[clinic end generated code: output=12be1a35bace882e input=7f83ff04d4d1733d]*/
31843179
{
3185-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(isatty));
3180+
return buffer_callmethod_noargs(self, &_Py_ID(isatty));
31863181
}
31873182

31883183
/*[clinic input]
@@ -3199,7 +3194,7 @@ _io_TextIOWrapper_flush_impl(textio *self)
31993194
self->telling = self->seekable;
32003195
if (_textiowrapper_writeflush(self) < 0)
32013196
return NULL;
3202-
return _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(flush));
3197+
return buffer_callmethod_noargs(self, &_Py_ID(flush));
32033198
}
32043199

32053200
/*[clinic input]
@@ -3232,9 +3227,9 @@ _io_TextIOWrapper_close_impl(textio *self)
32323227
else {
32333228
PyObject *exc = NULL;
32343229
if (self->finalizing) {
3235-
res = _textiowrapper_buffer_callmethod_onearg(self,
3236-
&_Py_ID(_dealloc_warn),
3237-
(PyObject *)self);
3230+
res = buffer_callmethod_onearg(self,
3231+
&_Py_ID(_dealloc_warn),
3232+
(PyObject *)self);
32383233
if (res) {
32393234
Py_DECREF(res);
32403235
}
@@ -3246,7 +3241,7 @@ _io_TextIOWrapper_close_impl(textio *self)
32463241
exc = PyErr_GetRaisedException();
32473242
}
32483243

3249-
res = _textiowrapper_buffer_callmethod_noargs(self, &_Py_ID(close));
3244+
res = buffer_callmethod_noargs(self, &_Py_ID(close));
32503245
if (exc != NULL) {
32513246
_PyErr_ChainExceptions1(exc);
32523247
Py_CLEAR(res);
@@ -3314,7 +3309,7 @@ static PyObject *
33143309
_io_TextIOWrapper_name_get_impl(textio *self)
33153310
/*[clinic end generated code: output=8c2f1d6d8756af40 input=26ecec9b39e30e07]*/
33163311
{
3317-
return _textiowrapper_buffer_get_attr(self, &_Py_ID(name));
3312+
return buffer_getattr(self, &_Py_ID(name));
33183313
}
33193314

33203315
/*[clinic input]
@@ -3332,7 +3327,7 @@ _io_TextIOWrapper_closed_get_impl(textio *self)
33323327
33333328
Match original behavior by calling CHECK_ATTACHED explicitly. */
33343329
CHECK_ATTACHED(self);
3335-
return _textiowrapper_buffer_get_attr(self, &_Py_ID(closed));
3330+
return buffer_getattr(self, &_Py_ID(closed));
33363331
}
33373332

33383333
/*[clinic input]

0 commit comments

Comments
 (0)