GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — gh-157649: Fix Py_CLEAR()/Py_SETREF() on C++ by vstinner · Pull Request #158070 · python/cpython Conversation
|
|
🤖 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
True for gcc and clang but not MSVC. Also, strictly speaking, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
MSVC would work itself out via your suggested
I'd prefer this because it keeps C++ out of the default path. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've run it on the relevant parts of the Cython CI and it fixes what I was hoping that it would fix. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, I changed the implementation to use Adding tests to test_cext and test_cppext became more and more annoying over time, since these "basic C/C++ extensions" became more complex over time. I merged test_cppext into test_cext (PR #158176) to share most code (init, setup, extension.c), especially extension.c which is now used by C and C++. By the way, I also made a change to check for reference leaks (and I had to fix a test for that!): PR #158227.
Oh ok, fixed. Since _Py_TYPEOF() was not used by default on C++ on my first implementation, this bug was not catched by test_cppext.
Ooops, I forgot that Py_XSETREF() as a copy-pasta implementation copied from Py_SETREF(). I added tests and also updated Py_XSETREF() implementation to use C++ auto. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@chris-eibl: Oh, the PR is still red because you requested changes. I addressed your review. Would you mind reviewing the updated PR? Once GitHub Action CI will pass, I will schedule a buildbot run to run test_cext on buildbots. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit 27f1d3e 🤖 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks Victor, I think this is the best we can get with the lowest risk: the gcc / clang basically stays untouched, and for MSVC we should get the
I think we'll rarely get there, except when not gcc, clang or MSVC. In case of MSVC for versions >= VS 2017, C++14 is the minimum, there is no /std switch for anything lower than C++14. Hence I think cpython/Lib/test/test_cext/__init__.py Lines 143 to 144 in 869a505
should be marked with skipIf likecpython/Lib/test/test_cext/__init__.py Lines 149 to 150 in 869a505
You should currently see a warning for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If test_build_cpp03 is changed, I would prefer to do in a separated PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Tests passed a wide diversity of buildbots, I enable auto-merge. test_dtrace fails on s390x, but that's a known and unrelated issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks for reviews! I merged my change. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* gh-121647: Fix _Py_TYPEOF() on C++ (#157267) Using MSVC (on Windows), _Py_TYPEOF() prefers decltype() over __typeof__() on C++. Fix also _Py_TYPEOF() usage in Py_CLEAR() and Py_SETREF() macros. Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++, "_Py_TYPEOF(dst)*" can fail with a compiler error. (cherry picked from commit bba99f2) * gh-157649: Fix Py_CLEAR()/Py_SETREF() on C++ (#158070) On C++, do not use decltype() in _Py_TYPEOF since it produces invalid code in Py_CLEAR() and Py_SETREF(). Instead, implement Py_CLEAR(), Py_SETREF() and Py_XSETREF() using "auto" on C++11 and newer. Add Py_CLEAR(), Py_SETREF() and Py_XSETREF() tests on an array. (cherry picked from commit 3330712)
|
Py_SETREF() macros family is a gift which keeps giving: see issue #161185 about strict aliasing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.