diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index f019568..58dc53c 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -127,7 +127,7 @@ macro_rules! call_py_func { e, // 获取 traceback match &e { - PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback_bound(py) { + PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback(py) { Some(traceback) => match traceback.format() { Ok(trace) => trace, Err(trace_e) => format!("failed to format traceback: {:?}", trace_e), diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 56435b4..d53d0f1 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -2,6 +2,7 @@ pub mod call; pub mod class; pub mod config; +use std::ffi::CString; use std::path::Path; use std::time::SystemTime; use std::{collections::HashMap, path::PathBuf}; @@ -133,7 +134,7 @@ impl PyStatus { } pub fn get_py_err_traceback(py_err: &PyErr) -> String { - Python::with_gil(|py| match py_err.traceback_bound(py) { + Python::with_gil(|py| match py_err.traceback(py) { Some(traceback) => match traceback.format() { Ok(trace) => trace, Err(e) => format!("{:?}", e), @@ -398,11 +399,11 @@ pub fn get_change_time(path: &Path) -> Option { path.metadata().ok() pub fn py_module_from_code(content: &str, path: &Path) -> PyResult> { Python::with_gil(|py| -> PyResult> { - let module: PyResult> = PyModule::from_code_bound( + let module: PyResult> = PyModule::from_code( py, - content, - &path.to_string_lossy(), - &path.file_name().unwrap().to_string_lossy(), + CString::new(content).unwrap().as_c_str(), + CString::new(path.to_string_lossy().as_bytes()).unwrap().as_c_str(), + CString::new(path.file_name().unwrap().to_string_lossy().as_bytes()).unwrap().as_c_str(), // !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的 ) .map(|module| module.into());