@@ -30,7 +30,7 @@ typedef struct {
3030 _PyUnicodeWriter is destroyed.
3131 */
3232 int state ;
33- _PyUnicodeWriter writer ;
33+ PyUnicodeWriter * writer ;
3434
3535 char ok ; /* initialized? */
3636 char closed ;
@@ -129,14 +129,18 @@ resize_buffer(stringio *self, size_t size)
129129static PyObject *
130130make_intermediate (stringio * self )
131131{
132- PyObject * intermediate = _PyUnicodeWriter_Finish (& self -> writer );
132+ PyObject * intermediate = PyUnicodeWriter_Finish (self -> writer );
133+ self -> writer = NULL ;
133134 self -> state = STATE_REALIZED ;
134135 if (intermediate == NULL )
135136 return NULL ;
136137
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 )) {
140144 Py_DECREF (intermediate );
141145 return NULL ;
142146 }
@@ -155,7 +159,8 @@ realize(stringio *self)
155159 assert (self -> state == STATE_ACCUMULATING );
156160 self -> state = STATE_REALIZED ;
157161
158- intermediate = _PyUnicodeWriter_Finish (& self -> writer );
162+ intermediate = PyUnicodeWriter_Finish (self -> writer );
163+ self -> writer = NULL ;
159164 if (intermediate == NULL )
160165 return -1 ;
161166
@@ -217,7 +222,7 @@ write_str(stringio *self, PyObject *obj)
217222
218223 if (self -> state == STATE_ACCUMULATING ) {
219224 if (self -> string_size == self -> pos ) {
220- if (_PyUnicodeWriter_WriteStr ( & self -> writer , decoded ))
225+ if (PyUnicodeWriter_WriteStr ( self -> writer , decoded ))
221226 goto fail ;
222227 goto success ;
223228 }
@@ -577,7 +582,8 @@ _io_StringIO_close_impl(stringio *self)
577582 /* Free up some memory */
578583 if (resize_buffer (self , 0 ) < 0 )
579584 return NULL ;
580- _PyUnicodeWriter_Dealloc (& self -> writer );
585+ PyUnicodeWriter_Discard (self -> writer );
586+ self -> writer = NULL ;
581587 Py_CLEAR (self -> readnl );
582588 Py_CLEAR (self -> writenl );
583589 Py_CLEAR (self -> decoder );
@@ -615,7 +621,7 @@ stringio_dealloc(stringio *self)
615621 PyMem_Free (self -> buf );
616622 self -> buf = NULL ;
617623 }
618- _PyUnicodeWriter_Dealloc ( & self -> writer );
624+ PyUnicodeWriter_Discard ( self -> writer );
619625 (void )stringio_clear (self );
620626 if (self -> weakreflist != NULL ) {
621627 PyObject_ClearWeakRefs ((PyObject * ) self );
@@ -699,7 +705,8 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
699705
700706 self -> ok = 0 ;
701707
702- _PyUnicodeWriter_Dealloc (& self -> writer );
708+ PyUnicodeWriter_Discard (self -> writer );
709+ self -> writer = NULL ;
703710 Py_CLEAR (self -> readnl );
704711 Py_CLEAR (self -> writenl );
705712 Py_CLEAR (self -> decoder );
@@ -754,8 +761,10 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
754761 /* Empty stringio object, we can start by accumulating */
755762 if (resize_buffer (self , 0 ) < 0 )
756763 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+ }
759768 self -> state = STATE_ACCUMULATING ;
760769 }
761770 self -> pos = 0 ;
0 commit comments