Open
Description
Feature or enhancement
Proposal:
Recently, MSVC implemented __typeof__
, which currently is defined as _Py_TYPEOF
only on GCC and Clang.
Lines 553 to 560 in 65feded
The only users of _Py_TYPEOF
are macros Py_CLEAR()
, Py_SETREF()
and Py_XSETREF()
.
If _Py_TYPEOF
is not defined, these macros fall back to slightly uglier implementations with memcpy
calls.
Lines 421 to 442 in 65feded
The proposal is to define _Py_TYPEOF
on:
- latest MSVC versions that support
__typeof__
- arbitrary compilers that support
__typeof__
- arbitrary compilers that support C23
typeof
or C++11decltype
By defining _Py_TYPEOF
, uses of Py_CLEAR()
, Py_SETREF()
and Py_XSETREF()
are switched to the _Py_TYPEOF
implementation; on these compilers, the benefits would be:
- Less worrying about miscompilation and machine code quality.
- Fewer surprises with hidden
memcpy
as seen in - Reduced variance between optimization settings thanks to more straightforward implementation.
Additionally, this removes a differing detail between MSVC and GCC/Clang builds, which should be generally desirable.
Has this already been discussed elsewhere?
No response given