python / pythoncapi-compat

The pythoncapi-compat project can be used to write a C extension supporting a wide range of Python versions with a single code base.
https://pythoncapi-compat.readthedocs.io/
BSD Zero Clause License
80 stars 23 forks source link

fix for pypy3.9-v7.3.11 #59

Closed logicsys closed 1 year ago

logicsys commented 1 year ago

Python 3.9.16 (feeb267ead3e6771d3f2f49b83e1894839f64fb7, Dec 29 2022, 14:23:21) PyPy 7.3.11 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)

Tests run fine on pypy 7.3.11 with those 2 changes

Ran 24 tests in 0.154s

OK

Python 2.7 (release build): 11 C tests succeeded! Ignore missing Python executable: python3.4 Ignore missing Python executable: python3.5 Ignore missing Python executable: python3.6 Ignore missing Python executable: python3.7 Ignore missing Python executable: python3.8 CPython 3.9 (release build): 11 C tests succeeded! CPython 3.9 (release build): 11 C++03 tests succeeded! CPython 3.9 (release build): 11 C++11 tests succeeded! Ignore missing Python executable: python3.10 Ignore missing Python executable: python3.11 Ignore missing Python executable: python3.12 Ignore missing Python executable: python3-debug Ignore missing Python executable: pypy Ignore missing Python executable: pypy2 Ignore missing Python executable: pypy2.7 Ignore missing Python executable: pypy3 Ignore missing Python executable: pypy3.6 Ignore missing Python executable: pypy3.7 Ignore missing Python executable: pypy3.8 Ignore missing Python executable: pypy3.9 PyPy 3.9 (release build): 8 C tests succeeded! PyPy 3.9 (release build): 8 C++03 tests succeeded! PyPy 3.9 (release build): 8 C++11 tests succeeded!

Tested: 3 Python executables

vstinner commented 1 year ago

Currently, when I run pypy3.9 runtests.py --current locally, it fails with:

building 'test_pythoncapi_compat_cext' extension
creating build
creating build/temp.linux-x86_64-3.9
gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/include/pypy3.9 -c test_pythoncapi_compat_cext.c -o build/temp.linux-x86_64-3.9/test_pythoncapi_compat_cext.o -I/home/vstinner/python/pythoncapi-compat -Werror -Wall -Wextra -Wconversion -Wno-typedef-redefinition -std=c99
In file included from /usr/include/pypy3.9/Python.h:123,
                 from /home/vstinner/python/pythoncapi-compat/pythoncapi_compat.h:21,
                 from test_pythoncapi_compat_cext.c:4:
/usr/include/pypy3.9/pypy_decl.h:648:29: error: static declaration of 'PyPyObject_CallNoArgs' follows non-static declaration
  648 | #define PyObject_CallNoArgs PyPyObject_CallNoArgs
      |                             ^~~~~~~~~~~~~~~~~~~~~
/home/vstinner/python/pythoncapi-compat/pythoncapi_compat.h:395:1: note: in expansion of macro 'PyObject_CallNoArgs'
  395 | PyObject_CallNoArgs(PyObject *func)
      | ^~~~~~~~~~~~~~~~~~~
/usr/include/pypy3.9/pypy_decl.h:648:29: note: previous declaration of 'PyPyObject_CallNoArgs' with type 'struct _object *(struct _object *)'
  648 | #define PyObject_CallNoArgs PyPyObject_CallNoArgs
      |                             ^~~~~~~~~~~~~~~~~~~~~
/usr/include/pypy3.9/pypy_decl.h:649:30: note: in expansion of macro 'PyObject_CallNoArgs'
  649 | PyAPI_FUNC(struct _object *) PyObject_CallNoArgs(struct _object *arg0);
      |                              ^~~~~~~~~~~~~~~~~~~
/usr/include/pypy3.9/pypy_decl.h:652:29: error: static declaration of 'PyPyObject_CallOneArg' follows non-static declaration
  652 | #define PyObject_CallOneArg PyPyObject_CallOneArg
      |                             ^~~~~~~~~~~~~~~~~~~~~
/home/vstinner/python/pythoncapi-compat/pythoncapi_compat.h:406:1: note: in expansion of macro 'PyObject_CallOneArg'
  406 | PyObject_CallOneArg(PyObject *func, PyObject *arg)
      | ^~~~~~~~~~~~~~~~~~~
/usr/include/pypy3.9/pypy_decl.h:652:29: note: previous declaration of 'PyPyObject_CallOneArg' with type 'struct _object *(struct _object *, struct _object *)'
  652 | #define PyObject_CallOneArg PyPyObject_CallOneArg
      |                             ^~~~~~~~~~~~~~~~~~~~~
/usr/include/pypy3.9/pypy_decl.h:653:30: note: in expansion of macro 'PyObject_CallOneArg'
  653 | PyAPI_FUNC(struct _object *) PyObject_CallOneArg(struct _object *arg0, struct _object *arg1);
      |                              ^~~~~~~~~~~~~~~~~~~
cc1: note: unrecognized command-line option '-Wno-typedef-redefinition' may have been intended to silence earlier diagnostics
error: command '/usr/bin/gcc' failed with exit code 1

But 7 months ago, the pypy3.9 job completed successfully: https://github.com/python/pythoncapi-compat/actions/runs/3557936154 on commit 3779f1221363b0f8c65c4f0ee24b36603c98547a. Did PyPy 3.9 added PyObject_CallNoArgs() and PyObject_CallOneArg() recently?

logicsys commented 1 year ago

Yeah they were added in 3.9-v7.3.11 and were not present in 3.9-v7.3.10

logicsys commented 1 year ago

Of course if the older pypy versions are failing with this change, we'll need to have it only take effect for pypy3.9-v7.3.11.. Will have a go later today

logicsys commented 1 year ago

Hmm this PR works for me on both 3.9-v7.3.11 & 3.9-v7.3.10..

vstinner commented 1 year ago

The 3.12-dev CI was broken, I just fixed it: commit 513acb3b060272652c8b2d6d600e45b976c73755. Please rebase your PR on top of it.

vstinner commented 1 year ago

Yeah they were added in 3.9-v7.3.11 and were not present in 3.9-v7.3.10

Hum, that's annoying. Since it's implemented as a macro in PyPy, what do you think of checking if the macro is already defined or not, rather than checking for PyPy? #if !defined(PyObject_CallNoArgs) && ... existing check ....

logicsys commented 1 year ago

yeah that sounds like a better approach, will try now

vstinner commented 1 year ago

It's kind of sad that PyPy updates requires fixing pythoncapi_compat.h, but so far, I failed to find a "future proof" approach to support PyPy.

vstinner commented 1 year ago

I merged your PR, thanks.