]> granicus.if.org Git - python/commitdiff
Fix SF bug 546434 -- buffer slice type inconsistent.
authorRaymond Hettinger <python@rcn.com>
Tue, 25 Jun 2002 00:25:30 +0000 (00:25 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 25 Jun 2002 00:25:30 +0000 (00:25 +0000)
Misc/NEWS
Objects/bufferobject.c

index 99c354784398a5ad9b8cc6af82557f4fd5a6155d..9fb542d9003c8a3f807fcf132ea6d1e19f8a25b3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -6,6 +6,11 @@ Type/class unification and new-style classes
 
 Core and builtins
 
+- Slices and repetitions of buffer objects now consistently return
+  a string.  Formerly, strings would be returned most of the time,
+  but a buffer object would be returned when the repetition count
+  was one or when the slice range was all inclusive.
+
 - The __slots__ variable can now mention "private" names, and the
   right thing will happen (e.g. __slots__ = ["__foo"]).
 
index 031c000b8ea9cd6bfebf4a3a4baa19822d033f83..690f56b70203287cc5e9ccbe75700ac79669783d 100644 (file)
@@ -296,13 +296,6 @@ buffer_concat(PyBufferObject *self, PyObject *other)
        if ( (count = (*pb->bf_getreadbuffer)(other, 0, &p2)) < 0 )
                return NULL;
 
-       /* optimize special case */
-       if ( count == 0 )
-       {
-           Py_INCREF(self);
-           return (PyObject *)self;
-       }
-
        ob = PyString_FromStringAndSize(NULL, self->b_size + count);
        p1 = PyString_AS_STRING(ob);
        memcpy(p1, self->b_ptr, self->b_size);
@@ -361,12 +354,6 @@ buffer_slice(PyBufferObject *self, int left, int right)
                right = 0;
        if ( right > self->b_size )
                right = self->b_size;
-       if ( left == 0 && right == self->b_size )
-       {
-               /* same as self */
-               Py_INCREF(self);
-               return (PyObject *)self;
-       }
        if ( right < left )
                right = left;
        return PyString_FromStringAndSize((char *)self->b_ptr + left,