8000 GH-124715: Move trashcan mechanism into `Py_Dealloc` by markshannon · Pull Request #132280 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-124715: Move trashcan mechanism into Py_Dealloc #132280

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

Merged
merged 9 commits into from
Apr 30, 2025
Merged
Changes from 1 commit
Commits
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
Make sure that the GC never sees objects with refcount of zero
  • Loading branch information
markshannon committed Apr 9, 2025
commit 235490e0a147d9be4618a57df0d8f60b20d028d5
9 changes: 7 additions & 2 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,11 @@ _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op)
#ifdef Py_GIL_DISABLED
op->ob_tid = (uintptr_t)tstate->delete_later;
#else
*((PyObject**)op) = tstate->delete_later;
/* Store the pointer in the refcnt field.
* As this object may still be tracked by the GC,
* it is important that we never store 0 (NULL). */
uintptr_t refcnt = (uintptr_t)tstate->delete_later;
*((uintptr_t*)op) = refcnt+1;
#endif
tstate->delete_later = op;
}
Expand All @@ -2931,7 +2935,8 @@ _PyTrash_thread_destroy_chain(PyThreadState *tstate)
op->ob_tid = 0;
_Py_atomic_store_ssize_relaxed(&op->ob_ref_shared, _Py_REF_MERGED);
#else
tstate->delete_later = *((PyObject**)op);
uintptr_t refcnt = *((uintptr_t*)op);
tstate->delete_later = (PyObject *)(refcnt - 1);
op->ob_refcnt = 0;
#endif

Expand Down
0