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
Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef() #99300
I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks "more correct". Examples:
(A) Assign + INCREF:
- result = Py_False;- Py_INCREF(result);+ result = Py_NewRef(Py_False);
While technically, Py_INCREF() and Py_XINCREF() modify the object in-place (increment their reference counter), for me Py_NewRef() makes me sense: it creates "a new reference".
The example (A) is weird: it assigns a variable to something, and only later creates a new reference. For me, the syntax with Py_NewRef() makes more sense.
Examples (B) and (C) are shorter with Py_NewRef(), and again, IMO makes more sense and are more readable.
Activity
gh-99300: Use Py_NewRef() in Python/ directory (#99302)
gh-99300: Use Py_NewRef() in Python/ directory (#99317)
gh-99300: Use Py_NewRef() in Python/ceval.c (#99318)
gh-99300: Use Py_NewRef() in Parser/ directory (#99330)
gh-99300: Use Py_NewRef() in Objects/dictobject.c (#99333)
gh-99300: Use Py_NewRef() in Objects/ directory (#99332)
pythongh-99300: Use Py_NewRef() in Objects/ directory (python#99332)
pythongh-99300: Use Py_NewRef() in Objects/dictobject.c (python#99333)
gh-99300: Use Py_NewRef() in Objects/listobject.c (#99336)
gh-99300: Use Py_NewRef() in Objects/ directory (#99335)
gh-99300: Use Py_NewRef() in Objects/ directory (#99351)
gh-99300: Use Py_NewRef() in Objects/ directory (#99354)
pythongh-99300: Use Py_NewRef() in Python/ directory (python#99302)
pythongh-99300: Use Py_NewRef() in Python/ directory (python#99317)
16 remaining items
gh-99300: Use Py_NewRef() in Modules/ directory (#99467)
gh-99300: Use Py_NewRef() in Modules/_datetimemodule.c (#99465)
gh-99300: Use Py_NewRef() in Modules/ directory (#99468)
gh-99300: Use Py_NewRef() in Modules/ directory (#99469)
gh-99300: Use Py_NewRef() in Modules/ directory (#99473)
gh-99300: Use Py_NewRef() in Doc/ directory (#99480)
gh-99300: Use Py_NewRef() in PC/ directory (#99479)
erlend-aasland commentedon Nov 14, 2022
For the record, see gh-23170 for the PR that converted
sqlite3toPy_NewRef/Py_XNewRef.gh-99300: Use Py_NewRef() in Python/Python-ast.c (#99499)
Merge branch 'main' into fix-issue21914
gh-99300: Replace Py_INCREF() with Py_NewRef() (#99513)
gh-99300: Replace Py_INCREF() with Py_NewRef() (#99530)
vstinner commentedon Nov 21, 2022
26 commits later, I have converted all "INCREF + assign" and "INCREF + return" to NewRef. I am now closing the issue.
gh-99300: Replace Py_INCREF() with Py_NewRef() in _elementtree.c (#99696