]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-99537: Use Py_SETREF() function in C code (#99656)
authorVictor Stinner <vstinner@python.org>
Tue, 22 Nov 2022 13:22:22 +0000 (14:22 +0100)
committerGitHub <noreply@github.com>
Tue, 22 Nov 2022 13:22:22 +0000 (14:22 +0100)
commit7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e
treea8d4dda9e9128545442794595f5ebc96a5c1c7b4
parent135ec7cefbaffd516b77362ad2b2ad1025af462e
gh-99537: Use Py_SETREF() function in C code (#99656)

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.
20 files changed:
Doc/includes/custom2.c
Doc/includes/custom3.c
Doc/includes/custom4.c
Modules/_collectionsmodule.c
Modules/_datetimemodule.c
Modules/_elementtree.c
Modules/_functoolsmodule.c
Modules/_io/stringio.c
Modules/_io/textio.c
Modules/_json.c
Modules/_pickle.c
Modules/_sqlite/cursor.c
Modules/_testinternalcapi.c
Modules/_tkinter.c
Modules/_zoneinfo.c
Modules/audioop.c
Modules/cjkcodecs/multibytecodec.c
Modules/itertoolsmodule.c
Modules/mathmodule.c
Modules/posixmodule.c