This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients eric.snow, jeremy.kloth, jkloth, larry, maciej.szulik, nanjekyejoannah, ncoghlan, phsilva, rhettinger, shihai1991, vstinner
Date 2020-03-17.02:35:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584412549.18.0.128167076611.issue39511@roundup.psfhosted.org>
In-reply-to
Content
> We should do that for each singletons:
> 
> * None (Py_None)
> * True (Py_True)
> * False (Py_False)
> * Ellipsis (Py_Ellipsis)

Aren't there a couple more lurking in the interpreter?  E.g. empty tuple, empty frozenset.


> That is exactly why I didn't propose a change to them.
> The singletons still are refcounted as usual,
> just that their ob_refcnt is ignored.
> If they somehow reach 0, they just "resurrect" themselves
> and ignore the regular collection behavior.

That seems like a very good idea!  They don't even need to "resurrect" themselves--we just ensure tp_dealloc is a no-op for those special values.  If we do that, different threads and different interpreters can change ob_refcnt willy-nilly, there can be unsafe races between threads, the value could no longer make any sense--but as long as we never free the object, it's all totally fine.

(Actually: tp_dealloc shouldn't be a no-op--it should add a million to the reference count for these special objects, to forestall future irrelevant calls to tp_dealloc.)

This might have minor deleterious effects, e.g. sys.getrefcount() would return misleading results for such objects.  I think that's acceptable.
History
Date User Action Args
2020-03-17 02:35:49larrysetrecipients: + larry, rhettinger, ncoghlan, vstinner, jkloth, phsilva, jeremy.kloth, eric.snow, maciej.szulik, nanjekyejoannah, shihai1991
2020-03-17 02:35:49larrysetmessageid: <1584412549.18.0.128167076611.issue39511@roundup.psfhosted.org>
2020-03-17 02:35:49larrylinkissue39511 messages
2020-03-17 02:35:48larrycreate