Deferring side effecting code in `_Py_Dealloc()`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Currently _Py_Dealloc() can call arbitrary code, and since _Py_Dealloc() can be called by any Py_DECREF() is means that Py_DECREF() can call arbitrary code. Py_DECREF() is everywhere, so it impairs our ability to reason about about the behavior of code.
This problem is not as severe as https://github.com/python/cpython/issues/97922, but is still worth fixing, especially as it will impair our ability to optimize traces for 3.12.
We can either make a Py_SAFE_DECREF() to be used internally, or change Py_DECREF() to defer all potentially side-effecting deallocation functions.
It is not clear which is the best option. Changing Py_DECREF() is simple, and certainly easy to reason about, but might delay deallocation of extension module objects for too long.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the _Py_Dealloc() and Py_DECREF() entry points referenced in the issue, then read issue 97922 for related context. Compare the proposed Py_SAFE_DECREF() approach with changing Py_DECREF() itself, including the effect on extension module object deallocation. Done means selecting and implementing a justified design with coverage for the resulting deallocation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100