New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INCREF/DECREFs around the rich comparison needs tests #84669
Comments
In Objects/dictobject.c, if I remove the INCREF/DECREF pair around PyObject_RichCompareBool(), all the tests still pass:
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. |
See bpo-1517. |
I can crash python interpreter with few lines of code when if we remove those codes. class S(str):
def __eq__(self, other):
d.clear()
return NotImplemented
def __hash__(self):
return hash('test')
d = {S(): 'value'}
'test' in d |
Would you like to add a test for this case? |
Oh, I mean, is it good to add a test for this case? |
Thank you. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: