gh-112205: Update textio module to use `@getter` as possible. (gh-113095)

This commit is contained in:
Donghee Na 2023-12-14 10:26:46 +00:00 committed by GitHub
parent b3c21265fa
commit 23a5711100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 125 additions and 49 deletions

View File

@ -1048,6 +1048,94 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
return return_value;
}
#if defined(_IO_TEXTIOWRAPPER_NAME_GETSETDEF)
# undef _IO_TEXTIOWRAPPER_NAME_GETSETDEF
# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, NULL},
#else
# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, NULL},
#endif
static PyObject *
_io_TextIOWrapper_name_get_impl(textio *self);
static PyObject *
_io_TextIOWrapper_name_get(textio *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = _io_TextIOWrapper_name_get_impl(self);
Py_END_CRITICAL_SECTION();
return return_value;
}
#if defined(_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF)
# undef _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF
# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, NULL},
#else
# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, NULL},
#endif
static PyObject *
_io_TextIOWrapper_closed_get_impl(textio *self);
static PyObject *
_io_TextIOWrapper_closed_get(textio *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = _io_TextIOWrapper_closed_get_impl(self);
Py_END_CRITICAL_SECTION();
return return_value;
}
#if defined(_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF)
# undef _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF
# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, NULL},
#else
# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, NULL},
#endif
static PyObject *
_io_TextIOWrapper_newlines_get_impl(textio *self);
static PyObject *
_io_TextIOWrapper_newlines_get(textio *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = _io_TextIOWrapper_newlines_get_impl(self);
Py_END_CRITICAL_SECTION();
return return_value;
}
#if defined(_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF)
# undef _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF
# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, NULL},
#else
# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, NULL},
#endif
static PyObject *
_io_TextIOWrapper_errors_get_impl(textio *self);
static PyObject *
_io_TextIOWrapper_errors_get(textio *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = _io_TextIOWrapper_errors_get_impl(self);
Py_END_CRITICAL_SECTION();
return return_value;
}
#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF)
# undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL},
@ -1091,4 +1179,4 @@ _io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED
return return_value;
}
/*[clinic end generated code: output=b312f2d2e2221580 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7af87bf848a5d3f3 input=a9049054013a1b77]*/

View File

@ -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) \
@ -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); \
@ -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);
@ -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);
@ -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
@ -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}
};