@@ -2940,21 +2940,19 @@ _PyBytes_FromTuple(PyObject *x)
29402940static PyObject *
29412941_PyBytes_FromIterator (PyObject * it , PyObject * x )
29422942{
2943- char * str ;
29442943 Py_ssize_t i , size ;
2945- _PyBytesWriter writer ;
29462944
29472945 /* For iterator version, create a bytes object and resize as needed */
29482946 size = PyObject_LengthHint (x , 64 );
29492947 if (size == -1 && PyErr_Occurred ())
29502948 return NULL ;
29512949
2952- _PyBytesWriter_Init (& writer );
2953- str = _PyBytesWriter_Alloc (& writer , size );
2954- if (str == NULL )
2950+ PyBytesWriter * writer = PyBytesWriter_Create (size );
2951+ if (writer == NULL ) {
29552952 return NULL ;
2956- writer .overallocate = 1 ;
2957- size = writer .allocated ;
2953+ }
2954+ char * str = PyBytesWriter_GetData (writer );
2955+ size = PyBytesWriter_GetAllocated (writer );
29582956
29592957 /* Run the iterator to exhaustion */
29602958 for (i = 0 ; ; i ++ ) {
@@ -2984,18 +2982,18 @@ _PyBytes_FromIterator(PyObject *it, PyObject *x)
29842982
29852983 /* Append the byte */
29862984 if (i >= size ) {
2987- str = _PyBytesWriter_Resize (& writer , str , size + 1 );
2988- if (str == NULL )
2989- return NULL ;
2990- size = writer .allocated ;
2985+ str = PyBytesWriter_ResizeAndUpdatePointer (writer , size + 1 , str );
2986+ if (str == NULL ) {
2987+ goto error ;
2988+ }
2989+ size = PyBytesWriter_GetAllocated (writer );
29912990 }
29922991 * str ++ = (char ) value ;
29932992 }
2994-
2995- return _PyBytesWriter_Finish (& writer , str );
2993+ return PyBytesWriter_FinishWithEndPointer (writer , str );
29962994
29972995 error :
2998- _PyBytesWriter_Dealloc ( & writer );
2996+ PyBytesWriter_Discard ( writer );
29992997 return NULL ;
30002998}
30012999
0 commit comments