Skip to content

Commit 088b10f

Browse files
corona10Glyphack
authored andcommitted
pythongh-112205: Update stringio module to use AC for the thread-safe (pythongh-112549)
1 parent 8d89410 commit 088b10f

File tree

2 files changed

+79
-35
lines changed

2 files changed

+79
-35
lines changed

Modules/_io/clinic/stringio.c.h

+55-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/stringio.c

+24-34
Original file line numberDiff line numberDiff line change
@@ -970,44 +970,44 @@ _io_StringIO___setstate___impl(stringio *self, PyObject *state)
970970
Py_RETURN_NONE;
971971
}
972972

973+
/*[clinic input]
974+
@critical_section
975+
@getter
976+
_io.StringIO.closed
977+
[clinic start generated code]*/
973978

974979
static PyObject *
975-
stringio_closed_impl(stringio *self, void *context)
980+
_io_StringIO_closed_get_impl(stringio *self)
981+
/*[clinic end generated code: output=531ddca7954331d6 input=178d2ef24395fd49]*/
976982
{
977983
CHECK_INITIALIZED(self);
978984
return PyBool_FromLong(self->closed);
979985
}
980986

981-
static PyObject *
982-
stringio_closed(stringio *self, void *context)
983-
{
984-
PyObject *result;
985-
Py_BEGIN_CRITICAL_SECTION(self);
986-
result = stringio_closed_impl(self, context);
987-
Py_END_CRITICAL_SECTION();
988-
return result;
989-
}
987+
/*[clinic input]
988+
@critical_section
989+
@getter
990+
_io.StringIO.line_buffering
991+
[clinic start generated code]*/
990992

991993
static PyObject *
992-
stringio_line_buffering_impl(stringio *self, void *context)
994+
_io_StringIO_line_buffering_get_impl(stringio *self)
995+
/*[clinic end generated code: output=360710e0112966ae input=6a7634e7f890745e]*/
993996
{
994997
CHECK_INITIALIZED(self);
995998
CHECK_CLOSED(self);
996999
Py_RETURN_FALSE;
9971000
}
9981001

999-
static PyObject *
1000-
stringio_line_buffering(stringio *self, void *context)
1001-
{
1002-
PyObject *result;
1003-
Py_BEGIN_CRITICAL_SECTION(self);
1004-
result = stringio_line_buffering_impl(self, context);
1005-
Py_END_CRITICAL_SECTION();
1006-
return result;
1007-
}
1002+
/*[clinic input]
1003+
@critical_section
1004+
@getter
1005+
_io.StringIO.newlines
1006+
[clinic start generated code]*/
10081007

10091008
static PyObject *
1010-
stringio_newlines_impl(stringio *self, void *context)
1009+
_io_StringIO_newlines_get_impl(stringio *self)
1010+
/*[clinic end generated code: output=35d7c0b66d7e0160 input=092a14586718244b]*/
10111011
{
10121012
CHECK_INITIALIZED(self);
10131013
CHECK_CLOSED(self);
@@ -1017,16 +1017,6 @@ stringio_newlines_impl(stringio *self, void *context)
10171017
return PyObject_GetAttr(self->decoder, &_Py_ID(newlines));
10181018
}
10191019

1020-
static PyObject *
1021-
stringio_newlines(stringio *self, void *context)
1022-
{
1023-
PyObject *result;
1024-
Py_BEGIN_CRITICAL_SECTION(self);
1025-
result = stringio_newlines_impl(self, context);
1026-
Py_END_CRITICAL_SECTION();
1027-
return result;
1028-
}
1029-
10301020
static struct PyMethodDef stringio_methods[] = {
10311021
_IO_STRINGIO_CLOSE_METHODDEF
10321022
_IO_STRINGIO_GETVALUE_METHODDEF
@@ -1047,15 +1037,15 @@ static struct PyMethodDef stringio_methods[] = {
10471037
};
10481038

10491039
static PyGetSetDef stringio_getset[] = {
1050-
{"closed", (getter)stringio_closed, NULL, NULL},
1051-
{"newlines", (getter)stringio_newlines, NULL, NULL},
1040+
_IO_STRINGIO_CLOSED_GETTERDEF
1041+
_IO_STRINGIO_NEWLINES_GETTERDEF
10521042
/* (following comments straight off of the original Python wrapper:)
10531043
XXX Cruft to support the TextIOWrapper API. This would only
10541044
be meaningful if StringIO supported the buffer attribute.
10551045
Hopefully, a better solution, than adding these pseudo-attributes,
10561046
will be found.
10571047
*/
1058-
{"line_buffering", (getter)stringio_line_buffering, NULL, NULL},
1048+
_IO_STRINGIO_LINE_BUFFERING_GETTERDEF
10591049
{NULL}
10601050
};
10611051

0 commit comments

Comments
 (0)