@@ -966,7 +966,6 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
966
966
}
967
967
968
968
static _PyUnicode_Name_CAPI * ucnhash_CAPI = NULL ;
969
- static int ucnhash_initialized = 0 ;
970
969
971
970
PyObject * PyCodec_NameReplaceErrors (PyObject * exc )
972
971
{
@@ -988,17 +987,17 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
988
987
return NULL ;
989
988
if (!(object = PyUnicodeEncodeError_GetObject (exc )))
990
989
return NULL ;
991
- if (!ucnhash_initialized ) {
990
+ if (!ucnhash_CAPI ) {
992
991
/* load the unicode data module */
993
992
ucnhash_CAPI = (_PyUnicode_Name_CAPI * )PyCapsule_Import (
994
993
PyUnicodeData_CAPSULE_NAME , 1 );
995
- ucnhash_initialized = 1 ;
994
+ if (!ucnhash_CAPI )
995
+ return NULL ;
996
996
}
997
997
for (i = start , ressize = 0 ; i < end ; ++ i ) {
998
998
/* object is guaranteed to be "ready" */
999
999
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 )) {
1002
1001
replsize = 1 + 1 + 1 + (int )strlen (buffer )+ 1 ;
1003
1002
}
1004
1003
else if (c >= 0x10000 ) {
@@ -1021,8 +1020,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
1021
1020
i < end ; ++ i ) {
1022
1021
c = PyUnicode_READ_CHAR (object , i );
1023
1022
* 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 )) {
1026
1024
* outp ++ = 'N' ;
1027
1025
* outp ++ = '{' ;
1028
1026
strcpy ((char * )outp , buffer );
0 commit comments