[BUG] Using types.CodeType in Python 3.11 fails with ValueError: types.CodeType size changed, may indicate binary incompatibility. Expected 168 from C header, got 160 from PyObject
See original GitHub issueVersions:
- Cython
0.29
branch: commit c0dfb9c2f592b7e0ece90ec83fbadcf6e6da3d47 (May 17, 2022) - Python 3.11.0b3+: commit a848a9894d (Jun 6 2022)
Reproducer, myext.pyx
:
# cython: language_level=3
cdef extern from "Python.h":
ctypedef class types.CodeType [object PyCodeObject]:
pass
Build the extension (I make the assumption that cythonize
uses Python 3.11):
cythonize -i myext.pyx
Importing the C extension fails:
$ python3.11 -c 'import myext'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "myext.pyx", line 1, in init myext
# cython: language_level=3
ValueError: types.CodeType size changed, may indicate binary incompatibility. Expected 168 from C header, got 160 from PyObject
To get Python 3.11 with Cython, you can use for example:
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0b3.tar.xz
tar -xf Python-3.11.0b3.tar.xz
cd Python-3.11.0b3
./configure --prefix /opt/py311
make
make install
cd ..
/opt/py311/bin/python3.11 -m pip install Cython
Then use /opt/py311/bin/cythonize
. You can use a different prefix.
The problem is that tp_basicsize
of &PyCode_Type
is 160 bytes, whereas and sizeof(PyCodeObject)
is 168 bytes.
Issue discovered when on my PR to update gevent to Python 3.11: https://github.com/gevent/gevent/pull/1872#issuecomment-1146149244
@hroncok proposed a Cython pull request in Fedora: https://src.fedoraproject.org/rpms/Cython/pull-request/35
I am working on reworking @hroncok’s PR to propose a PR to the master branch of Cython.
cc @encukou who helped to debug this tedious issue.
Issue Analytics
- State:
- Created a year ago
- Comments:20 (15 by maintainers)
Top Results From Across the Web
may indicate binary incompatibility.. PyObject segmentation fault
Expected 896 from C header, got 904 from PyObject Segmentation fault ... builtins.type size changed, may indicate binary incompatibility.
Read more >Issue 47236: Document types.CodeType.replace() changes ...
CodeType.replace(co_code=new_code) must now pass co_exceptiontable or exception handling will no longer work as expected. Callers are ...
Read more >RuntimeWarning: numpy.dtype size changed, may indicate ...
When import scipy, error info shows: RuntimeWarning: builtin.type size changed, may indicate binary incompatibility. Expected zd, got zd.
Read more >The Python/C API
Most Python/C API functions have one or more arguments as well as a return value of type PyObject*. This type is.
Read more >What's New in Python 3.11 - YouTube
Anthony Shaw – Microsoft's own Senior Open Source Advocate specializing in Python and Cloud solutions gives an exhaustive speech on what's ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has been resolved by weakening the conditions in https://github.com/cython/cython/pull/4894
Yes, it does 😦 It seems that the upper bound should be rounded up to the nearest
alignof(the struct)
boundary. (Butalignof
is C11. For older C… well, people tend to get away with usingsizeof(long long)
as maximum alignment, or even hardcoding it to 64 – even on platforms wherelong long
has 128-byte alignment, sincelong long
is rare in complex structs.)It’s good to know there is possibility to admit defeat 😃