Skip to content

Commit

Permalink
Revert to prior init mechanism to support pypy (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeharker authored May 26, 2024
1 parent 801e9f1 commit bd87768
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/_rtmidi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ __all__ = (
'get_compiled_api', 'get_compiled_api_by_name', 'get_rtmidi_version'
)

cdef extern from "Python.h":
void Py_Initialize()
cdef extern from "py_init.h":
void py_init()

Py_Initialize()
py_init()

# Declarations for RtMidi C++ classes and their methods we use

Expand Down
22 changes: 22 additions & 0 deletions src/py_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <Python.h>
/*
* This code initializes Python threads and GIL, because RtMidi calls Python
* from native threads.
*
* See http://permalink.gmane.org/gmane.comp.python.cython.user/5837
*
* *PyEval_InitThreads* is a no-op since Python.37 and deprecated since
* Python 3.6. Now *Py_Initialize* initializes the GIL.
*
* The calls are in this separate C file instead of in the main .pyx file so
* that we can use pre-compiler conditionals and don't get a compiler
* deprecation warning on Python 3.9+ for including *PyEval_InitThreads*.
*/

void py_init() {
#if !defined(PYPY_VERSION) and PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 7
Py_Initialize();
#else
PyEval_InitThreads();
#endif
}

0 comments on commit bd87768

Please sign in to comment.