mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
gh-125859: Fix crash when gc.get_objects is called during GC (#125882)
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is called during a GC in the free threading build. Switch to `_PyObjectStack` to avoid corrupting the `struct worklist` linked list maintained by the GC. Also, don't return objects that are frozen (`gc.freeze()`) or in the process of being collected to more closely match the behavior of the default build.
This commit is contained in:
parent
b61fece852
commit
e545ead66c
5 changed files with 160 additions and 73 deletions
|
|
@ -71,6 +71,16 @@ _PyObjectStack_Pop(_PyObjectStack *stack)
|
|||
return obj;
|
||||
}
|
||||
|
||||
static inline Py_ssize_t
|
||||
_PyObjectStack_Size(_PyObjectStack *stack)
|
||||
{
|
||||
Py_ssize_t size = 0;
|
||||
for (_PyObjectStackChunk *buf = stack->head; buf != NULL; buf = buf->prev) {
|
||||
size += buf->n;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
// Merge src into dst, leaving src empty
|
||||
extern void
|
||||
_PyObjectStack_Merge(_PyObjectStack *dst, _PyObjectStack *src);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue