Skip to content

Keep ob_tid, ob_ref_local, and ob_ref_shared fields valid across allocations in free-threaded build #115491

Closed
@colesbury

Description

@colesbury

Feature or enhancement

The free-threaded implementation of dict and list try avoid acquiring locks during read operations. To support this, we need to be able to access the reference count fields of Python objects after they are deallocated (and possibly reallocated). Some of this support is provided by #115103. Additionally, we need to ensure that the debug allocators do not overwrite these fields with "dead" bytes 0xDD, which might make the object look "alive" by having a non-zero reference count.

We still would like to overwrite the rest of the allocation (i.e., from ob_type onwards) to detect use-after-frees in debug builds.

See also: https://peps.python.org/pep-0703/#optimistically-avoiding-locking

Linked PRs

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions