
On Thu, Dec 16, 2021 at 2:48 AM Petr Viktorin <encukou@gmail.com> wrote:
But does the sign bit need to stay intact, and do we actually need to rely on the immortal bit to always be set for immortal objects? If the refcount rolls over to zero, an immortal object's dealloc could bump it back and give itself another few minutes. Allowing such rollover would mean having to deal with negative refcounts, but that might be acceptable.
FWIW, my original attempt at immortal objects (quite a while ago) used the sign bit as the marker (negative refcount meant immortal). However, this broke GC and Py_DECREF() and getting those to work right was a pain. It also made a few things harder to debug because a negative refcount no longer necessarily indicated something had gone wrong. In the end I switched to a really high bit as the marker and it was all much simpler. -eric