pytroll / aggdraw

Python package wrapping AGG2 drawing functionality
https://aggdraw.readthedocs.io/en/latest/
Other
99 stars 47 forks source link

Attempt to fix PyPy/CPython 3.8+ compatibility #86

Open djhoese opened 1 year ago

djhoese commented 1 year ago

Conda-forge has been trying for a long time to build a PyPy binary of aggdraw, but has been failing:

https://github.com/conda-forge/aggdraw-feedstock/pull/25

The error is basically:

  aggdraw.cxx:271:1: error: invalid conversion from 'printfunc' {aka 'int (*)(_object*, FILE*, int)'} to 'Py_ssize_t' {aka 'long int'} [-fpermissive]
    271 | };
        | ^
        | |
        | printfunc {aka int (*)(_object*, FILE*, int)}
  aggdraw.cxx:312:1: error: invalid conversion from 'printfunc' {aka 'int (*)(_object*, FILE*, int)'} to 'Py_ssize_t' {aka 'long int'} [-fpermissive]
    312 | };
        | ^
        | |
        | printfunc {aka int (*)(_object*, FILE*, int)}
  error: command '/home/conda/feedstock_root/build_artifacts/aggdraw_1667346120715/_build_env/bin/x86_64-conda-linux-gnu-cc' failed with exit code 1

It turns out printfunc is deprecated and unused, but was repurposed in Python 3.8:

https://peps.python.org/pep-0590/#changes-to-the-pytypeobject-struct

I found a PR in swig that had to make the same type of update (https://github.com/swig/swig/pull/2264) so I copied that simple logic here. Once merged I'll have to cherry-pick it to the maint branch so it can be released for the current stable version.

I should be able to turn on PyPy wheel builds in CI too.

djhoese commented 1 year ago

Ok turns out this is much harder than I thought. Here's what Cython says and we're a pure C++ module at this point:

https://cython.readthedocs.io/en/stable/src/userguide/pypy.html

This will just have to wait I guess.