Conversation
On C++, do not use decltype() in _Py_TYPEOF since it produces invalid code in Py_CLEAR() and Py_SETREF(). Instead, implement Py_CLEAR() and Py_SETREF() using "auto" on C++11 and newer. Add Py_CLEAR() and Py_SETREF() tests on an array.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit d448889 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158070%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
This LGTM, though I'm not very knowledgeable about the macros here. To contribute something slightly non-trivial in response to your ping, the history of why decltype isn't suitable, resp. that there's no unified infra for this between C & C++, is actually quite fun/tragic. To the best of my understanding (based on public posts, I'm not privy to committee-internal details):
Looking at the diff, this provides an idea perhaps, in that the C++ case could be ordered after |
| * Py_DECREF(). | ||
| */ | ||
| #ifdef _Py_TYPEOF | ||
| #define Py_XSETREF(dst, src) \ |
There was a problem hiding this comment.
I'd adjust Py_XSETREF like Py_SETREF and add a test using it. Currently, it would fail because MSVC does not support __typeof__ in C++, see below.
| #elif defined(__GNUC__) || defined(__clang__) || \ | ||
| (defined(_MSC_VER) && _MSC_VER >= 1939) | ||
| #elif (defined(__GNUC__) || defined(__clang__) \ | ||
| || (defined(_MSC_VER) && _MSC_VER >= 1939)) |
There was a problem hiding this comment.
| || (defined(_MSC_VER) && _MSC_VER >= 1939)) | |
| || (defined(_MSC_VER) && _MSC_VER >= 1939 && !defined(__cplusplus))) |
MSVC does not support __typeof__ in C++, so I'd guard with !defined(__cplusplus). 1
Footnotes
-
because
__STDC_VERSION__is only set if option /std is used, https://godbolt.org/z/78cP4crsW. ↩
|
When you're done making the requested changes, leave the comment: And if you don't make the requested changes, you will be poked with soft cushions! |
True for gcc and clang but not MSVC. Also, strictly speaking, |
MSVC would work itself out via your suggested
I'd prefer this because it keeps C++ out of the default path. |
|
Yeah, as said above, that would be the least change in behaviour (and no change wrt gcc and clang) compared to 3.15. Which means Whether we'd like to unify for C++11 or favor |
|
I've run it on the relevant parts of the Cython CI and it fixes what I was hoping that it would fix. |
On C++, do not use decltype() in _Py_TYPEOF since it produces invalid code in Py_CLEAR() and Py_SETREF(). Instead, implement Py_CLEAR() and Py_SETREF() using "auto" on C++11 and newer.
Add Py_CLEAR() and Py_SETREF() tests on an array.
numpyprogram #157649