8000 gh-135552: Skip clearing of tp_subclasses weakrefs in GC by sergey-miryanov · Pull Request #136147 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135552: Skip clearing of tp_subclasses weakrefs in GC #136147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f14f0ba
Reset type cache after finalization
sergey-miryanov Jun 19, 2025
61fc657
Add tests
fxeqxmulfx Jun 22, 2025
d8124a9
Organize tests
sergey-miryanov Jun 22, 2025
bb21510
Remove wrong solution
sergey-miryanov Jun 22, 2025
0e649ab
Do not clear weakrefs to types before finalization of instances
sergey-miryanov Jun 22, 2025
ff79617
Merge branch 'main' into gh-135552-fix-gc-segfault
sergey-miryanov Jun 22, 2025
ac394bc
Add news
sergey-miryanov Jun 22, 2025
3b18738
Update Misc/NEWS.d/next/Core_and_Builtins/2025-06-23-01-07-09.gh-issu…
sergey-miryanov Jun 23, 2025
de8841c
Update Misc/NEWS.d/next/Core_and_Builtins/2025-06-23-01-07-09.gh-issu…
sergey-miryanov Jun 23, 2025
f8745e0
Split unreachable to types and objects while deduce
sergey-miryanov Jun 23, 2025
f166933
Merge branch 'gh-135552-fix-gc-segfault' of github.com:sergey-miryano…
sergey-miryanov Jun 23, 2025
3fe0f15
Simplify tests
sergey-miryanov Jun 24, 2025
96f09db
Merge branch 'main' into gh-135552-fix-gc-segfault-2
sergey-miryanov Jun 30, 2025
1ad18ec
Remove unreachable_types pass
sergey-miryanov Jun 30, 2025
bc0297c
Remove obsolete comments
sergey-miryanov Jun 30, 2025
3294f2e
Add is_subclass to PyWeakReference and do not clear those weakrefs in GC
sergey-miryanov Jun 30, 2025
6c45159
Create weakrefs for subclasses with sentinel callback to properly han…
sergey-miryanov Jul 1, 2025
e5e95ff
Update news entry
sergey-miryanov Jul 1, 2025
edf634c
Add some comments
sergey-miryanov Jul 1, 2025
bd7d9f3
Crazy idea to use noop-callback as a sentinel
sergey-miryanov Jul 2, 2025
987f6a3
Immortalize sentinel callback
sergey-miryanov Jul 2, 2025
be87675
Clear weakref sentinel in the right place
sergey-miryanov Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add is_subclass to PyWeakReference and do not clear those weakrefs in GC
  • Loading branch information
sergey-miryanov committed Jun 30, 2025
commit 3294f2e4cec9c4705fdd338a8b49b6e1a6c84e9f
1 change: 1 addition & 0 deletions Include/cpython/weakrefobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct _PyWeakReference {
*/
PyMutex *weakrefs_lock;
#endif
uint8_t is_subclass;
};

PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
Expand Down
3 changes: 3 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9265,6 +9265,9 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
return -1;
}

((PyWeakReference*)ref)->is_subclass = 1;


// Only get tp_subclasses after creating the key and value.
// PyWeakref_NewRef() can trigger a garbage collec 8000 tion which can execute
// arbitrary Python code and so modify base->tp_subclasses.
Expand Down
1 change: 1 addition & 0 deletions Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ init_weakref(PyWeakReference *self, PyObject *ob, PyObject *callback)
_PyObject_SetMaybeWeakref(ob);
_PyObject_SetMaybeWeakref((PyObject *)self);
#endif
self->is_subclass = 0;
}

// Clear the weakref and steal its callback into `callback`, if provided.
Expand Down
Loading
0