unicode: make ucnhash_capi initialization thread-safe in `--disable-gil` builds
Feature or enhancement
The _PyUnicode_Name_CAPI provides functions to get the name for a given Unicode character code and vice versa. It is lazily initialized and stored in the per-interpreter _Py_unicode_state:
| struct _Py_unicode_state { | |
| struct _Py_unicode_fs_codec fs_codec; | |
| _PyUnicode_Name_CAPI *ucnhash_capi; | |
| // Unicode identifiers (_Py_Identifier): see _PyUnicode_FromId() | |
| struct _Py_unicode_ids ids; | |
| }; |
The initialization of the ucnhash_capi isn't thread-safe without the GIL. (There can be a data race on reading and writing ucnhash_capi).
Mostly for my own reference, here are the similar modifications in the nogil-3.12 fork: colesbury/nogil-3.12@5d006db9fa