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

Cython 3 compatbility #77

Open
sanjayankur31 opened this issue Jul 21, 2023 · 6 comments
Open

Cython 3 compatbility #77

sanjayankur31 opened this issue Jul 21, 2023 · 6 comments

Comments

@sanjayankur31
Copy link

sanjayankur31 commented Jul 21, 2023

Cython 3 has been released, and the MUSIC sources need to be updated to work with it. Examples of errors when trying to build MUSIC with Cython 3:

warning: ./pyconfig.pxi:1:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
warning: music/pybuffer.pxd:8:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
make[1]: *** [Makefile:444: all-recursive] Error 1
make: *** [Makefile:372: all] Error 2

Here's the migration guide: https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html

@hroncok
Copy link

hroncok commented Nov 14, 2023

In the Fedora RPM package I see:

Error compiling Cython file:
------------------------------------------------------------
...
            raise TypeError("object does not present buffer interface")

        cdef Py_buffer* pybuf = &self.pybuf
        PyObject_GetBuffer(data, pybuf, bufflags)
        self.dtype = TypeDict[getformat(pybuf)]
        self.items = pybuf.len / pybuf.itemsize
                               ^
------------------------------------------------------------

pybuffer.pyx:63:31: Cannot assign type 'double' to 'Py_ssize_t'

Cython 3 assumes Python 3 / semantics. This should be fixable by using //. Let me have a look.

@hroncok
Copy link

hroncok commented Nov 14, 2023

f007845 (committed 2 years ago)

@hroncok
Copy link

hroncok commented Nov 14, 2023

And then I get:

pymusic.cpp: In function 'PyObject* __pyx_pf_7pymusic_5Setup_6config(__pyx_obj_7pymusic_Setup*, std::string)':
pymusic.cpp:13679:45: error: invalid cast from type 'std::string' {aka 'std::__cxx11::basic_string<char>'} to type 'PyObject*' {aka '_object*'}
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:1512:43: note: in definition of macro 'likely'
 1512 |   #define likely(x)   __builtin_expect(!!(x), 1)
      |                                           ^
/usr/include/python3.12/object.h:194:28: note: in expansion of macro '_Py_CAST'
  194 | #define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
      |                            ^~~~~~~~
/usr/include/python3.12/object.h:254:43: note: in expansion of macro '_PyObject_CAST'
  254 | #  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
      |                                           ^~~~~~~~~~~~~~
/usr/include/python3.12/floatobject.h:17:32: note: in expansion of macro 'Py_IS_TYPE'
   17 | #define PyFloat_CheckExact(op) Py_IS_TYPE((op), &PyFloat_Type)
      |                                ^~~~~~~~~~
pymusic.cpp:2870:10: note: in expansion of macro 'PyFloat_CheckExact'
 2870 | ((likely(PyFloat_CheckExact(obj))) ?  PyFloat_AS_DOUBLE(obj) :\
      |          ^~~~~~~~~~~~~~~~~~
pymusic.cpp:13679:20: note: in expansion of macro '__Pyx_PyObject_AsDouble'
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                    ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.12/Python.h:38,
                 from pymusic.cpp:34:
pymusic.cpp:13679:45: error: invalid cast from type 'std::string' {aka 'std::__cxx11::basic_string<char>'} to type 'PyObject*' {aka '_object*'}
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/python3.12/pyport.h:24:38: note: in definition of macro '_Py_CAST'
   24 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
/usr/include/python3.12/cpython/floatobject.h:18:49: note: in expansion of macro '_PyObject_CAST'
   18 | #define PyFloat_AS_DOUBLE(op) PyFloat_AS_DOUBLE(_PyObject_CAST(op))
      |                                                 ^~~~~~~~~~~~~~
pymusic.cpp:2870:39: note: in expansion of macro 'PyFloat_AS_DOUBLE'
 2870 | ((likely(PyFloat_CheckExact(obj))) ?  PyFloat_AS_DOUBLE(obj) :\
      |                                       ^~~~~~~~~~~~~~~~~
pymusic.cpp:13679:20: note: in expansion of macro '__Pyx_PyObject_AsDouble'
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                    ^~~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:13679:45: error: invalid cast from type 'std::string' {aka 'std::__cxx11::basic_string<char>'} to type 'PyObject*' {aka '_object*'}
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:1512:43: note: in definition of macro 'likely'
 1512 |   #define likely(x)   __builtin_expect(!!(x), 1)
      |                                           ^
/usr/include/python3.12/object.h:194:28: note: in expansion of macro '_Py_CAST'
  194 | #define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
      |                            ^~~~~~~~
/usr/include/python3.12/object.h:254:43: note: in expansion of macro '_PyObject_CAST'
  254 | #  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
      |                                           ^~~~~~~~~~~~~~
/usr/include/python3.12/longobject.h:14:31: note: in expansion of macro 'Py_IS_TYPE'
   14 | #define PyLong_CheckExact(op) Py_IS_TYPE((op), &PyLong_Type)
      |                               ^~~~~~~~~~
pymusic.cpp:2871:9: note: in expansion of macro 'PyLong_CheckExact'
 2871 |  likely(PyLong_CheckExact(obj)) ?\
      |         ^~~~~~~~~~~~~~~~~
pymusic.cpp:13679:20: note: in expansion of macro '__Pyx_PyObject_AsDouble'
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                    ^~~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:13679:45: error: invalid cast from type 'std::string' {aka 'std::__cxx11::basic_string<char>'} to type 'PyObject*' {aka '_object*'}
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:2872:18: note: in definition of macro '__Pyx_PyObject_AsDouble'
 2872 |  PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
      |                  ^~~
pymusic.cpp:13679:45: error: invalid cast from type 'std::string' {aka 'std::__cxx11::basic_string<char>'} to type 'PyObject*' {aka '_object*'}
13679 |       __pyx_t_10 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_v_vs)); if (unlikely(__pyx_t_10 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L10_error)
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
pymusic.cpp:2872:50: note: in definition of macro '__Pyx_PyObject_AsDouble'
 2872 |  PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
      |                                                  ^~~
pymusic.cpp: At global scope:
pymusic.cpp:25805:15: warning: 'double __Pyx__PyObject_AsDouble(PyObject*)' defined but not used [-Wunused-function]
25805 | static double __Pyx__PyObject_AsDouble(PyObject* obj) {
      |               ^~~~~~~~~~~~~~~~~~~~~~~~

@hroncok
Copy link

hroncok commented Nov 14, 2023

I belive this might be a regression in Cython, I've opened cython/cython#5818

@hroncok
Copy link

hroncok commented Nov 14, 2023

With cython/cython@bbbe428 Cython 3 works here.

@sanjayankur31
Copy link
Author

I've got a WIP spec here, waiting on Cython 3.0.6:

https://bugzilla.redhat.com/show_bug.cgi?id=2224366

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

No branches or pull requests

2 participants