You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Check for ref counting bugs in debug mode caused by immortal objects. #94851
With #90699, the identifiers are statically allocated and are immortal. This makes it easy to make reference counting mistakes as they are not detected and cause negative ref count in _Py_RefTotal.
On my machine the reference count is negative because of missing incref on &_Py_STR(empty):
To make it easy to discover reference counting issue, I propose to after each runtime finalization check that all the static allocated immortal objects have ref count of 999999999 otherwise _PyObject_Dump can be used to output the object and abort the process in debug mode and this will help prevent these kinds of issues of "unstable" ref count.
I tested on Ubuntu 20.04.4 LTS with 5.4.0-1074-azure kernel.
I think it is dependent on which code path is executed by site module but it doesn't matter as c functions always returns strong references and never borrowed references.
IIUC, once the https://peps.python.org/pep-0683/ is landed, we do not have to handle these kinds of reference counting operations for _Py_STR cases. Is it correct?
Yes, once immortal objects are implemented then we can take advantage of this work and remove all the reference counting, even automate it once we have all the correct reference counting of immortal objects.
Activity
corona10 commentedon Jul 14, 2022
Hmm FYI on macOS latest branch: 6cbb57f
It's not reproducible but I didn't check it on Linux.
corona10 commentedon Jul 14, 2022
Same on Ubuntu 20.04.4 LTS 6cbb57f
kumaraditya303 commentedon Jul 14, 2022
I tested on
Ubuntu 20.04.4 LTSwith5.4.0-1074-azurekernel.I think it is dependent on which code path is executed by site module but it doesn't matter as c functions always returns strong references and never borrowed references.
pythonGH-94851: fix immortal objects refcounting in compiler (pythong…
GH-94851: fix immortal objects refcounting in compiler (gh-95040)
corona10 commentedon Jul 20, 2022
@ericsnowcurrently
IIUC, once the https://peps.python.org/pep-0683/ is landed, we do not have to handle these kinds of reference counting operations for _Py_STR cases. Is it correct?
kumaraditya303 commentedon Jul 20, 2022
Yes, once immortal objects are implemented then we can take advantage of this work and remove all the reference counting, even automate it once we have all the correct reference counting of immortal objects.
kumaraditya303 commentedon Jul 20, 2022
Also this issue would be relevant even after immortal objects as even with immortal objects we still want stable
-X showrefcount.kumaraditya303 commentedon Jul 20, 2022
FTR, so far the following PRs have been merged which fixed refcounting on immortal objects:
GH-94851: fix immortal objects refcounting in compiler (gh-95040)
ericsnowcurrently commentedon Jul 21, 2022
Right.
ericsnowcurrently commentedon Jul 21, 2022
I suspect we'll drop this check later. However, it is helpful until then.
GH-94851: check refcnt of immortal objects after finalization (GH-95001)
kumaraditya303 commentedon Jul 25, 2022
Fixed by #95001
GH-94851: check unicode consistency of static strings in debug mode (#…
Merge branch 'main' into inlinecomp2
pythonGH-94851: check unicode consistency of static strings in debug …
pythonGH-94851: check unicode consistency of static strings in debug …