[Python-Dev] Counting references to Py_None (original) (raw)

Brett Cannon 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> wrote:

Hello!

I'm seeing that our code increases the reference counting to PyNone, and I find this a little strange: isn't PyNone eternal and will never die?

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... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160320/bd0d8f82/attachment.html>



More information about the Python-Dev mailing list