File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1426,26 +1426,27 @@ _PyCodec_SurrogateEscapeUnicodeEncodeError(PyObject *exc)
14261426 return NULL ;
14271427 }
14281428
1429- PyObject * res = PyBytes_FromStringAndSize ( NULL , slen );
1430- if (res == NULL ) {
1429+ PyBytesWriter * writer = PyBytesWriter_Create ( slen );
1430+ if (writer == NULL ) {
14311431 Py_DECREF (obj );
14321432 return NULL ;
14331433 }
14341434
1435- char * outp = PyBytes_AsString ( res );
1435+ char * outp = PyBytesWriter_GetData ( writer );
14361436 for (Py_ssize_t i = start ; i < end ; i ++ ) {
14371437 Py_UCS4 ch = PyUnicode_READ_CHAR (obj , i );
14381438 if (ch < 0xdc80 || ch > 0xdcff ) {
14391439 /* Not a UTF-8b surrogate, fail with original exception. */
14401440 Py_DECREF (obj );
1441- Py_DECREF ( res );
1441+ PyBytesWriter_Discard ( writer );
14421442 PyErr_SetObject (PyExceptionInstance_Class (exc ), exc );
14431443 return NULL ;
14441444 }
14451445 * outp ++ = ch - 0xdc00 ;
14461446 }
14471447 Py_DECREF (obj );
14481448
1449+ PyObject * res = PyBytesWriter_Finish (writer ); // can be NULL
14491450 return Py_BuildValue ("(Nn)" , res , end );
14501451}
14511452
You can’t perform that action at this time.
0 commit comments