SIGN IN SIGN UP
python / cpython UNCLAIMED

The Python programming language

0 0 95 Python

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.
V
Victor Stinner committed
b11a384dc7471ffc16de4b86e8f5fdeef151f348
Parent: 7031275
Committed by GitHub <noreply@github.com> on 12/7/2022, 2:22:38 PM