]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-99537: Use Py_SETREF() function in C code (#99657)
authorVictor Stinner <vstinner@python.org>
Tue, 22 Nov 2022 12:39:11 +0000 (13:39 +0100)
committerGitHub <noreply@github.com>
Tue, 22 Nov 2022 12:39:11 +0000 (13:39 +0100)
commit135ec7cefbaffd516b77362ad2b2ad1025af462e
tree1f92fbda32d21f0efc9f54432c32af03fe49a608
parent3db0a21f731cec28a89f7495a82ee2670bce75fe
gh-99537: Use Py_SETREF() function in C code (#99657)

Fix potential race condition in code patterns:

* Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);"
* Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);"
* Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);"

Other changes:

* Replace "old = var; var = new; Py_DECREF(var)"
  with "Py_SETREF(var, new);"
* Replace "old = var; var = new; Py_XDECREF(var)"
  with "Py_XSETREF(var, new);"
* And remove the "old" variable.
19 files changed:
Objects/bytesobject.c
Objects/capsule.c
Objects/fileobject.c
Objects/floatobject.c
Objects/genobject.c
Objects/setobject.c
Objects/sliceobject.c
Objects/stringlib/unicode_format.h
Objects/typeobject.c
Objects/unicodeobject.c
Objects/weakrefobject.c
Python/_warnings.c
Python/bltinmodule.c
Python/compile.c
Python/errors.c
Python/hamt.c
Python/pythonrun.c
Python/sysmodule.c
Python/traceback.c