diff options
author | Donghee Na <donghee.na@python.org> | 2023-11-30 23:37:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 23:37:30 (GMT) |
commit | 5b0629966f47542527400b03498d5156846f0da6 (patch) | |
tree | 9df64a689dd14bccfda4bf045a61b3185f72ebe3 /Modules/_io | |
parent | 674c288b1c29b5d838c0cb6de0ea7a64caf294ff (diff) | |
download | cpython-5b0629966f47542527400b03498d5156846f0da6.zip cpython-5b0629966f47542527400b03498d5156846f0da6.tar.gz cpython-5b0629966f47542527400b03498d5156846f0da6.tar.bz2 |
gh-112205: Update stringio module to use AC for the thread-safe (gh-112549)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/clinic/stringio.c.h | 56 | ||||
-rw-r--r-- | Modules/_io/stringio.c | 58 |
2 files changed, 79 insertions, 35 deletions
diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 8e5c687..ed505ae 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -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]*/ diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index 0aa5e34..74dcee2 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -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} }; |