Feature or enhancement
The _struct module has a few small issues:
- The use of
PyDict_GetItemWithError returns a borrowed reference (should use PyDict_GetItemRef)
- The
state->cache is lazily created; we should instead create it during _structmodule_exec
- We want
state->cache to be an immutable reference to a mutable dict. (The dict will be thread-safe.) Use PyDict_Clear to empty the dict instead of clearing the reference.
See the commit from the nogil-3.12 fork for context: colesbury/nogil-3.12@ada9b73feb. Note that in CPython the relevant function is PyDict_GetItemRef not PyDict_FetchItemWithError.
Linked PRs
Feature or enhancement
The
_structmodule has a few small issues:PyDict_GetItemWithErrorreturns a borrowed reference (should usePyDict_GetItemRef)state->cacheis lazily created; we should instead create it during_structmodule_execstate->cacheto be an immutable reference to a mutable dict. (Thedictwill be thread-safe.) UsePyDict_Clearto empty the dict instead of clearing the reference.See the commit from the
nogil-3.12fork for context: colesbury/nogil-3.12@ada9b73feb. Note that in CPython the relevant function isPyDict_GetItemRefnotPyDict_FetchItemWithError.Linked PRs
_structmodule thread-safe in--disable-gilbuilds #112094