Description
Feature or enhancement
Remove the section of the PyObject_Print function that handles input objects that have a negative reference counter:
Lines 274 to 278 in 88297e2
Previous discussion
The PR #98749 that improves the coverage of PyObject_Print
is blocked due to a failing pipeline. After investigation, the test that is failing is associated with the Address Sanitizer. In particular, it fails the test that covers the aforementioned section. It consists in passing an object (specifically a Python string) with its reference counter set to zero and comparing the output string to the expected result: https://github.com/MonadChains/cpython/blob/562b9d26db7e766741c954146d4423eda414d2f6/Modules/_testcapimodule.c#L2053-L2080
However, when the reference counter of the object goes to zero, it is deallocated, and the Address Sanitizer does not like it.
After the discussion in https://mail.python.org/archives/list/core-mentorship@python.org/thread/7BP55KL6VB3H2ZZ5JZP2NV6RX72HBUCC/, a possible solution to this is to clean up the function and remove this section entirely. Normally this kind of check is performed only in specific situations like for example _Py_ForgetReference
or Py_DECREF
so it seems a bit weird to have it in PyObject_Print
.
Alternatively, another solution could be to remove the failing test from the PR and don't cover this section of the function.