Skip to content
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

py311 issues with const correctness #301

Closed
tacaswell opened this issue Apr 30, 2022 · 6 comments
Closed

py311 issues with const correctness #301

tacaswell opened this issue Apr 30, 2022 · 6 comments

Comments

@tacaswell
Copy link
Contributor

I'm opening a different issue from #288 because those were all of the type "a struct changed" where as this is related to how casting is done and the tracking of const correctness.

python/cpython#91959 changed how casting was done internally to CPython to silence compiler errors. However by moving to the new method of casting, the compiler is now detecting that const is being discarded.

Per python/cpython#91959 (comment)

The C API requires non-const PyObject*.

I think the fix is to add const_cast in greenlet before calling into the CPython apis as needed.

compiler errors folded:

$ gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/tcaswell/.virtualenvs/bleeding/include -I/home/tcaswell/.pybuild/bleeding/include/python3.11 -c src/greenlet/greenlet.cpp -o build/temp.linux-x86_64-3.11/src/greenlet/greenlet.o

In file included from /home/tcaswell/.pybuild/bleeding/include/python3.11/Python.h:38,
                 from src/greenlet/greenlet.cpp:14:
src/greenlet/greenlet_refs.hpp: In member function ‘void greenlet::refs::CreatedModule::PyAddObject(const char*, const PyObject*)’:
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: ‘reinterpret_cast’ from type ‘const PyObject*’ {aka ‘const _object*’} to type ‘PyObject*’ {aka ‘_object*’} casts away qualifiers
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:505:35: note: in expansion of macro ‘_PyObject_CAST’
  505 | #  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
      |                                   ^~~~~~~~~~~~~~
src/greenlet/greenlet_refs.hpp:854:13: note: in expansion of macro ‘Py_INCREF’
  854 |             Py_INCREF(new_object);
      |             ^~~~~~~~~
src/greenlet/greenlet_refs.hpp: In member function ‘void greenlet::refs::PyErrPieces::normalize()’:
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::OwnedErrPiece’ to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:780:41: note: in expansion of macro ‘_PyObject_CAST’
  780 | #  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
      |                                         ^~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyerrors.h:57:6: note: in expansion of macro ‘PyType_Check’
   57 |     (PyType_Check((x)) &&                                               \
      |      ^~~~~~~~~~~~
src/greenlet/greenlet_refs.hpp:993:17: note: in expansion of macro ‘PyExceptionClass_Check’
  993 |             if (PyExceptionClass_Check(type)) {
      |                 ^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/tcaswell/.pybuild/bleeding/include/python3.11/Python.h:44,
                 from src/greenlet/greenlet.cpp:14:
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::OwnedErrPiece’ to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:774:59: note: in definition of macro ‘PyType_FastSubclass’
  774 | #define PyType_FastSubclass(type, flag) PyType_HasFeature(type, flag)
      |                                                           ^~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:136:31: note: in expansion of macro ‘_PyObject_CAST’
  136 | #  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
      |                               ^~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyerrors.h:61:25: note: in expansion of macro ‘Py_TYPE’
   61 |     PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)
      |                         ^~~~~~~
src/greenlet/greenlet_refs.hpp:1003:22: note: in expansion of macro ‘PyExceptionInstance_Check’
 1003 |             else if (PyExceptionInstance_Check(type)) {
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/tcaswell/.pybuild/bleeding/include/python3.11/Python.h:38,
                 from src/greenlet/greenlet.cpp:14:
src/greenlet/greenlet_thread_state.hpp: In destructor ‘greenlet::ThreadState::~ThreadState()’:
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::BorrowedObject’ {aka ‘greenlet::refs::BorrowedReference<_object, greenlet::refs::NoOpChecker>’} to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:265:59: note: in expansion of macro ‘_PyObject_CAST’
  265 | #  define PyObject_TypeCheck(ob, type) PyObject_TypeCheck(_PyObject_CAST(ob), type)
      |                                                           ^~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/methodobject.h:17:31: note: in expansion of macro ‘PyObject_TypeCheck’
   17 | #define PyCFunction_Check(op) PyObject_TypeCheck(op, &PyCFunction_Type)
      |                               ^~~~~~~~~~~~~~~~~~
src/greenlet/greenlet_thread_state.hpp:400:33: note: in expansion of macro ‘PyCFunction_Check’
  400 |                              && PyCFunction_Check(refs.at(0))
      |                                 ^~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::BorrowedObject’ {aka ‘greenlet::refs::BorrowedReference<_object, greenlet::refs::NoOpChecker>’} to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:127:35: note: in expansion of macro ‘_PyObject_CAST’
  127 | #  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
      |                                   ^~~~~~~~~~~~~~
src/greenlet/greenlet_thread_state.hpp:401:33: note: in expansion of macro ‘Py_REFCNT’
  401 |                              && Py_REFCNT(refs.at(0)) == 2) {
      |                                 ^~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::BorrowedObject’ {aka ‘greenlet::refs::BorrowedReference<_object, greenlet::refs::NoOpChecker>’} to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:580:29: note: in expansion of macro ‘_PyObject_CAST’
  580 |         PyObject *_py_tmp = _PyObject_CAST(op); \
      |                             ^~~~~~~~~~~~~~
src/greenlet/greenlet_thread_state.hpp:422:33: note: in expansion of macro ‘Py_CLEAR’
  422 |                                 Py_CLEAR(function_w);
      |                                 ^~~~~~~~
src/greenlet/greenlet.cpp: In function ‘PyObject* green_repr(greenlet::refs::BorrowedGreenlet)’:
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: invalid cast from type ‘greenlet::refs::BorrowedGreenlet’ {aka ‘greenlet::refs::_BorrowedGreenlet<_greenlet, greenlet::refs::GreenletChecker>’} to type ‘PyObject*’ {aka ‘_object*’}
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:136:31: note: in expansion of macro ‘_PyObject_CAST’
  136 | #  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
      |                               ^~~~~~~~~~~~~~
src/greenlet/greenlet.cpp:2395:33: note: in expansion of macro ‘Py_TYPE’
 2395 |     const char* const tp_name = Py_TYPE(self)->tp_name;
      |                                 ^~~~~~~
src/greenlet/greenlet_refs.hpp: In instantiation of ‘greenlet::refs::OwnedReference<T, <anonymous> >& greenlet::refs::OwnedReference<T, <anonymous> >::operator=(const greenlet::refs::OwnedReference<T, <anonymous> >&) [with T = _object; void (* TC)(void*) = greenlet::refs::NoOpChecker]’:
src/greenlet/greenlet_refs.hpp:908:11:   required from here
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: ‘reinterpret_cast’ from type ‘const _object*’ to type ‘PyObject*’ {aka ‘_object*’} casts away qualifiers
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:605:37: note: in expansion of macro ‘_PyObject_CAST’
  605 | #  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
      |                                     ^~~~~~~~~~~~~~
src/greenlet/greenlet_refs.hpp:342:13: note: in expansion of macro ‘Py_XDECREF’
  342 |             Py_XDECREF(tmp);
      |             ^~~~~~~~~~
src/greenlet/greenlet_refs.hpp: In instantiation of ‘greenlet::refs::OwnedReference<T, <anonymous> >& greenlet::refs::OwnedReference<T, <anonymous> >::operator=(const greenlet::refs::OwnedReference<T, <anonymous> >&) [with T = _object; void (* TC)(void*) = greenlet::refs::ContextExactChecker]’:
src/greenlet/greenlet.cpp:2337:40:   required from here
/home/tcaswell/.pybuild/bleeding/include/python3.11/pyport.h:20:44: error: ‘reinterpret_cast’ from type ‘const _object*’ to type ‘PyObject*’ {aka ‘_object*’} casts away qualifiers
   20 | #  define _Py_reinterpret_cast(type, expr) reinterpret_cast<type>(expr)
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:107:28: note: in expansion of macro ‘_Py_reinterpret_cast’
  107 | #define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
      |                            ^~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/bleeding/include/python3.11/object.h:605:37: note: in expansion of macro ‘_PyObject_CAST’
  605 | #  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
      |                                     ^~~~~~~~~~~~~~
src/greenlet/greenlet_refs.hpp:342:13: note: in expansion of macro ‘Py_XDECREF’
  342 |             Py_XDECREF(tmp);
      |             ^~~~~~~~~~

@tacaswell
Copy link
Contributor Author

There was a second class of casting issues that I missed on the first read of the errors.

@tacaswell
Copy link
Contributor Author

This is fixed by python/cpython#92951

@vstinner
Copy link
Contributor

This is fixed by python/cpython#92951

This change will be part of Python 3.11 beta2 scheduled at next week (Monday, 2022-05-30).

@vstinner
Copy link
Contributor

This is nothing to do in the greenlet side, so I suggest closing the issue. See my follow-up issue: #303 "Schedule for a beta release of greenlet 2.0?"

@vstinner
Copy link
Contributor

See also #302 (no longer needed).

@tacaswell
Copy link
Contributor Author

This was also fixed upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants