New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:

In Objects/dictobject.c, if I remove the INCREF/DECREF pair around 
PyObject_RichCompareBool(), all the tests still pass:

-           Py_INCREF(startkey);
            cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
-           Py_DECREF(startkey);

It would be nice to have tests demonstrating why it is necessary.  IIRC the 
reason is that an object could have a custom comparison that clears the 
enclosing container and frees the element during the comparison.  

Also, it would be nice if PyObject_RichCompareBool() could be redesigned to not 
fail if a borrowed reference gets deallocated while the function is running.  
The incref and decref occur on a hot path, and it is unfortunate that they 
cause extra writes to objects scattered all over memory, likely causing a lot 
of cache misses in real programs.

----------
assignee: serhiy.storchaka
components: Interpreter Core
messages: 367997
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: INCREF/DECREFs around the rich comparison needs tests

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

Reply via email to