]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112205: Update textio module to use `@getter` as possible. (gh-113095)
authorDonghee Na <donghee.na@python.org>
Thu, 14 Dec 2023 10:26:46 +0000 (10:26 +0000)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 10:26:46 +0000 (10:26 +0000)
Modules/_io/clinic/textio.c.h
Modules/_io/textio.c

index a492f340c74c0ddfb6af666a842543ad146e5cb1..f24f65f0c1d4f9c6a561054d689c2e6a9fd390da 100644 (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]*/
index c76d92cdd38b9a751e745b41eb633366eea7cbbc..702336ca2aeb06852e76d9d20b43fa5557a92088 100644 (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}
 };