]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-98724: Fix Py_CLEAR() macro side effects (#99100) (#100070)
authorVictor Stinner <vstinner@python.org>
Wed, 7 Dec 2022 14:22:38 +0000 (15:22 +0100)
committerGitHub <noreply@github.com>
Wed, 7 Dec 2022 14:22:38 +0000 (15:22 +0100)
commitb11a384dc7471ffc16de4b86e8f5fdeef151f348
treec2fc15ebb4de11991f9f1799fa2588a484003073
parent7031275776f43c76231318c2158a7a2753bc1fba
gh-98724: Fix Py_CLEAR() macro side effects (#99100) (#100070)

The Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros now only evaluate
their arguments once. If an argument has side effects, these side
effects are no longer duplicated.

Use temporary variables to avoid duplicating side effects of macro
arguments. If available, use _Py_TYPEOF() to avoid type punning.
Otherwise, use memcpy() for the assignment to prevent a
miscompilation with strict aliasing caused by type punning.

Add _Py_TYPEOF() macro: __typeof__() on GCC and clang.

Add test_py_clear() and test_py_setref() unit tests to _testcapi.
Doc/c-api/refcounting.rst
Doc/whatsnew/3.12.rst
Include/cpython/object.h
Include/object.h
Include/pyport.h
Misc/NEWS.d/next/C API/2022-11-04-16-13-35.gh-issue-98724.p0urWO.rst [new file with mode: 0644]
Modules/_testcapimodule.c