(I already replied to some of your questions in my reply to Hugh.)
Le jeu. 4 juin 2020 à 12:09, Petr Viktorin email@example.com a écrit :
I see that the current documentation of Py_TYPE, Py_REFCNT ans Py_SIZE suggest that using them as lvalues is perfectly valid. There is no mention that anything changed.
Oh, it seems like https://docs.python.org/dev/ is no longer updated for an unknown reason.
The documentation was updated.
If you look into the up to date Git repository, Py_TYPE() got a ".. versionchanged:: 3.10" markup, and the change is mentioned in "Porting to Python 3.10: C API Changes" section of What's New in Python 3.10. https://github.com/python/cpython/blob/master/Doc/c-api/structures.rst
My project py3c was ment as compatibility headers for the 2→3 transition, but I ended up taking pull requests for newer features as well: https://github.com/encukou/py3c
That's an interesting approach, to automate "updating" C extensions to the newer C API.
There is also a similar project for Python code: https://github.com/asottile/pyupgrade (and many others more specific for Python 2 => Python 3 migration).
One option is to copy/paste compatibility macros like Py_SET_SIZE() for old Python versions directly in the C code of these extensions. It avoids depending on something external. It's a variant of having a vendored copy of an hypothetical PythonCompat.h header file.
By the way, it's also how Cython handles backward compatibility.
Night gathers, and now my watch begins. It shall not end until my death.