As a data point, I don't remember that recent versions of CPython brought any particular pain for PyArrow, which is a set of bindings written in Cython around some C++ core library code.
Regards Antoine. On Wed, 27 Apr 2022 18:31:13 +0200 Victor Stinner <vstin...@python.org> wrote: > Hi, > > If you got issues with using the Python C API <Python.h> in C++, > please speak up! I'm looking for feedback :-) > > Extending Python by writing C++ code is now easy with the pybind11 project: > https://pybind11.readthedocs.io/ > > It seems like over the last years, building C++ extensions with the > Python C API started to emit more C++ compiler warnings. One > explanation may be that converting macros to static inline functions > (PEP 670) introduce new warnings, even if the old and the new code is > exactly the same. I just discover this issue recently. C and C++ > compilers treat static inline functions differently. Macros are > treated at legacy code which cannot be fixed, like system headers or > old C header files, and so many warnings are made quiet. Static inline > functions (defined in header files) are treated as regular code and > compilers are more eager to emit warnings. > > I just modified the Python C API to use C++ static_cast<type>(expr) > and reinterpret_cast<type>(expr) if it's used with C++. In C, the > regular (type)expr cast (called "old-style cast" by C++ compilers ;-)) > is still used as before. > > I'm also working on adding an unit test to make suite that using the > Python C API works with a C++ compiler and doesn't emit compiler > warnings: > > * https://github.com/python/cpython/issues/91321 > * https://github.com/python/cpython/pull/32175 > > In terms of C++ version, it was proposed to target C++11. > > In the pythoncapi-compat project, I got warnings when the NULL > constant is used in static inline functions. I modified the > pythoncapi_compat.h header file to use nullptr if used with C++ to fix > these compiler warnings. So far, I'm unable to reproduce the issue > with <Python.h>, and so I didn't try to address this issue in Python. > > Victor _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/JFRJID3ETO3GZ5UHKONDA45WTUS5N7KE/ Code of Conduct: http://python.org/psf/codeofconduct/