bodograumann / python-iconv

Python 3 wrapper for iconv and usage as codecs
GNU General Public License v3.0
7 stars 2 forks source link

Python 3.11: iconvmodule.c:166:26: error: lvalue required as left operand of assignment #6

Closed jwilk closed 2 years ago

jwilk commented 2 years ago

python-iconv fails to build with Python 3.11:

$ python3 --version
Python 3.11.0a1

$ python3 setup.py build
running build
running build_py
running build_ext
building 'iconv' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.11 -c iconvmodule.c -o build/temp.linux-x86_64-3.11/iconvmodule.o
iconvmodule.c: In function ‘Iconv_iconv’:
iconvmodule.c:112:35: warning: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
  112 |     iresult = iconv(self->handle, &inbuf, &inbuf_size, &outbuf, &outbuf_size);
      |                                   ^~~~~~
      |                                   |
      |                                   const char **
In file included from iconvmodule.c:1:
/usr/include/iconv.h:42:54: note: expected ‘char ** restrict’ but argument is of type ‘const char **’
   42 | extern size_t iconv (iconv_t __cd, char **__restrict __inbuf,
      |                                    ~~~~~~~~~~~~~~~~~~^~~~~~~
iconvmodule.c:122:17: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  122 |     if (iresult == -1) {
      |                 ^~
iconvmodule.c: In function ‘PyInit_iconv’:
iconvmodule.c:166:26: error: lvalue required as left operand of assignment
  166 |     Py_TYPE(&Iconv_Type) = &PyType_Type;
      |                          ^
error: command '/usr/bin/gcc' failed with exit code 1

This seems to be caused by https://github.com/python/cpython/commit/f3fa63ec75fdbb4a08a10957a5c631bf0c4a5970:

Convert the Py_TYPE() and Py_SIZE() macros to static inline functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be used to set an object type and size.

bodograumann commented 2 years ago

Thank you so much for reporting this issue. I have released version 1.1.2 which should fix it.

jwilk commented 2 years ago

Yup, 1.1.2 works for me. Thanks for the quick fix.