Skip to content

Commit

Permalink
pythongh-112205: Update textio module to use @getter as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Dec 14, 2023
1 parent fddc829 commit 22814ab
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 49 deletions.
90 changes: 89 additions & 1 deletion Modules/_io/clinic/textio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 36 additions & 48 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg)
}

static PyObject *
textiowrapper_closed_get(textio *self, void *context);
_io_TextIOWrapper_closed_get_impl(textio *self);

/* This macro takes some shortcuts to make the common case faster. */
#define CHECK_CLOSED(self) \
Expand All @@ -1486,7 +1486,7 @@ textiowrapper_closed_get(textio *self, void *context);
if (self->raw != NULL) \
r = _PyFileIO_closed(self->raw); \
else { \
_res = textiowrapper_closed_get(self, NULL); \
_res = _io_TextIOWrapper_closed_get_impl(self); \
if (_res == NULL) \
return NULL; \
r = PyObject_IsTrue(_res); \
Expand Down Expand Up @@ -3090,7 +3090,7 @@ _io_TextIOWrapper_close_impl(textio *self)
int r;
CHECK_ATTACHED(self);

res = textiowrapper_closed_get(self, NULL);
res = _io_TextIOWrapper_closed_get_impl(self);
if (res == NULL)
return NULL;
r = PyObject_IsTrue(res);
Expand Down Expand Up @@ -3164,42 +3164,43 @@ textiowrapper_iternext(textio *self)
return line;
}

/*[clinic input]
@critical_section
@getter
_io.TextIOWrapper.name
[clinic start generated code]*/

static PyObject *
textiowrapper_name_get_impl(textio *self, void *context)
_io_TextIOWrapper_name_get_impl(textio *self)
/*[clinic end generated code: output=8c2f1d6d8756af40 input=26ecec9b39e30e07]*/
{
CHECK_ATTACHED(self);
return PyObject_GetAttr(self->buffer, &_Py_ID(name));
}

static PyObject *
textiowrapper_name_get(textio *self, void *context)
{
PyObject *result = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
result = textiowrapper_name_get_impl(self, context);
Py_END_CRITICAL_SECTION();
return result;
}
/*[clinic input]
@critical_section
@getter
_io.TextIOWrapper.closed
[clinic start generated code]*/

static PyObject *
textiowrapper_closed_get_impl(textio *self, void *context)
_io_TextIOWrapper_closed_get_impl(textio *self)
/*[clinic end generated code: output=b49b68f443a85e3c input=7dfcf43f63c7003d]*/
{
CHECK_ATTACHED(self);
return PyObject_GetAttr(self->buffer, &_Py_ID(closed));
}

static PyObject *
textiowrapper_closed_get(textio *self, void *context)
{
PyObject *result = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
result = textiowrapper_closed_get_impl(self, context);
Py_END_CRITICAL_SECTION();
return result;
}
/*[clinic input]
@critical_section
@getter
_io.TextIOWrapper.newlines
[clinic start generated code]*/

static PyObject *
textiowrapper_newlines_get_impl(textio *self, void *context)
_io_TextIOWrapper_newlines_get_impl(textio *self)
/*[clinic end generated code: output=53aa03ac35573180 input=610df647e514b3e8]*/
{
PyObject *res;
CHECK_ATTACHED(self);
Expand All @@ -3211,33 +3212,20 @@ textiowrapper_newlines_get_impl(textio *self, void *context)
return res;
}

static PyObject *
textiowrapper_newlines_get(textio *self, void *context)
{
PyObject *result = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
result = textiowrapper_newlines_get_impl(self, context);
Py_END_CRITICAL_SECTION();
return result;
}
/*[clinic input]
@critical_section
@getter
_io.TextIOWrapper.errors
[clinic start generated code]*/

static PyObject *
textiowrapper_errors_get_impl(textio *self, void *context)
_io_TextIOWrapper_errors_get_impl(textio *self)
/*[clinic end generated code: output=dca3a3ef21b09484 input=b45f983e6d43c4d8]*/
{
CHECK_INITIALIZED(self);
return Py_NewRef(self->errors);
}

static PyObject *
textiowrapper_errors_get(textio *self, void *context)
{
PyObject *result = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
result = textiowrapper_errors_get_impl(self, context);
Py_END_CRITICAL_SECTION();
return result;
}

/*[clinic input]
@critical_section
@getter
Expand Down Expand Up @@ -3349,12 +3337,12 @@ static PyMemberDef textiowrapper_members[] = {
};

static PyGetSetDef textiowrapper_getset[] = {
{"name", (getter)textiowrapper_name_get, NULL, NULL},
{"closed", (getter)textiowrapper_closed_get, NULL, NULL},
_IO_TEXTIOWRAPPER_NAME_GETSETDEF
_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
*/
{"newlines", (getter)textiowrapper_newlines_get, NULL, NULL},
{"errors", (getter)textiowrapper_errors_get, NULL, NULL},
_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF
_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
{NULL}
};
Expand Down

0 comments on commit 22814ab

Please sign in to comment.