summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorKirill Podoprigora <kirill.bast9@mail.ru>2023-11-30 10:12:49 (GMT)
committerGitHub <noreply@github.com>2023-11-30 10:12:49 (GMT)
commit0785c685599aaa052f85d6163872bdecb9c66486 (patch)
tree269bcf13cdd75f338d3539126d6dd0021846fdd7 /Python
parent81261fa67ff82b03c255733b0d1abbbb8a228187 (diff)
downloadcpython-0785c685599aaa052f85d6163872bdecb9c66486.zip
cpython-0785c685599aaa052f85d6163872bdecb9c66486.tar.gz
cpython-0785c685599aaa052f85d6163872bdecb9c66486.tar.bz2
gh-111972: Make Unicode name C APIcapsule initialization thread-safe (#112249)
Diffstat (limited to 'Python')
-rw-r--r--Python/codecs.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 545bf82..d8fe7b2 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -931,8 +931,6 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
return Py_BuildValue("(Nn)", res, end);
}
-static _PyUnicode_Name_CAPI *ucnhash_capi = NULL;
-
PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
{
if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeEncodeError)) {
@@ -953,13 +951,9 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
return NULL;
if (!(object = PyUnicodeEncodeError_GetObject(exc)))
return NULL;
- if (!ucnhash_capi) {
- /* load the unicode data module */
- ucnhash_capi = (_PyUnicode_Name_CAPI *)PyCapsule_Import(
- PyUnicodeData_CAPSULE_NAME, 1);
- if (!ucnhash_capi) {
- return NULL;
- }
+ _PyUnicode_Name_CAPI *ucnhash_capi = _PyUnicode_GetNameCAPI();
+ if (ucnhash_capi == NULL) {
+ return NULL;
}
for (i = start, ressize = 0; i < end; ++i) {
/* object is guaranteed to be "ready" */