aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-14 09:41:48 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-10-14 09:41:48 +0200
commit661aaccf9def380540cc1d440761159a414094d1 (patch)
tree4dde0b83f77253d3a46b0dd8bf1d5f144e48fb58 /Include/bytesobject.h
parentFix long_format_binary() (diff)
downloadcpython-661aaccf9def380540cc1d440761159a414094d1.tar.gz
cpython-661aaccf9def380540cc1d440761159a414094d1.tar.bz2
cpython-661aaccf9def380540cc1d440761159a414094d1.zip
Add use_bytearray attribute to _PyBytesWriter
Issue #25399: Add a new use_bytearray attribute to _PyBytesWriter to use a bytearray buffer, instead of using a bytes object.
Diffstat (limited to 'Include/bytesobject.h')
-rw-r--r--Include/bytesobject.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index b7a7c36bcbb..fbb63226f64 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -128,17 +128,21 @@ PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGrouping(char *buffer,
A _PyBytesWriter variable must be declared at the end of variables in a
function to optimize the memory allocation on the stack. */
typedef struct {
- /* bytes object */
+ /* bytes, bytearray or NULL (when the small buffer is used) */
PyObject *buffer;
- /* Number of allocated size */
+ /* Number of allocated size. */
Py_ssize_t allocated;
/* Minimum number of allocated bytes,
incremented by _PyBytesWriter_Prepare() */
Py_ssize_t min_size;
- /* If non-zero, overallocate the buffer (default: 0). */
+ /* If non-zero, use a bytearray instead of a bytes object for buffer. */
+ int use_bytearray;
+
+ /* If non-zero, overallocate the buffer (default: 0).
+ This flag must be zero if use_bytearray is non-zero. */
int overallocate;
/* Stack buffer */
@@ -153,7 +157,7 @@ typedef struct {
PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
/* Get the buffer content and reset the writer.
- Return a bytes object.
+ Return a bytes object, or a bytearray object if use_bytearray is non-zero.
Raise an exception and return NULL on error. */
PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer,
void *str);