diff options
author | Aivars KalvÄns <aivars.kalvans@gmail.com> | 2022-07-27 08:43:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-27 08:43:34 (GMT) |
commit | 8c88e360e71c8fd456b261f5c5ccc2d8e4db63a0 (patch) | |
tree | 9b843cce89cc6023014df88ff45ce5eead7a5bad /Modules/_io | |
parent | 565403038b75eb64ea483b2757ba30769246d853 (diff) | |
download | cpython-8c88e360e71c8fd456b261f5c5ccc2d8e4db63a0.zip cpython-8c88e360e71c8fd456b261f5c5ccc2d8e4db63a0.tar.gz cpython-8c88e360e71c8fd456b261f5c5ccc2d8e4db63a0.tar.bz2 |
gh-95005: Replace PyAccu with PyUnicodeWriter (gh-95006)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/stringio.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index 3fe02d3..0f31c17 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -1,7 +1,6 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" #include <stddef.h> // offsetof() -#include "pycore_accu.h" #include "pycore_object.h" #include "_iomodule.h" @@ -27,12 +26,12 @@ typedef struct { /* The stringio object can be in two states: accumulating or realized. In accumulating state, the internal buffer contains nothing and - the contents are given by the embedded _PyAccu structure. + the contents are given by the embedded _PyUnicodeWriter structure. In realized state, the internal buffer is meaningful and the - _PyAccu is destroyed. + _PyUnicodeWriter is destroyed. */ int state; - _PyAccu accu; + _PyUnicodeWriter writer; char ok; /* initialized? */ char closed; @@ -126,12 +125,14 @@ resize_buffer(stringio *self, size_t size) static PyObject * make_intermediate(stringio *self) { - PyObject *intermediate = _PyAccu_Finish(&self->accu); + PyObject *intermediate = _PyUnicodeWriter_Finish(&self->writer); self->state = STATE_REALIZED; if (intermediate == NULL) return NULL; - if (_PyAccu_Init(&self->accu) || - _PyAccu_Accumulate(&self->accu, intermediate)) { + + _PyUnicodeWriter_Init(&self->writer); + self->writer.overallocate = 1; + if (_PyUnicodeWriter_WriteStr(&self->writer, intermediate)) { Py_DECREF(intermediate); return NULL; } @@ -150,7 +151,7 @@ realize(stringio *self) assert(self->state == STATE_ACCUMULATING); self->state = STATE_REALIZED; - intermediate = _PyAccu_Finish(&self->accu); + intermediate = _PyUnicodeWriter_Finish(&self->writer); if (intermediate == NULL) return -1; @@ -218,7 +219,7 @@ write_str(stringio *self, PyObject *obj) if (self->state == STATE_ACCUMULATING) { if (self->string_size == self->pos) { - if (_PyAccu_Accumulate(&self->accu, decoded)) + if (_PyUnicodeWriter_WriteStr(&self->writer, decoded)) goto fail; goto success; } @@ -572,7 +573,7 @@ _io_StringIO_close_impl(stringio *self) /* Free up some memory */ if (resize_buffer(self, 0) < 0) return NULL; - _PyAccu_Destroy(&self->accu); + _PyUnicodeWriter_Dealloc(&self->writer); Py_CLEAR(self->readnl); Py_CLEAR(self->writenl); Py_CLEAR(self->decoder); @@ -602,7 +603,7 @@ stringio_dealloc(stringio *self) PyMem_Free(self->buf); self->buf = NULL; } - _PyAccu_Destroy(&self->accu); + _PyUnicodeWriter_Dealloc(&self->writer); Py_CLEAR(self->readnl); Py_CLEAR(self->writenl); Py_CLEAR(self->decoder); @@ -687,7 +688,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value, self->ok = 0; - _PyAccu_Destroy(&self->accu); + _PyUnicodeWriter_Dealloc(&self->writer); Py_CLEAR(self->readnl); Py_CLEAR(self->writenl); Py_CLEAR(self->decoder); @@ -742,8 +743,8 @@ _io_StringIO___init___impl(stringio *self, PyObject *value, /* Empty stringio object, we can start by accumulating */ if (resize_buffer(self, 0) < 0) return -1; - if (_PyAccu_Init(&self->accu)) - return -1; + _PyUnicodeWriter_Init(&self->writer); + self->writer.overallocate = 1; self->state = STATE_ACCUMULATING; } self->pos = 0; |