fix python3.7 support

This commit is contained in:
Nikolay Kim 2018-02-21 10:29:14 -08:00
parent d50d1fb7ea
commit 057660e546
3 changed files with 11 additions and 4 deletions

View File

@ -4,6 +4,8 @@ Changes
0.2.5 (2018-02-21)
^^^^^^^^^^^^^^^^^^
* CPython 3.7 support
* Embedded CPython 3.7b1 crashes on initialization #110
* Generated extension functions are weakly typed #108

View File

@ -453,7 +453,14 @@ fn main() {
Err(_) => PythonVersion{major: 3, minor: None}
};
let (python_interpreter_path, flags) = configure_from_path(&version).unwrap();
let config_map = get_config_vars(&python_interpreter_path).unwrap();
let mut config_map = get_config_vars(&python_interpreter_path).unwrap();
// WITH_THREAD is always on for 3.7
let (interpreter_version, _, _) = find_interpreter_and_get_config(&version).unwrap();
if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 {
config_map.insert("WITH_THREAD".to_owned(), "1".to_owned());
}
for (key, val) in &config_map {
match cfg_line_for_var(key, val) {
Some(line) => println!("{}", line),

View File

@ -39,12 +39,11 @@ pub fn prepare_freethreaded_python() {
if ffi::Py_IsInitialized() != 0 {
// If Python is already initialized, we expect Python threading to also be initialized,
// as we can't make the existing Python main thread acquire the GIL.
#[cfg(py_sys_config = "WITH_THREAD")]
assert_ne!(ffi::PyEval_ThreadsInitialized(), 0);
} else {
// If Python isn't initialized yet, we expect that Python threading
// isn't initialized either.
#[cfg(py_sys_config = "WITH_THREAD")]
#[cfg(not(Py_3_7))]
assert_eq!(ffi::PyEval_ThreadsInitialized(), 0);
// Initialize Python.
// We use Py_InitializeEx() with initsigs=0 to disable Python signal handling.
@ -52,7 +51,6 @@ pub fn prepare_freethreaded_python() {
// Note that the 'main thread' notion in Python isn't documented properly;
// and running Python without one is not officially supported.
ffi::Py_InitializeEx(0);
#[cfg(py_sys_config = "WITH_THREAD")]
ffi::PyEval_InitThreads();
// PyEval_InitThreads() will acquire the GIL,
// but we don't want to hold it at this point