ninia / jep

Embed Python in Java
Other
1.33k stars 150 forks source link

Update pyembed.c code to not have deprecation warnings on PyEval_InitThreads #355

Closed ndjensen closed 2 years ago

ndjensen commented 2 years ago

When building Jep 4.0 with Python 3.10, the following warning is produced:

src/main/c/Jep/pyembed.c: In function ‘pyembed_startup’:
src/main/c/Jep/pyembed.c:398:5: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]
     PyEval_InitThreads();
     ^~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/python3.10/Python.h:144,
                 from src/main/c/Include/jep_platform.h:35,
                 from src/main/c/Include/Jep.h:35,
                 from src/main/c/Jep/pyembed.c:44:
/usr/local/include/python3.10/ceval.h:122:37: note: declared here
 Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
                                     ^~~~~~~~~~~~~~~~~~

The documentation also points this out: https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads

Update the code to not have the deprecation warning with newer versions of Python. This may require the use of macros like #IF PY_MINOR_VERSION > 8 depending on how old of versions of Python we're supporting, I'm not sure.

The documentation says this method will be removed in Python 3.11 so this should be targeted for Jep 4.1.0 at the latest or 4.0.x if there is an earlier release.

ndjensen commented 2 years ago

Fix is here: https://github.com/ninia/jep/commit/0866d0a85554a0b9af372c549db571a66f524082

ndjensen commented 2 years ago

This is part of the 4.0.1 release.