Skip to content

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Aug 2, 2024

The PyStructSequence destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which tp_clear() was called.

Account for the non-sequence fields in tp_basicsize and use that,
along with Py_SIZE(), to compute the "real" size of a
PyStructSequence in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd1)

Co-authored-by: Sam Gross [email protected]

…ythonGH-122577)

The `PyStructSequence` destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which `tp_clear()` was called.

Account for the non-sequence fields in `tp_basicsize` and use that,
along with `Py_SIZE()`, to compute the "real" size of a
`PyStructSequence` in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd1)

Co-authored-by: Sam Gross <[email protected]>
@XuehaiPan
Copy link
Contributor

Out of curious, would this patch be included in Python 3.13.0rc2?

@Yhg1s Yhg1s merged commit 57ba3b0 into python:3.13 Sep 2, 2024
@Yhg1s
Copy link
Member

Yhg1s commented Sep 2, 2024

Out of curious, would this patch be included in Python 3.13.0rc2?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants