Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
602 stars 345 forks source link

Compiling `pythonShim.cpp` with Python 3.12 issues a deprecated declaration warning #1715

Closed bryanwweber closed 3 months ago

bryanwweber commented 3 months ago

As of Python 3.12, the Py_UnbufferedStdioFlag is deprecated, and a warning is issued:

gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -Iinclude -Iinclude/cantera/ext -Isrc -Icantera -I/tmp/build-env-ryhje233/lib/python3.12/site-packages/numpy/_core/include -I/tmp/build-env-ryhje233/include -I/home/bryan/.local/share/mise/installs/python/3.12.4/include/python3.12 -c src/extensions/pythonShim.cpp -o build/temp.linux-x86_64-cpython-312/src/extensions/pythonShim.o -std=c++17 -g0
src/extensions/pythonShim.cpp: In function ‘void Cantera::loadCanteraPython()’:
src/extensions/pythonShim.cpp:74:5: warning: ‘Py_UnbufferedStdioFlag’ is deprecated [-Wdeprecated-declarations]
   74 |     Py_UnbufferedStdioFlag = 1;
      |     ^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/bryan/.local/share/mise/installs/python/3.12.4/include/python3.12/Python.h:48,
                 from src/extensions/pythonShim.cpp:15:
/home/bryan/.local/share/mise/installs/python/3.12.4/include/python3.12/cpython/pydebug.h:20:37: note: declared here
   20 | Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_UnbufferedStdioFlag;
      |                                     ^~~~~~~~~~~~~~~~~~~~~~

See https://docs.python.org/3/c-api/init.html#c.Py_UnbufferedStdioFlag. Can be replaced by https://docs.python.org/3/c-api/init_config.html. It remains to be seen how far back the init_config struct is compatible.

bryanwweber commented 3 months ago

This seems to go all the way back to 3.8, so it should be good for all our versions: https://docs.python.org/3.8/c-api/init_config.html#c.PyConfig.buffered_stdio