Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Port to Python 3.11: use Py_SET_SIZE()#114

Merged
martindurant merged 1 commit into
intake:masterintake/python-snappy:masterfrom
vstinner:python311Copy head branch name to clipboard
Dec 8, 2021
Merged

Port to Python 3.11: use Py_SET_SIZE()#114
martindurant merged 1 commit into
intake:masterintake/python-snappy:masterfrom
vstinner:python311Copy head branch name to clipboard

Conversation

@vstinner

@vstinner vstinner commented Dec 6, 2021

Copy link
Copy Markdown
Contributor

On Python 3.11, "Py_SIZE(str) = actual_size;" fails with a compiler
error. Since Python 3.9, Py_SET_SIZE() must be used instead:

Add a copy of the pythoncapi_compat.h header file to get
Py_SET_SIZE() on Python 3.8 and older:
https://github.com/pythoncapi/pythoncapi_compat

On Python 3.11, "Py_SIZE(str) = actual_size;" fails with a compiler
error. Since Python 3.9, Py_SET_SIZE() must be used instead:

* https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes
* https://docs.python.org/dev/c-api/structures.html#c.Py_SIZE

Add a copy of the pythoncapi_compat.h header file to get
Py_SET_SIZE() on Python 3.8 and older:
https://github.com/pythoncapi/pythoncapi_compat
@martindurant

Copy link
Copy Markdown
Member

I am no expert, so hopefully someone else can confirm this is good. If there are no objections, I can merge it in a couple of days.

@vstinner

vstinner commented Dec 7, 2021

Copy link
Copy Markdown
Contributor Author

Without my change, the build fails:

$ git switch master
$ rm -rf build; LANG= ~/python/main/python setup.py build_ext
(...)
building 'snappy._snappy' extension
(...)
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c src/snappy/crc32c.c -o build/temp.linux-x86_64-3.11-pydebug/src/snappy/crc32c.o
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c src/snappy/snappymodule.cc -o build/temp.linux-x86_64-3.11-pydebug/src/snappy/snappymodule.o
In file included from /home/vstinner/python/main/Include/Python.h:42,
                 from src/snappy/snappymodule.cc:29:
src/snappy/snappymodule.cc: In function ‘PyObject* maybe_resize(PyObject*, size_t, size_t)’:
/home/vstinner/python/main/Include/object.h:146:29: error: lvalue required as left operand of assignment
  146 | #define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob))
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/snappy/snappymodule.cc:72:13: note: in expansion of macro ‘Py_SIZE’
   72 |             Py_SIZE(str) = actual_size;
      |             ^~~~~~~
error: command '/usr/bin/gcc' failed with exit code 1

With the change, the build completes succesfully:

$ git switch python311 
$ rm -rf build; LANG= ~/python/main/python setup.py build_ext
(...)
building 'snappy._snappy' extension
(...)
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c src/snappy/crc32c.c -o build/temp.linux-x86_64-3.11-pydebug/src/snappy/crc32c.o
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c src/snappy/snappymodule.cc -o build/temp.linux-x86_64-3.11-pydebug/src/snappy/snappymodule.o
(...)
g++ -pthread -shared build/temp.linux-x86_64-3.11-pydebug/src/snappy/crc32c.o build/temp.linux-x86_64-3.11-pydebug/src/snappy/snappymodule.o -lsnappy -o build/lib.linux-x86_64-3.11-pydebug/snappy/_snappy.cpython-311d-x86_64-linux-gnu.so

@martindurant martindurant merged commit 1a539d7 into intake:master Dec 8, 2021
@vstinner vstinner deleted the python311 branch December 8, 2021 19:18
@vstinner

vstinner commented Dec 8, 2021

Copy link
Copy Markdown
Contributor Author

Nice, thanks ;-)

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 this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.