@@ -5697,8 +5697,6 @@ PyUnicode_AsUTF16String(PyObject *unicode)
5697
5697
5698
5698
/* --- Unicode Escape Codec ----------------------------------------------- */
5699
5699
5700
- static _PyUnicode_Name_CAPI * ucnhash_capi = NULL ;
5701
-
5702
5700
PyObject *
5703
5701
_PyUnicode_DecodeUnicodeEscapeInternal (const char * s ,
5704
5702
Py_ssize_t size ,
@@ -5711,6 +5709,8 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
5711
5709
const char * end ;
5712
5710
PyObject * errorHandler = NULL ;
5713
5711
PyObject * exc = NULL ;
5712
+ _PyUnicode_Name_CAPI * ucnhash_capi ;
5713
+ PyInterpreterState * interp = _PyInterpreterState_Get ();
5714
5714
5715
5715
// so we can remember if we've seen an invalid escape char or not
5716
5716
* first_invalid_escape = NULL ;
@@ -5858,6 +5858,7 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
5858
5858
5859
5859
/* \N{name} */
5860
5860
case 'N' :
5861
+ ucnhash_capi = interp -> unicode .ucnhash_capi ;
5861
5862
if (ucnhash_capi == NULL ) {
5862
5863
/* load the unicode data module */
5863
5864
ucnhash_capi = (_PyUnicode_Name_CAPI * )PyCapsule_Import (
@@ -5869,6 +5870,7 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
5869
5870
);
5870
5871
goto onError ;
5871
5872
}
5873
+ interp -> unicode .ucnhash_capi = ucnhash_capi ;
5872
5874
}
5873
5875
5874
5876
message = "malformed \\N character escape" ;
@@ -15128,10 +15130,10 @@ _PyUnicode_Fini(PyInterpreterState *interp)
15128
15130
assert (get_interned_dict () == NULL );
15129
15131
// bpo-47182: force a unicodedata CAPI capsule re-import on
15130
15132
// subsequent initialization of main interpreter.
15131
- ucnhash_capi = NULL ;
15132
15133
}
15133
15134
15134
15135
_PyUnicode_FiniEncodings (& state -> fs_codec );
15136
+ interp -> unicode .ucnhash_capi = NULL ;
15135
15137
15136
15138
unicode_clear_identifiers (state );
15137
15139
}
0 commit comments