1
1
#define PY_SSIZE_T_CLEAN
2
2
#include "Python.h"
3
3
#include <stddef.h> // offsetof()
4
- #include "pycore_accu.h"
5
4
#include "pycore_object.h"
6
5
#include "_iomodule.h"
7
6
@@ -27,12 +26,12 @@ typedef struct {
27
26
28
27
/* The stringio object can be in two states: accumulating or realized.
29
28
In accumulating state, the internal buffer contains nothing and
30
- the contents are given by the embedded _PyAccu structure.
29
+ the contents are given by the embedded _PyUnicodeWriter structure.
31
30
In realized state, the internal buffer is meaningful and the
32
- _PyAccu is destroyed.
31
+ _PyUnicodeWriter is destroyed.
33
32
*/
34
33
int state ;
35
- _PyAccu accu ;
34
+ _PyUnicodeWriter writer ;
36
35
37
36
char ok ; /* initialized? */
38
37
char closed ;
@@ -126,12 +125,14 @@ resize_buffer(stringio *self, size_t size)
126
125
static PyObject *
127
126
make_intermediate (stringio * self )
128
127
{
129
- PyObject * intermediate = _PyAccu_Finish (& self -> accu );
128
+ PyObject * intermediate = _PyUnicodeWriter_Finish (& self -> writer );
130
129
self -> state = STATE_REALIZED ;
131
130
if (intermediate == NULL )
132
131
return NULL ;
133
- if (_PyAccu_Init (& self -> accu ) ||
134
- _PyAccu_Accumulate (& self -> accu , intermediate )) {
132
+
133
+ _PyUnicodeWriter_Init (& self -> writer );
134
+ self -> writer .overallocate = 1 ;
135
+ if (_PyUnicodeWriter_WriteStr (& self -> writer , intermediate )) {
135
136
Py_DECREF (intermediate );
136
137
return NULL ;
137
138
}
@@ -150,7 +151,7 @@ realize(stringio *self)
150
151
assert (self -> state == STATE_ACCUMULATING );
151
152
self -> state = STATE_REALIZED ;
152
153
153
- intermediate = _PyAccu_Finish (& self -> accu );
154
+ intermediate = _PyUnicodeWriter_Finish (& self -> writer );
154
155
if (intermediate == NULL )
155
156
return -1 ;
156
157
@@ -218,7 +219,7 @@ write_str(stringio *self, PyObject *obj)
218
219
219
220
if (self -> state == STATE_ACCUMULATING ) {
220
221
if (self -> string_size == self -> pos ) {
221
- if (_PyAccu_Accumulate (& self -> accu , decoded ))
222
+ if (_PyUnicodeWriter_WriteStr (& self -> writer , decoded ))
222
223
goto fail ;
223
224
goto success ;
224
225
}
@@ -572,7 +573,7 @@ _io_StringIO_close_impl(stringio *self)
572
573
/* Free up some memory */
573
574
if (resize_buffer (self , 0 ) < 0 )
574
575
return NULL ;
575
- _PyAccu_Destroy (& self -> accu );
576
+ _PyUnicodeWriter_Dealloc (& self -> writer );
576
577
Py_CLEAR (self -> readnl );
577
578
Py_CLEAR (self -> writenl );
578
579
Py_CLEAR (self -> decoder );
@@ -602,7 +603,7 @@ stringio_dealloc(stringio *self)
602
603
PyMem_Free (self -> buf );
603
604
self -> buf = NULL ;
604
605
}
605
- _PyAccu_Destroy (& self -> accu );
606
+ _PyUnicodeWriter_Dealloc (& self -> writer );
606
607
Py_CLEAR (self -> readnl );
607
608
Py_CLEAR (self -> writenl );
608
609
Py_CLEAR (self -> decoder );
@@ -687,7 +688,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
687
688
688
689
self -> ok = 0 ;
689
690
690
- _PyAccu_Destroy (& self -> accu );
691
+ _PyUnicodeWriter_Dealloc (& self -> writer );
691
692
Py_CLEAR (self -> readnl );
692
693
Py_CLEAR (self -> writenl );
693
694
Py_CLEAR (self -> decoder );
@@ -742,8 +743,8 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
742
743
/* Empty stringio object, we can start by accumulating */
743
744
if (resize_buffer (self , 0 ) < 0 )
744
745
return -1 ;
745
- if ( _PyAccu_Init ( & self -> accu ))
746
- return - 1 ;
746
+ _PyUnicodeWriter_Init ( & self -> writer );
747
+ self -> writer . overallocate = 1 ;
747
748
self -> state = STATE_ACCUMULATING ;
748
749
}
749
750
self -> pos = 0 ;
0 commit comments