[Python-Dev] Counting references to Py_None
brett at python.org
Sun Mar 20 13:10:01 EDT 2016
On Sun, 20 Mar 2016 at 09:44 Facundo Batista <facundobatista at gmail.com>
> I'm seeing that our code increases the reference counting to Py_None,
> and I find this a little strange: isn't Py_None eternal and will never
Semantically yes, but we have to technically make that happen. :)
> What's the point of counting its references?
It's just another Python object, so if you return it then the code that
receives it may very well decref it because it always DECREFs the object
returned. And if we didn't keep its count accurately it would eventually
hit zero and constantly have its dealloc function checked for. We could add
a magical "never dies" value for the refcount, but that adds another `if`
branch in all the code instead of simply treating Py_None like any other
object and properly tracking its reference.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev