gh-127945: make initialization of error_object_name thread safe in ctypes (#131896)

This commit is contained in:
Kumar Aditya 2025-03-30 16:20:35 +05:30 committed by GitHub
parent bc5a028c13
commit 28e476f6a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View file

@ -6093,14 +6093,19 @@ _ctypes_mod_exec(PyObject *mod)
}
#ifdef WORDS_BIGENDIAN
st->swapped_suffix = PyUnicode_InternFromString("_le");
st->swapped_suffix = PyUnicode_InternFromString("_le");
#else
st->swapped_suffix = PyUnicode_InternFromString("_be");
st->swapped_suffix = PyUnicode_InternFromString("_be");
#endif
if (st->swapped_suffix == NULL) {
return -1;
}
st->error_object_name = PyUnicode_InternFromString("ctypes.error_object");
if (st->error_object_name == NULL) {
return -1;
}
if (_ctypes_add_types(mod) < 0) {
return -1;
}

View file

@ -164,12 +164,7 @@ _ctypes_get_errobj(ctypes_state *st, int **pspace)
"cannot get thread state");
return NULL;
}
if (st->error_object_name == NULL) {
st->error_object_name = PyUnicode_InternFromString("ctypes.error_object");
if (st->error_object_name == NULL) {
return NULL;
}
}
assert(st->error_object_name != NULL);
if (PyDict_GetItemRef(dict, st->error_object_name, &errobj) < 0) {
return NULL;
}