@@ -30,7 +30,7 @@ typedef struct {
30
30
_PyUnicodeWriter is destroyed.
31
31
*/
32
32
int state ;
33
- _PyUnicodeWriter writer ;
33
+ PyUnicodeWriter * writer ;
34
34
35
35
char ok ; /* initialized? */
36
36
char closed ;
@@ -129,14 +129,18 @@ resize_buffer(stringio *self, size_t size)
129
129
static PyObject *
130
130
make_intermediate (stringio * self )
131
131
{
132
- PyObject * intermediate = _PyUnicodeWriter_Finish (& self -> writer );
132
+ PyObject * intermediate = PyUnicodeWriter_Finish (self -> writer );
133
+ self -> writer = NULL ;
133
134
self -> state = STATE_REALIZED ;
134
135
if (intermediate == NULL )
135
136
return NULL ;
136
137
137
- _PyUnicodeWriter_Init (& self -> writer );
138
- self -> writer .overallocate = 1 ;
139
- if (_PyUnicodeWriter_WriteStr (& self -> writer , intermediate )) {
138
+ self -> writer = PyUnicodeWriter_Create (0 );
139
+ if (self -> writer == NULL ) {
140
+ Py_DECREF (intermediate );
141
+ return NULL ;
142
+ }
143
+ if (PyUnicodeWriter_WriteStr (self -> writer , intermediate )) {
140
144
Py_DECREF (intermediate );
141
145
return NULL ;
142
146
}
@@ -155,7 +159,8 @@ realize(stringio *self)
155
159
assert (self -> state == STATE_ACCUMULATING );
156
160
self -> state = STATE_REALIZED ;
157
161
158
- intermediate = _PyUnicodeWriter_Finish (& self -> writer );
162
+ intermediate = PyUnicodeWriter_Finish (self -> writer );
163
+ self -> writer = NULL ;
159
164
if (intermediate == NULL )
160
165
return -1 ;
161
166
@@ -217,7 +222,7 @@ write_str(stringio *self, PyObject *obj)
217
222
218
223
if (self -> state == STATE_ACCUMULATING ) {
219
224
if (self -> string_size == self -> pos ) {
220
- if (_PyUnicodeWriter_WriteStr ( & self -> writer , decoded ))
225
+ if (PyUnicodeWriter_WriteStr ( self -> writer , decoded ))
221
226
goto fail ;
222
227
goto success ;
223
228
}
@@ -577,7 +582,8 @@ _io_StringIO_close_impl(stringio *self)
577
582
/* Free up some memory */
578
583
if (resize_buffer (self , 0 ) < 0 )
579
584
return NULL ;
580
- _PyUnicodeWriter_Dealloc (& self -> writer );
585
+ PyUnicodeWriter_Discard (self -> writer );
586
+ self -> writer = NULL ;
581
587
Py_CLEAR (self -> readnl );
582
588
Py_CLEAR (self -> writenl );
583
589
Py_CLEAR (self -> decoder );
@@ -615,7 +621,7 @@ stringio_dealloc(stringio *self)
615
621
PyMem_Free (self -> buf );
616
622
self -> buf = NULL ;
617
623
}
618
- _PyUnicodeWriter_Dealloc ( & self -> writer );
624
+ PyUnicodeWriter_Discard ( self -> writer );
619
625
(void )stringio_clear (self );
620
626
if (self -> weakreflist != NULL ) {
621
627
PyObject_ClearWeakRefs ((PyObject * ) self );
@@ -699,7 +705,8 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
699
705
700
706
self -> ok = 0 ;
701
707
702
- _PyUnicodeWriter_Dealloc (& self -> writer );
708
+ PyUnicodeWriter_Discard (self -> writer );
709
+ self -> writer = NULL ;
703
710
Py_CLEAR (self -> readnl );
704
711
Py_CLEAR (self -> writenl );
705
712
Py_CLEAR (self -> decoder );
@@ -754,8 +761,10 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
754
761
/* Empty stringio object, we can start by accumulating */
755
762
if (resize_buffer (self , 0 ) < 0 )
756
763
return -1 ;
757
- _PyUnicodeWriter_Init (& self -> writer );
758
- self -> writer .overallocate = 1 ;
764
+ self -> writer = PyUnicodeWriter_Create (0 );
765
+ if (self -> writer == NULL ) {
766
+ return -1 ;
767
+ }
759
768
self -> state = STATE_ACCUMULATING ;
760
769
}
761
770
self -> pos = 0 ;
0 commit comments