paulscherrerinstitute / cbf

GNU General Public License v3.0
12 stars 9 forks source link

cbf module should be built with PY_SSIZE_T_CLEAN to support Python 3.10+ #16

Closed sstendahl closed 1 year ago

sstendahl commented 1 year ago

Hey,

The cbf module does not work with Python 3.10 and later. This is due to a change since this version that requires PY_SSIZE_T_CLEAN to be defined before including Python.h in the build. See the documentation on this matter: https://docs.python.org/3/c-api/arg.html#strings-and-buffers

Note

For all # variants of formats (s#, y#, etc.), the macro PY_SSIZE_T_CLEAN must be defined before including Python.h. On Python 3.9 and older, the type of the length argument is Py_ssize_t if the PY_SSIZE_T_CLEAN macro is defined, or int otherwise.

I tried to include#define PY_SSIZE_T_CLEAN on top of the python-cbf.c before building cbf myself. This does get rid of the error, but then I get a segementation fault while I try to open a cbf file. I do not know if this is related, and I don't really have the time to test this further right now. For reference, I tested this with Fedora Silverblue 37 inside a toolbox with Python 3.11. I only tried to open this with my own tool built in Python 3.11 using this modified module. Didn't try to open it in Python directly. A segmentation fault typically is C-related though, so I don't think it's something in (my own) Python code, my guess is some additional configuration is required to get it working on Python => 3.10.

If I do happen to find the time, and figure it out I'll open a Pull Request, but I figure you (the devs of this project) are more familiar with the code-base so it may be more efficient to just submit this bug report.

sstendahl commented 1 year ago

Got a fix working on my machine, I had to define the Py_ssize_t type as well. See related PR: https://github.com/paulscherrerinstitute/cbf/pull/17