Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-92135: Fix _Py_reinterpret_cast() for const#92138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
vstinner commented May 2, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented May 2, 2022
@tacaswell@serge-sans-paille: Does my |
vstinner commented May 2, 2022
erlend-aasland commented May 2, 2022
FTR, in another project, I recently had to use two casts in order to avoid G++ warnings: voidinner_set(void *); // original code (generated warnings)voidset_func(constchar *str){inner_set(str)} // new set func, still generated warningsvoidimproved_set_func(constchar *str){inner_set(const_cast<void *>(str))} // final set func, no warningsvoidset_func_without_warning(constchar *str){constvoid *vptr = static_cast<constvoid *>(str); inner_set(const_cast<void *>(vptr))} |
Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when casting a constant expression to a non constant type: use const_cast<> in C++. * In C++, Py_SAFE_DOWNCAST() now uses static_cast<> rather than reinterpret_cast<>. * Add tests to the _testcppext C++ extension. * test_cppext no longer captures stdout in verbose mode.
vstinner commented May 2, 2022
I understand that this approach (updated First, I renamed the macro _Py_reinterpret_const_cast(), but @serge-sans-paille didn't like this name, and me neither (it's too long!). So I kept the name |
vstinner commented May 2, 2022
@tacaswell: This issue should now be fixed. Please try greenlet with on the main branch of Python. |
tacaswell commented May 2, 2022
The const issues is fixed the other casting issues still remains |
vstinner commented May 3, 2022
I have no idea how to fix this cast. Do you have an idea? Does Maybe greenlet should be modified to cast to |
tacaswell commented May 3, 2022
I think we need an actual C++ expert to tell us if what greenlets is doing is fully kosher or undefined behavior that just happened to work before.
python-greenlet/greenlet@50f8786 is one way that works. |
serge-sans-paille commented May 4, 2022
That's an interesting situation: greenlets are written in C++, and the object that raises issues is of type According to me, this means we need something along these lines: |
Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when
casting a constant expression to a non constant type: use
const_cast<> in C++.
reinterpret_cast<>.