From 75832bfa2e70dbd8964a452965379743d572ada0 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 19 Nov 2024 22:57:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E4=B8=80=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/py/call.rs | 2 +- ica-rs/src/py/mod.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) 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());