summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-04-15 15:52:27 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-04-15 15:52:27 (GMT)
commite914d413128e504f4bb4c46315c9afef104388c9 (patch)
tree8170ba652ef5cb511f6849da643a29ac37b5ce7b /Objects/bytesobject.c
parent12bb6f4c7d590e29f7c57d176d4295da4ef4573a (diff)
downloadcpython-e914d413128e504f4bb4c46315c9afef104388c9.zip
cpython-e914d413128e504f4bb4c46315c9afef104388c9.tar.gz
cpython-e914d413128e504f4bb4c46315c9afef104388c9.tar.bz2
Issue #26766: Fix _PyBytesWriter_Finish()
Return a bytearray object when bytearray is requested and when the small buffer is used. Fix also test_bytes: bytearray%args must return a bytearray type.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index ec03233..701ae9d 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -4150,7 +4150,12 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str)
result = PyBytes_FromStringAndSize(NULL, 0);
}
else if (writer->use_small_buffer) {
- result = PyBytes_FromStringAndSize(writer->small_buffer, size);
+ if (writer->use_bytearray) {
+ result = PyByteArray_FromStringAndSize(writer->small_buffer, size);
+ }
+ else {
+ result = PyBytes_FromStringAndSize(writer->small_buffer, size);
+ }
}
else {
result = writer->buffer;