-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
changes to PyObject casting macros causing build failures with python-greenlet #92898
Comments
Well, you can assign the issue to me, but I'm not sure that I have the C++ skills to fix this specific issue. |
Okay, I will also take a look at this issue too. |
@serge-sans-paille cc @tacaswell IMHO implementing the conversion operator for PyObject* might be a common usecases in the C++ world, |
I wrote a simple C++ program to test casts of many types to @serge-sans-paille's approach using templates works in all cases: template<typename type, typename expr_type>
type _Py_reinterpret_cast_impl(expr_type* expr) { return reinterpret_cast<type>(expr);}
template<typename type, typename expr_type>
type _Py_reinterpret_cast_impl(expr_type const * expr) { return reinterpret_cast<type>(const_cast<expr_type*>(expr));}
template<typename type, typename expr_type>
type _Py_reinterpret_cast_impl(expr_type & expr) { return static_cast<type>(expr);}
template<typename type, typename expr_type>
type _Py_reinterpret_cast_impl(expr_type const & expr) { return static_cast<type>(const_cast<expr_type &>(expr));}
#define _Py_CAST(type, expr) _Py_reinterpret_cast_impl<type>(expr) |
PEP 670 converted more macros to static inline functions. While doing this work, I tried to fix C++ compiler warnings on "old-style cast" by adding _Py_CAST() and _Py_STATIC_CAST(). I tried to minimize the quantity of C++ code in the Python C API header files: in short, it's mostly 2 lines which use The problem is that my implementation doesn't cover all cases: it doesn't cover greenlet case which implements a class which has a cast operator to |
Use the adequate kind of cast based on the macro argument: const ref, cont pointer, ref or pointer. This should be compatible with C++ overloads. Fix python#92898
… operator (pythongh-92951) (cherry picked from commit 5b71b51) Co-authored-by: serge-sans-paille <[email protected]>
* Add StrongRef class. * Rename and reformat functions of the _Py_CAST() implementation.
…GH-93111) * Add StrongRef class. * Rename and reformat functions of the _Py_CAST() implementation. (cherry picked from commit 20d30ba) Co-authored-by: Victor Stinner <[email protected]>
* Add StrongRef class. * Rename and reformat functions of the _Py_CAST() implementation. (cherry picked from commit 20d30ba) Co-authored-by: Victor Stinner <[email protected]>
Bug report
There have been changes to how the macros for casting PyObject pointers per #91959 (comment) by @vstinner any new compiler warnings are a regression.
There were two types of errors in greenlet, one related to const correctness which has been fixed via #92138) and one related to casting wrapper classes (that has not been fixed).
Per @serge-sans-paille in #92138 (comment)
and suggests a patch to CPython.
python-greenlet/greenlet#302 is a fix on the greenlet side.
The key line of the error is
This is also affecting python/pyperformance#198
A bunch of links: #92800 (comment)
Your environment
The text was updated successfully, but these errors were encountered: