summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bufferedio.c
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-12-13 00:39:26 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-12-13 00:39:26 (GMT)
commit317def9fdb29893df1ab380d396fcdd2eafe0588 (patch)
treea164f7c0cb8eedcf94fe46aea3f5eab3545d9e14 /Modules/_io/bufferedio.c
parentd233796f7d444c67fe51b7dd9521d548e650286f (diff)
downloadcpython-317def9fdb29893df1ab380d396fcdd2eafe0588.zip
cpython-317def9fdb29893df1ab380d396fcdd2eafe0588.tar.gz
cpython-317def9fdb29893df1ab380d396fcdd2eafe0588.tar.bz2
bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics (#4826)
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r--Modules/_io/bufferedio.c51
1 files changed, 1 insertions, 50 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 1ae7a70..d7e82b9 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -197,7 +197,7 @@ bufferediobase_write(PyObject *self, PyObject *args)
}
-typedef struct _buffered {
+typedef struct {
PyObject_HEAD
PyObject *raw;
@@ -239,18 +239,8 @@ typedef struct _buffered {
PyObject *dict;
PyObject *weakreflist;
-
- /* a doubly-linked chained list of "buffered" objects that need to
- be flushed when the process exits */
- struct _buffered *next, *prev;
} buffered;
-/* the actual list of buffered objects */
-static buffered buffer_list_end = {
- .next = &buffer_list_end,
- .prev = &buffer_list_end
-};
-
/*
Implementation notes:
@@ -390,20 +380,9 @@ _enter_buffered_busy(buffered *self)
static void
-remove_from_linked_list(buffered *self)
-{
- self->next->prev = self->prev;
- self->prev->next = self->next;
- self->prev = NULL;
- self->next = NULL;
-}
-
-static void
buffered_dealloc(buffered *self)
{
self->finalizing = 1;
- if (self->next != NULL)
- remove_from_linked_list(self);
if (_PyIOBase_finalize((PyObject *) self) < 0)
return;
_PyObject_GC_UNTRACK(self);
@@ -1827,38 +1806,10 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedWriter_Type &&
Py_TYPE(raw) == &PyFileIO_Type);
- if (self->next == NULL) {
- self->prev = &buffer_list_end;
- self->next = buffer_list_end.next;
- buffer_list_end.next->prev = self;
- buffer_list_end.next = self;
- }
-
self->ok = 1;
return 0;
}
-/*
-* Ensure all buffered writers are flushed before proceeding with
-* normal shutdown. Otherwise, if the underlying file objects get
-* finalized before the buffered writer wrapping it then any buffered
-* data will be lost.
-*/
-void _PyIO_atexit_flush(void)
-{
- while (buffer_list_end.next != &buffer_list_end) {
- buffered *buf = buffer_list_end.next;
- remove_from_linked_list(buf);
- if (buf->ok && !buf->finalizing) {
- /* good state and not finalizing */
- Py_INCREF(buf);
- buffered_flush(buf, NULL);
- Py_DECREF(buf);
- PyErr_Clear();
- }
- }
-}
-
static Py_ssize_t
_bufferedwriter_raw_write(buffered *self, char *start, Py_ssize_t len)
{