File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -356,26 +356,24 @@ The bytes objects frm and to must be of the same length.");
356356PyObject *
357357_Py_bytes_maketrans (Py_buffer * frm , Py_buffer * to )
358358{
359- PyObject * res = NULL ;
360- Py_ssize_t i ;
361- char * p ;
362-
363359 if (frm -> len != to -> len ) {
364360 PyErr_Format (PyExc_ValueError ,
365361 "maketrans arguments must have same length" );
366362 return NULL ;
367363 }
368- res = PyBytes_FromStringAndSize ( NULL , 256 );
369- if (!res )
364+ PyBytesWriter * writer = PyBytesWriter_Create ( 256 );
365+ if (!writer ) {
370366 return NULL ;
371- p = PyBytes_AS_STRING (res );
367+ }
368+ char * p = PyBytesWriter_GetData (writer );
369+ Py_ssize_t i ;
372370 for (i = 0 ; i < 256 ; i ++ )
373371 p [i ] = (char ) i ;
374372 for (i = 0 ; i < frm -> len ; i ++ ) {
375373 p [((unsigned char * )frm -> buf )[i ]] = ((char * )to -> buf )[i ];
376374 }
377375
378- return res ;
376+ return PyBytesWriter_Finish ( writer ) ;
379377}
380378
381379#define FASTSEARCH fastsearch
You can’t perform that action at this time.
0 commit comments