Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to prior init mechanism to support pypy #202

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading