Skip to content

Commit 9f3ebfd

Browse files
kumaraditya303seehwan80
authored andcommitted
pythongh-127945: make initialization of error_object_name thread safe in ctypes (python#131896)
1 parent e352ae6 commit 9f3ebfd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Modules/_ctypes/_ctypes.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -6093,14 +6093,19 @@ _ctypes_mod_exec(PyObject *mod)
60936093
}
60946094

60956095
#ifdef WORDS_BIGENDIAN
6096-
st->swapped_suffix = PyUnicode_InternFromString("_le");
6096+
st->swapped_suffix = PyUnicode_InternFromString("_le");
60976097
#else
6098-
st->swapped_suffix = PyUnicode_InternFromString("_be");
6098+
st->swapped_suffix = PyUnicode_InternFromString("_be");
60996099
#endif
61006100
if (st->swapped_suffix == NULL) {
61016101
return -1;
61026102
}
61036103

6104+
st->error_object_name = PyUnicode_InternFromString("ctypes.error_object");
6105+
if (st->error_object_name == NULL) {
6106+
return -1;
6107+
}
6108+
61046109
if (_ctypes_add_types(mod) < 0) {
61056110
return -1;
61066111
}

Modules/_ctypes/callproc.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,7 @@ _ctypes_get_errobj(ctypes_state *st, int **pspace)
164164
"cannot get thread state");
165165
return NULL;
166166
}
167-
if (st->error_object_name == NULL) {
168-
st->error_object_name = PyUnicode_InternFromString("ctypes.error_object");
169-
if (st->error_object_name == NULL) {
170-
return NULL;
171-
}
172-
}
167+
assert(st->error_object_name != NULL);
173168
if (PyDict_GetItemRef(dict, st->error_object_name, &errobj) < 0) {
174169
return NULL;
175170
}

0 commit comments

Comments
 (0)