From 057660e546424ecd8241296c365f8878e29c017a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 21 Feb 2018 10:29:14 -0800 Subject: [PATCH] fix python3.7 support --- CHANGES.txt | 2 ++ build.rs | 9 ++++++++- src/pythonrun.rs | 4 +--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4b422056..2d7c65c6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/build.rs b/build.rs index 2ffe199a..8c2b61fc 100644 --- a/build.rs +++ b/build.rs @@ -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), diff --git a/src/pythonrun.rs b/src/pythonrun.rs index cf02c7c4..b137804f 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -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