@@ -853,21 +853,18 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
853853
854854PyObject  * PyCodec_BackslashReplaceErrors (PyObject  * exc )
855855{
856-     Py_ssize_t  start , end ;
856+     PyObject  * obj ;
857+     Py_ssize_t  objlen , start , end ;
857858    if  (PyObject_TypeCheck (exc , (PyTypeObject  * )PyExc_UnicodeDecodeError )) {
858-         if  (PyUnicodeDecodeError_GetStart (exc , & start ) <  0 ) {
859-             return  NULL ;
860-         }
861-         if  (PyUnicodeDecodeError_GetEnd (exc , & end ) <  0 ) {
859+         if  (_PyUnicodeError_GetParams (exc ,
860+                                       & obj , & objlen , & start , & end , true) <  0 )
861+         {
862862            return  NULL ;
863863        }
864864        if  (end  <= start ) {
865+             Py_DECREF (obj );
865866            goto oob ;
866867        }
867-         PyObject  * obj  =  PyUnicodeDecodeError_GetObject (exc );
868-         if  (obj  ==  NULL ) {
869-             return  NULL ;
870-         }
871868        const  unsigned char   * p  =  (const  unsigned char   * )PyBytes_AS_STRING (obj );
872869        PyObject  * res  =  PyUnicode_New (4  *  (end  -  start ), 127 );
873870        if  (res  ==  NULL ) {
@@ -887,33 +884,21 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
887884        return  Py_BuildValue ("(Nn)" , res , end );
888885    }
889886
890-     PyObject  * obj  =  NULL ;
891-     if  (PyObject_TypeCheck (exc , (PyTypeObject  * )PyExc_UnicodeEncodeError )) {
892-         if  (PyUnicodeEncodeError_GetStart (exc , & start ) <  0 ) {
893-             return  NULL ;
894-         }
895-         if  (PyUnicodeEncodeError_GetEnd (exc , & end ) <  0 ) {
896-             return  NULL ;
897-         }
898-         obj  =  PyUnicodeEncodeError_GetObject (exc );
899-     }
900-     else  if  (PyObject_TypeCheck (exc , (PyTypeObject  * )PyExc_UnicodeTranslateError )) {
901-         if  (PyUnicodeTranslateError_GetStart (exc , & start ) <  0 ) {
902-             return  NULL ;
903-         }
904-         if  (PyUnicodeTranslateError_GetEnd (exc , & end ) <  0 ) {
887+     if  (
888+         PyObject_TypeCheck (exc , (PyTypeObject  * )PyExc_UnicodeEncodeError )
889+         ||  PyObject_TypeCheck (exc , (PyTypeObject  * )PyExc_UnicodeTranslateError )
890+     ) {
891+         if  (_PyUnicodeError_GetParams (exc ,
892+                                       & obj , & objlen , & start , & end , false) <  0 )
893+         {
905894            return  NULL ;
906895        }
907-         obj  =  PyUnicodeTranslateError_GetObject (exc );
908896    }
909897    else  {
910898        wrong_exception_type (exc );
911899        return  NULL ;
912900    }
913901
914-     if  (obj  ==  NULL ) {
915-         return  NULL ;
916-     }
917902    if  (end  <= start ) {
918903        Py_DECREF (obj );
919904        goto oob ;
0 commit comments