@@ -966,7 +966,6 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
966966}
967967
968968static _PyUnicode_Name_CAPI * ucnhash_CAPI = NULL ;
969- static int ucnhash_initialized = 0 ;
970969
971970PyObject * PyCodec_NameReplaceErrors (PyObject * exc )
972971{
@@ -988,17 +987,17 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
988987 return NULL ;
989988 if (!(object = PyUnicodeEncodeError_GetObject (exc )))
990989 return NULL ;
991- if (!ucnhash_initialized ) {
990+ if (!ucnhash_CAPI ) {
992991 /* load the unicode data module */
993992 ucnhash_CAPI = (_PyUnicode_Name_CAPI * )PyCapsule_Import (
994993 PyUnicodeData_CAPSULE_NAME , 1 );
995- ucnhash_initialized = 1 ;
994+ if (!ucnhash_CAPI )
995+ return NULL ;
996996 }
997997 for (i = start , ressize = 0 ; i < end ; ++ i ) {
998998 /* object is guaranteed to be "ready" */
999999 c = PyUnicode_READ_CHAR (object , i );
1000- if (ucnhash_CAPI &&
1001- ucnhash_CAPI -> getname (NULL , c , buffer , sizeof (buffer ), 1 )) {
1000+ if (ucnhash_CAPI -> getname (NULL , c , buffer , sizeof (buffer ), 1 )) {
10021001 replsize = 1 + 1 + 1 + (int )strlen (buffer )+ 1 ;
10031002 }
10041003 else if (c >= 0x10000 ) {
@@ -1021,8 +1020,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
10211020 i < end ; ++ i ) {
10221021 c = PyUnicode_READ_CHAR (object , i );
10231022 * outp ++ = '\\' ;
1024- if (ucnhash_CAPI &&
1025- ucnhash_CAPI -> getname (NULL , c , buffer , sizeof (buffer ), 1 )) {
1023+ if (ucnhash_CAPI -> getname (NULL , c , buffer , sizeof (buffer ), 1 )) {
10261024 * outp ++ = 'N' ;
10271025 * outp ++ = '{' ;
10281026 strcpy ((char * )outp , buffer );
0 commit comments