@@ -795,6 +795,31 @@ writer_finish(PyObject *self_raw, PyObject *Py_UNUSED(args))
795795}
796796
797797
798+ static PyObject *
799+ writer_finish_with_size (PyObject * self_raw , PyObject * args )
800+ {
801+ PyAPI_FUNC (PyObject * ) _PyUnicodeWriter_FinishWithSize (
802+ _PyUnicodeWriter * writer ,
803+ Py_ssize_t size );
804+
805+ WriterObject * self = (WriterObject * )self_raw ;
806+ if (writer_check (self ) < 0 ) {
807+ return NULL ;
808+ }
809+
810+ Py_ssize_t size ;
811+ if (!PyArg_ParseTuple (args , "n" , & size )) {
812+ return NULL ;
813+ }
814+
815+ _PyUnicodeWriter * writer = (_PyUnicodeWriter * )self -> writer ;
816+ PyObject * str = _PyUnicodeWriter_FinishWithSize (writer , size );
817+ PyUnicodeWriter_Discard (self -> writer );
818+ self -> writer = NULL ;
819+ return str ;
820+ }
821+
822+
798823static PyMethodDef writer_methods [] = {
799824 {"write_char" , _PyCFunction_CAST (writer_write_char ), METH_VARARGS },
800825 {"write_utf8" , _PyCFunction_CAST (writer_write_utf8 ), METH_VARARGS },
@@ -809,6 +834,7 @@ static PyMethodDef writer_methods[] = {
809834 {"get_pointer" , _PyCFunction_CAST (writer_get_pointer ), METH_VARARGS },
810835 {"get_buffer" , _PyCFunction_CAST (writer_get_buffer ), METH_VARARGS },
811836 {"finish" , _PyCFunction_CAST (writer_finish ), METH_NOARGS },
837+ {"finish_with_size" , _PyCFunction_CAST (writer_finish_with_size ), METH_VARARGS },
812838 {NULL , NULL } /* sentinel */
813839};
814840
0 commit comments