Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4744f59

Browse filesBrowse files
authored
gh-112062: Make _struct module thread-safe in --disable-gil builds (#112094)
* gh-112062: Make `_struct` module thread-safe in --disable-gil builds
1 parent 55f3cce commit 4744f59
Copy full SHA for 4744f59

File tree

Expand file treeCollapse file tree

1 file changed

+6
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-7
lines changed

‎Modules/_struct.c

Copy file name to clipboardExpand all lines: Modules/_struct.c
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,12 +2250,6 @@ cache_struct_converter(PyObject *module, PyObject *fmt, PyStructObject **ptr)
22502250
return 1;
22512251
}
22522252

2253-
if (state->cache == NULL) {
2254-
state->cache = PyDict_New();
2255-
if (state->cache == NULL)
2256-
return 0;
2257-
}
2258-
22592253
s_object = PyDict_GetItemWithError(state->cache, fmt);
22602254
if (s_object != NULL) {
22612255
*ptr = (PyStructObject *)Py_NewRef(s_object);
@@ -2288,7 +2282,7 @@ static PyObject *
22882282
_clearcache_impl(PyObject *module)
22892283
/*[clinic end generated code: output=ce4fb8a7bf7cb523 input=463eaae04bab3211]*/
22902284
{
2291-
Py_CLEAR(get_struct_state(module)->cache);
2285+
PyDict_Clear(get_struct_state(module)->cache);
22922286
Py_RETURN_NONE;
22932287
}
22942288

@@ -2512,6 +2506,11 @@ _structmodule_exec(PyObject *m)
25122506
{
25132507
_structmodulestate *state = get_struct_state(m);
25142508

2509+
state->cache = PyDict_New();
2510+
if (state->cache == NULL) {
2511+
return -1;
2512+
}
2513+
25152514
state->PyStructType = PyType_FromModuleAndSpec(
25162515
m, &PyStructType_spec, NULL);
25172516
if (state->PyStructType == NULL) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.