8000 Add Py_SETREF and Py_CLEAR operations (#56) · python/pythoncapi-compat@8ebf997 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ebf997

Browse files
authored
Add Py_SETREF and Py_CLEAR operations (#56)
* Py_CLEAR doesn't replace Py_DECREF(). * Remove FORCE_NEWREF. Instead, exclude NewRef operations from "all". * Enhance Py_INCREF_assign. * Replace also "PyObject *var = x; Py_INCREF(x);".
1 parent 35208be commit 8ebf997

File tree

4 files changed

+478
-51
lines changed

4 files changed

+478
-51
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
=========
33

4+
* 2022-11-15: Add experimental operations to the upgrade_pythoncapi script:
5+
``Py_INCREF_return``, ``Py_INCREF_assign``, ``Py_CLEAR`` and ``Py_SETREF``.
46
* 2022-11-09: Fix ``Py_SETREF()`` and ``Py_XSETREF()`` macros
57
for `gh-98724 <https://github.com/python/cpython/issues/98724>`_.
68
* 2022-11-04: Add ``PyFrame_GetVar()`` and ``PyFrame_GetVarString()``

docs/upgrade.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,31 @@ PyThreadState_GetFrame
141141
----------------------
142142

143143
* Replace ``tstate->frame`` with ``_PyThreadState_GetFrameBorrow(tstate)``.
144+
145+
Experimental operations
146+
-----------------------
147+
148+
The following operations are experimental (ex: can introduce compiler warnings)
149+
and so not included in the ``all`` group, they have to be selected explicitly.
150+
Example: ``-o all,Py_SETREF``.
151+
152+
Experimental operations:
153+
154+
* ``Py_INCREF_return``:
155+
156+
* Replace ``Py_INCREF(res); return res;`` with ``return Py_NewRef(res);``
157+
158+
* ``Py_INCREF_assign``:
159+
160+
* Replace ``x = y; Py_INCREF(x);`` with ``x = Py_NewRef(y);``
161+
* Replace ``x = y; Py_INCREF(y);`` with ``x = Py_NewRef(y);``
162+
* Replace ``Py_INCREF(y); x = y;`` with ``x = Py_NewRef(y);``
163+
164+
* ``Py_CLEAR``:
165+
166+
* Replace ``Py_XDECREF(var); var = NULL;`` with ``Py_CLEAR(var);``
167+
168+
* ``Py_SETREF``:
169+
170+
* Replace ``Py_DECREF(x); x = y;`` with ``Py_SETREF(x, y);``
171+
* Replace ``Py_XDECREF(x); x = y;`` with ``Py_XSETREF(x, y);``

0 commit comments

Comments
 (0)
0