]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112205: Update stringio module to use AC for the thread-safe (gh-112549)
authorDonghee Na <donghee.na@python.org>
Thu, 30 Nov 2023 23:37:30 +0000 (23:37 +0000)
committerGitHub <noreply@github.com>
Thu, 30 Nov 2023 23:37:30 +0000 (08:37 +0900)
Modules/_io/clinic/stringio.c.h
Modules/_io/stringio.c

index 8e5c687dc6a55f8f0f32f8fcdc1972a8d9110de9..ed505ae67589a89c830ea104c9d1a7b9ee817259 100644 (file)
@@ -474,4 +474,58 @@ _io_StringIO___setstate__(stringio *self, PyObject *state)
 
     return return_value;
 }
-/*[clinic end generated code: output=5c8d67f4408a1e6e input=a9049054013a1b77]*/
+
+#define _IO_STRINGIO_CLOSED_GETTERDEF    \
+    {"closed", (getter)_io_StringIO_closed_get, NULL, NULL},
+
+static PyObject *
+_io_StringIO_closed_get_impl(stringio *self);
+
+static PyObject *
+_io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_StringIO_closed_get_impl(self);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
+#define _IO_STRINGIO_LINE_BUFFERING_GETTERDEF    \
+    {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, NULL},
+
+static PyObject *
+_io_StringIO_line_buffering_get_impl(stringio *self);
+
+static PyObject *
+_io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_StringIO_line_buffering_get_impl(self);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
+#define _IO_STRINGIO_NEWLINES_GETTERDEF    \
+    {"newlines", (getter)_io_StringIO_newlines_get, NULL, NULL},
+
+static PyObject *
+_io_StringIO_newlines_get_impl(stringio *self);
+
+static PyObject *
+_io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_StringIO_newlines_get_impl(self);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+/*[clinic end generated code: output=3a92e8b6c322f61b input=a9049054013a1b77]*/
index 0aa5e34cd7c8b20cf0ab71f41b9856b7892e3b02..74dcee2373030696f31e8da4a87054bfae64e540 100644 (file)
@@ -970,44 +970,44 @@ _io_StringIO___setstate___impl(stringio *self, PyObject *state)
     Py_RETURN_NONE;
 }
 
+/*[clinic input]
+@critical_section
+@getter
+_io.StringIO.closed
+[clinic start generated code]*/
 
 static PyObject *
-stringio_closed_impl(stringio *self, void *context)
+_io_StringIO_closed_get_impl(stringio *self)
+/*[clinic end generated code: output=531ddca7954331d6 input=178d2ef24395fd49]*/
 {
     CHECK_INITIALIZED(self);
     return PyBool_FromLong(self->closed);
 }
 
-static PyObject *
-stringio_closed(stringio *self, void *context)
-{
-    PyObject *result;
-    Py_BEGIN_CRITICAL_SECTION(self);
-    result = stringio_closed_impl(self, context);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
+/*[clinic input]
+@critical_section
+@getter
+_io.StringIO.line_buffering
+[clinic start generated code]*/
 
 static PyObject *
-stringio_line_buffering_impl(stringio *self, void *context)
+_io_StringIO_line_buffering_get_impl(stringio *self)
+/*[clinic end generated code: output=360710e0112966ae input=6a7634e7f890745e]*/
 {
     CHECK_INITIALIZED(self);
     CHECK_CLOSED(self);
     Py_RETURN_FALSE;
 }
 
-static PyObject *
-stringio_line_buffering(stringio *self, void *context)
-{
-    PyObject *result;
-    Py_BEGIN_CRITICAL_SECTION(self);
-    result = stringio_line_buffering_impl(self, context);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
+/*[clinic input]
+@critical_section
+@getter
+_io.StringIO.newlines
+[clinic start generated code]*/
 
 static PyObject *
-stringio_newlines_impl(stringio *self, void *context)
+_io_StringIO_newlines_get_impl(stringio *self)
+/*[clinic end generated code: output=35d7c0b66d7e0160 input=092a14586718244b]*/
 {
     CHECK_INITIALIZED(self);
     CHECK_CLOSED(self);
@@ -1017,16 +1017,6 @@ stringio_newlines_impl(stringio *self, void *context)
     return PyObject_GetAttr(self->decoder, &_Py_ID(newlines));
 }
 
-static PyObject *
-stringio_newlines(stringio *self, void *context)
-{
-    PyObject *result;
-    Py_BEGIN_CRITICAL_SECTION(self);
-    result = stringio_newlines_impl(self, context);
-    Py_END_CRITICAL_SECTION();
-    return result;
-}
-
 static struct PyMethodDef stringio_methods[] = {
     _IO_STRINGIO_CLOSE_METHODDEF
     _IO_STRINGIO_GETVALUE_METHODDEF
@@ -1047,15 +1037,15 @@ static struct PyMethodDef stringio_methods[] = {
 };
 
 static PyGetSetDef stringio_getset[] = {
-    {"closed",         (getter)stringio_closed,         NULL, NULL},
-    {"newlines",       (getter)stringio_newlines,       NULL, NULL},
+    _IO_STRINGIO_CLOSED_GETTERDEF
+    _IO_STRINGIO_NEWLINES_GETTERDEF
     /*  (following comments straight off of the original Python wrapper:)
         XXX Cruft to support the TextIOWrapper API. This would only
         be meaningful if StringIO supported the buffer attribute.
         Hopefully, a better solution, than adding these pseudo-attributes,
         will be found.
     */
-    {"line_buffering", (getter)stringio_line_buffering, NULL, NULL},
+    _IO_STRINGIO_LINE_BUFFERING_GETTERDEF
     {NULL}
 };