Skip to content

Add weakref support to Struct types - #131

Merged
jcrist merged 2 commits into
mainfrom
struct-weakref
Jun 27, 2022
Merged

Add weakref support to Struct types#131
jcrist merged 2 commits into
mainfrom
struct-weakref

Conversation

@jcrist

@jcrist jcrist commented Jun 27, 2022

Copy link
Copy Markdown
Member

This adds a new weakref config option for structs. If True, instances of the struct type will support weakrefs. Defaults to False.

This was requested by a user for quickle (jcrist/quickle#63), which isn't actively maintained, but is the predecessor for msgspec. It was easy enough to add, and uncovered a few subtle bugs (fixed here):

  • Fixes a bug when deallocating long chains of Struct instances, which requires trashcan support. Previously the freelist interactions were done outside of the TRASHCAN macros, which was incorrect.
  • Fixes a bug where Struct types with a __del__ method and GC support interacted poorly with the freelist, potentially causing reused instances to fail to run their __del__ method.

jcrist added 2 commits June 27, 2022 16:43
This adds a new `weakref` config option for structs. If `True`,
instances of the struct type will support weakrefs. Defaults to False.

This also fixes a few subtle (and unlikely) bugs in the `Struct_dealloc`
implementation:
- Fixes a bug when deallocating long chains of Struct instances, which
requires trashcan support. Previously the freelist interactions were
done outside of the TRASHCAN macros, which was incorrect.
- Fixes a bug where `Struct` types with a `__del__` method and GC
support interacted poorly with the freelist, potentially causing reused
instances to fail to run their `__del__` method.
@jcrist
jcrist merged commit a35f5ea into main Jun 27, 2022
@jcrist
jcrist deleted the struct-weakref branch June 27, 2022 22:02
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.

1 participant