summaryrefslogtreecommitdiffstats
path: root/Modules/_io/textio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r--Modules/_io/textio.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 3369694..8b5d00f 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -231,16 +231,14 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
PyObject *errors)
/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
{
- self->decoder = decoder;
- Py_INCREF(decoder);
+ self->decoder = Py_NewRef(decoder);
if (errors == NULL) {
- self->errors = &_Py_ID(strict);
+ self->errors = Py_NewRef(&_Py_ID(strict));
}
else {
- self->errors = errors;
+ self->errors = Py_NewRef(errors);
}
- Py_INCREF(self->errors);
self->translate = translate ? 1 : 0;
self->seennl = 0;
@@ -301,8 +299,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
&_Py_ID(decode), input, final ? Py_True : Py_False, NULL);
}
else {
- output = input;
- Py_INCREF(output);
+ output = Py_NewRef(input);
}
if (check_decoded(output) < 0)
@@ -1148,8 +1145,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
* of the partially constructed object (like self->encoding)
*/
- Py_INCREF(errors);
- self->errors = errors;
+ self->errors = Py_NewRef(errors);
self->chunk_size = 8192;
self->line_buffering = line_buffering;
self->write_through = write_through;
@@ -1157,8 +1153,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
}
- self->buffer = buffer;
- Py_INCREF(buffer);
+ self->buffer = Py_NewRef(buffer);
/* Build the decoder object */
if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
@@ -1284,9 +1279,8 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
}
Py_DECREF(codec_info);
- Py_INCREF(errors);
Py_SETREF(self->encoding, encoding);
- Py_SETREF(self->errors, errors);
+ Py_SETREF(self->errors, Py_NewRef(errors));
return _textiowrapper_fix_encoder_state(self);
}
@@ -1502,8 +1496,7 @@ _textiowrapper_writeflush(textio *self)
PyObject *b;
if (PyBytes_Check(pending)) {
- b = pending;
- Py_INCREF(b);
+ b = Py_NewRef(pending);
}
else if (PyUnicode_Check(pending)) {
assert(PyUnicode_IS_ASCII(pending));
@@ -1618,8 +1611,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
// See bpo-43260
PyUnicode_GET_LENGTH(text) <= self->chunk_size &&
is_asciicompat_encoding(self->encodefunc)) {
- b = text;
- Py_INCREF(b);
+ b = Py_NewRef(text);
}
else {
b = (*self->encodefunc)((PyObject *) self, text);
@@ -1741,8 +1733,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
return NULL;
}
else {
- chars = self->decoded_chars;
- Py_INCREF(chars);
+ chars = Py_NewRef(self->decoded_chars);
}
self->decoded_chars_used += n;
@@ -2139,10 +2130,9 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
}
if (remaining == NULL) {
- line = self->decoded_chars;
+ line = Py_NewRef(self->decoded_chars);
start = self->decoded_chars_used;
offset_to_buffer = 0;
- Py_INCREF(line);
}
else {
assert(self->decoded_chars_used == 0);
@@ -3115,8 +3105,7 @@ static PyObject *
textiowrapper_errors_get(textio *self, void *context)
{
CHECK_INITIALIZED(self);
- Py_INCREF(self->errors);
- return self->errors;
+ return Py_NewRef(self->errors);
}
static PyObject *