Skip to content

Commit 53926a1

Browse files
committed
_PyBytesWriter: rename size attribute to min_size
1 parent fa7762e commit 53926a1

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

Include/bytesobject.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ typedef struct {
134134
/* Number of allocated size */
135135
Py_ssize_t allocated;
136136

137-
/* Current size of the buffer (can be smaller than the allocated size) */
138-
Py_ssize_t size;
137+
/* Minimum number of allocated bytes,
138+
incremented by _PyBytesWriter_Prepare() */
139+
Py_ssize_t min_size;
139140

140141
/* If non-zero, overallocate the buffer (default: 0). */
141142
int overallocate;

Objects/bytesobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,7 +3821,7 @@ _PyBytesWriter_Init(_PyBytesWriter *writer)
38213821
{
38223822
writer->buffer = NULL;
38233823
writer->allocated = 0;
3824-
writer->size = 0;
3824+
writer->min_size = 0;
38253825
writer->overallocate = 0;
38263826
writer->use_small_buffer = 0;
38273827
#ifdef Py_DEBUG
@@ -3874,7 +3874,7 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
38743874
}
38753875

38763876
start = _PyBytesWriter_AsString(writer);
3877-
assert(0 <= writer->size && writer->size <= writer->allocated);
3877+
assert(0 <= writer->min_size && writer->min_size <= writer->allocated);
38783878
/* the last byte must always be null */
38793879
assert(start[writer->allocated] == 0);
38803880

@@ -3897,18 +3897,18 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size)
38973897
return str;
38983898
}
38993899

3900-
if (writer->size > PY_SSIZE_T_MAX - size) {
3900+
if (writer->min_size > PY_SSIZE_T_MAX - size) {
39013901
PyErr_NoMemory();
39023902
_PyBytesWriter_Dealloc(writer);
39033903
return NULL;
39043904
}
3905-
writer->size += size;
3905+
writer->min_size += size;
39063906

39073907
allocated = writer->allocated;
3908-
if (writer->size <= allocated)
3908+
if (writer->min_size <= allocated)
39093909
return str;
39103910

3911-
allocated = writer->size;
3911+
allocated = writer->min_size;
39123912
if (writer->overallocate
39133913
&& allocated <= (PY_SSIZE_T_MAX - allocated / OVERALLOCATE_FACTOR)) {
39143914
/* overallocate to limit the number of realloc() */
@@ -3957,7 +3957,7 @@ char*
39573957
_PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
39583958
{
39593959
/* ensure that _PyBytesWriter_Alloc() is only called once */
3960-
assert(writer->size == 0 && writer->buffer == NULL);
3960+
assert(writer->min_size == 0 && writer->buffer == NULL);
39613961
assert(size >= 0);
39623962

39633963
writer->use_small_buffer = 1;

0 commit comments

Comments
 (0)