You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash on deallocator of type 'time.struct_time' during finalizing for free-threaded Python #122527
The GC is clearing the type's dictionary (i.e., _PyType_GetDict) before the structseq instances is freed, so the REAL_SIZE call fails. We're also not handling that failure, which leads to a crash.
The default build works because the GC happens to free the structseq instance first before calling tp_clear() on the type's dictionary, but I don't think the GC guarantees any ordering of tp_clear() calls.
Activity
Eclips4 commentedon Jul 31, 2024
Thanks for the report!
Confirmed on current main.
colesbury commentedon Jul 31, 2024
Bisected to:
(oops)
colesbury commentedon Jul 31, 2024
The problem is in
structseq_dealloc, theREAL_SIZE()call fails:cpython/Objects/structseq.c
Lines 116 to 131 in 8844197
REAL_SIZEis a macro that expands to:The GC is clearing the type's dictionary (i.e.,
_PyType_GetDict) before thestructseqinstances is freed, so theREAL_SIZEcall fails. We're also not handling that failure, which leads to a crash.The default build works because the GC happens to free the
structseqinstance first before callingtp_clear()on the type's dictionary, but I don't think the GC guarantees any ordering oftp_clear()calls.colesbury commentedon Jul 31, 2024
You can trigger a similar crash in the default build with some weirder code:
pythongh-122527: Fix a crash on deallocation of `PyStructSequence`
gh-122527: Fix a crash on deallocation of `PyStructSequence` (GH-122577)
pythongh-122527: Fix a crash on deallocation of `PyStructSequence` (p…
pythongh-122527: Fix a crash on deallocation of `PyStructSequence` (p…
pythongh-122527: Fix a crash on deallocation of `PyStructSequence` (p…
[3.13] gh-122527: Fix a crash on deallocation of `PyStructSequence` (G…
[3.12] gh-122527: Fix a crash on deallocation of `PyStructSequence` (G…
time.strptime()with lambda/function call triggers GC finalization error in Python 3.12 (struct_time n_fields missing in tp_clear) #148551 as a duplicate of this issue