Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit4744f59

Browse 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 parent55f3cce commit4744f59

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

‎Modules/_struct.c

Lines 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
return1;
22512251
}
22522252

2253-
if (state->cache==NULL) {
2254-
state->cache=PyDict_New();
2255-
if (state->cache==NULL)
2256-
return0;
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)

[8]ページ先頭

©2009-2025 Movatter.jp