[Python-checkins] cpython: Issue #15381: Try to fix refcount bug. Empty and 1-byte buffers are always

serhiy.storchaka python-checkins at python.org
Tue Feb 3 13:58:47 CET 2015


https://hg.python.org/cpython/rev/3fdbdf4d2ac7
changeset:   94487:3fdbdf4d2ac7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue Feb 03 14:57:49 2015 +0200
summary:
  Issue #15381: Try to fix refcount bug. Empty and 1-byte buffers are always shared.

files:
  Modules/_io/bytesio.c |  4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)


diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -38,7 +38,8 @@
         return NULL; \
     }
 
-#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1)
+#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1 || \
+                          PyBytes_GET_SIZE((self)->buf) <= 1)
 
 
 /* Internal routine to get a line from the buffer of a BytesIO
@@ -308,6 +309,7 @@
     char *output;
 
     assert(self->buf != NULL);
+    assert(size <= self->string_size);
     if (size > 1 &&
         self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
         self->exports == 0) {

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


More information about the Python-checkins mailing list