https://bz.mercurial-scm.org/show_bug.cgi?id=6451

            Bug ID: 6451
           Summary: Py_SET_TYPE() should be used to support Python 3.10
           Product: Mercurial
           Version: default branch
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: feature
          Priority: wish
         Component: Mercurial
          Assignee: bugzi...@mercurial-scm.org
          Reporter: victor.stin...@gmail.com
                CC: mercurial-devel@mercurial-scm.org
    Python Version: ---

Created attachment 2090
  --> https://bz.mercurial-scm.org/attachment.cgi?id=2090&action=edit
Patch adding pythoncapi_compat.h and replace Py_TYPE() assignments with
Py_SET_TYPE() calls.

In Python 3.10, "Py_SET_TYPE(obj, type)" should now be used instead of using
absuing the Py_TYPE() macro: "Py_TYPE(obj) = type;".

See https://www.python.org/dev/peps/pep-0620/ and
https://bugs.python.org/issue39573 for the rationale.

Py_TYPE() was converted to a static inline macro in Python 3.10 to raise a
compiler error on "Py_TYPE(obj) = type;". But since this change broke too many
C extensions, I reverted it.

So I'm now proposing patches to every broken C extensions before considering to
re-apply the change in the Python C API.

Attached patch replaces "Py_TYPE(obj) = type;" with "Py_SET_TYPE(obj, type);".
It adds a copy of the pythoncapi_compat.h header file coming from my project:
https://github.com/pythoncapi/pythoncapi_compat

The initial version of the patch was created by upgrade_pythoncapi.py tool
which is also part of pythoncapi_compat project.

Sadly, I had to copy pythoncapi_compat.h in two directories: mercurial/ and
contrib/python-zstandard/zstd/common/. I didn't know if a contrib/ extension
can add mercurial/ to its include directory list (-I compiler flag).

Feel free to rewrite my patch and steal the patch, I'm not sure to the
Mercurial code base.

There is no need to update pythoncapi_compat.h unless tomorrow you will need a
new function if a newer version of this header file. IMO it's a good practice
to vendor a copy of the header file (which is less than 300 lines of C code).
The pythoncapi_compat project is new and I'm not sure that it's going to be
packaged widely on Windows, macOS and very single Linux distribution (for
example).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to