@@ -661,18 +661,9 @@ PyObject *PyCodec_LookupError(const char *name)
661661
662662static void wrong_exception_type (PyObject * exc )
663663{
664- _Py_IDENTIFIER (__class__ );
665- _Py_IDENTIFIER (__name__ );
666- PyObject * type = _PyObject_GetAttrId (exc , & PyId___class__ );
667- if (type != NULL ) {
668- PyObject * name = _PyObject_GetAttrId (type , & PyId___name__ );
669- Py_DECREF (type );
670- if (name != NULL ) {
671- PyErr_Format (PyExc_TypeError ,
672- "don't know how to handle %S in error callback" , name );
673- Py_DECREF (name );
674- }
675- }
664+ PyErr_Format (PyExc_TypeError ,
665+ "don't know how to handle %.200s in error callback" ,
666+ exc -> ob_type -> tp_name );
676667}
677668
678669PyObject * PyCodec_StrictErrors (PyObject * exc )
@@ -688,15 +679,16 @@ PyObject *PyCodec_StrictErrors(PyObject *exc)
688679PyObject * PyCodec_IgnoreErrors (PyObject * exc )
689680{
690681 Py_ssize_t end ;
691- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
682+
683+ if (PyObject_TypeCheck (exc , (PyTypeObject * )PyExc_UnicodeEncodeError )) {
692684 if (PyUnicodeEncodeError_GetEnd (exc , & end ))
693685 return NULL ;
694686 }
695- else if (PyObject_IsInstance (exc , PyExc_UnicodeDecodeError )) {
687+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeDecodeError )) {
696688 if (PyUnicodeDecodeError_GetEnd (exc , & end ))
697689 return NULL ;
698690 }
699- else if (PyObject_IsInstance (exc , PyExc_UnicodeTranslateError )) {
691+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeTranslateError )) {
700692 if (PyUnicodeTranslateError_GetEnd (exc , & end ))
701693 return NULL ;
702694 }
@@ -712,7 +704,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
712704{
713705 Py_ssize_t start , end , i , len ;
714706
715- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
707+ if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeEncodeError )) {
716708 PyObject * res ;
717709 int kind ;
718710 void * data ;
@@ -731,14 +723,14 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
731723 assert (_PyUnicode_CheckConsistency (res , 1 ));
732724 return Py_BuildValue ("(Nn)" , res , end );
733725 }
734- else if (PyObject_IsInstance (exc , PyExc_UnicodeDecodeError )) {
726+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeDecodeError )) {
735727 if (PyUnicodeDecodeError_GetEnd (exc , & end ))
736728 return NULL ;
737729 return Py_BuildValue ("(Cn)" ,
738730 (int )Py_UNICODE_REPLACEMENT_CHARACTER ,
739731 end );
740732 }
741- else if (PyObject_IsInstance (exc , PyExc_UnicodeTranslateError )) {
733+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeTranslateError )) {
742734 PyObject * res ;
743735 int kind ;
744736 void * data ;
@@ -765,7 +757,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
765757
766758PyObject * PyCodec_XMLCharRefReplaceErrors (PyObject * exc )
767759{
768- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
760+ if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeEncodeError )) {
769761 PyObject * restuple ;
770762 PyObject * object ;
771763 Py_ssize_t i ;
@@ -863,7 +855,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
863855
864856PyObject * PyCodec_BackslashReplaceErrors (PyObject * exc )
865857{
866- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
858+ if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeEncodeError )) {
867859 PyObject * restuple ;
868860 PyObject * object ;
869861 Py_ssize_t i ;
@@ -1007,7 +999,8 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
1007999 Py_ssize_t start ;
10081000 Py_ssize_t end ;
10091001 PyObject * res ;
1010- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
1002+
1003+ if (PyObject_TypeCheck (exc , (PyTypeObject * )PyExc_UnicodeEncodeError )) {
10111004 unsigned char * outp ;
10121005 if (PyUnicodeEncodeError_GetStart (exc , & start ))
10131006 return NULL ;
@@ -1078,7 +1071,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
10781071 Py_DECREF (object );
10791072 return restuple ;
10801073 }
1081- else if (PyObject_IsInstance (exc , PyExc_UnicodeDecodeError )) {
1074+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeDecodeError )) {
10821075 unsigned char * p ;
10831076 Py_UCS4 ch = 0 ;
10841077 if (PyUnicodeDecodeError_GetStart (exc , & start ))
@@ -1157,7 +1150,8 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
11571150 Py_ssize_t start ;
11581151 Py_ssize_t end ;
11591152 PyObject * res ;
1160- if (PyObject_IsInstance (exc , PyExc_UnicodeEncodeError )) {
1153+
1154+ if (PyObject_TypeCheck (exc , (PyTypeObject * )PyExc_UnicodeEncodeError )) {
11611155 char * outp ;
11621156 if (PyUnicodeEncodeError_GetStart (exc , & start ))
11631157 return NULL ;
@@ -1188,7 +1182,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
11881182 Py_DECREF (object );
11891183 return restuple ;
11901184 }
1191- else if (PyObject_IsInstance (exc , PyExc_UnicodeDecodeError )) {
1185+ else if (PyObject_TypeCheck (exc , ( PyTypeObject * ) PyExc_UnicodeDecodeError )) {
11921186 PyObject * str ;
11931187 unsigned char * p ;
11941188 Py_UCS2 ch [4 ]; /* decode up to 4 bad bytes. */
0 commit comments