Larry Hastings <la...@hastings.org> added the comment:

> 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.

----------
nosy: +larry

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39511>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to