[Python-checkins] cpython (merge 3.4 -> default): merge 3.4 (#22517)

benjamin.peterson python-checkins at python.org
Tue Sep 30 04:49:41 CEST 2014


https://hg.python.org/cpython/rev/a2add97e28b9
changeset:   92647:a2add97e28b9
parent:      92643:090dc85f4226
parent:      92646:e54da75100f6
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon Sep 29 22:49:05 2014 -0400
summary:
  merge 3.4 (#22517)

files:
  Lib/test/test_io.py      |  6 ++++++
  Misc/NEWS                |  3 +++
  Modules/_io/bufferedio.c |  2 ++
  3 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1628,6 +1628,12 @@
         pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
         self.assertTrue(pair.isatty())
 
+    def test_weakref_clearing(self):
+        brw = self.tp(self.MockRawIO(), self.MockRawIO())
+        ref = weakref.ref(brw)
+        brw = None
+        ref = None # Shouldn't segfault.
+
 class CBufferedRWPairTest(BufferedRWPairTest):
     tp = io.BufferedRWPair
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,9 @@
 Library
 -------
 
+- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
+  weakrefs.
+
 - Issue #22448: Improve canceled timer handles cleanup to prevent
   unbound memory usage. Patch by Joshua Moore-Oliva.
 
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -2343,6 +2343,8 @@
 bufferedrwpair_dealloc(rwpair *self)
 {
     _PyObject_GC_UNTRACK(self);
+    if (self->weakreflist != NULL)
+        PyObject_ClearWeakRefs((PyObject *)self);
     Py_CLEAR(self->reader);
     Py_CLEAR(self->writer);
     Py_CLEAR(self->dict);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list