Skip to content

Commit

Permalink
Cherry-pick upstream fixes to support building against python3 librar…
Browse files Browse the repository at this point in the history
…ies (#201)

* [python-3.7-fix]: Allow compilation with Python 3.7

PyOS_AfterFork() is deprecated in favour of the new functions
PyOS_BeforeFork(), PyOS_AfterFork_Parent() and
PyOS_AfterFork_Child(). (Contributed by Antoine Pitrou in bpo-16500.)

* ChangeLog: python: Fix compile-time errors about deprecation via ifdefs.

Co-authored-by: Manoj Srivastava <[email protected]>
Co-authored-by: Paul <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2022
1 parent 04cccf4 commit 98b4dc7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,18 @@ static void *cpy_interactive(void *pipefd) {
cpy_log_exception("interactive session init");
}
cur_sig = PyOS_setsig(SIGINT, python_sigint_handler);
#if PY_VERSION_HEX < 0x03070000
PyOS_AfterFork();
#else
PyOS_AfterFork_Child();
#endif
#if PY_VERSION_HEX < 0x03090000
// deprecated. Called by Py_Initialize(). Removed in Py3.11
// https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
PyEval_InitThreads();
#else
Py_Initialize();
#endif
close(*(int *)pipefd);
PyRun_InteractiveLoop(stdin, "<stdin>");
PyOS_setsig(SIGINT, cur_sig);
Expand Down Expand Up @@ -1174,7 +1184,13 @@ static int cpy_init(void) {
;
(void)close(pipefd[0]);
} else {
#if PY_VERSION_HEX < 0x03090000
// deprecated. Called by Py_Initialize(). Removed in Py3.11
// https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
PyEval_InitThreads();
#else
Py_Initialize();
#endif
state = PyEval_SaveThread();
}
CPY_LOCK_THREADS
Expand Down

0 comments on commit 98b4dc7

Please sign in to comment.