fix: 修复3个P0遗留 — AutoRollback回退/ConfigReloaded序列化/FfiString跨allocator
This commit is contained in:
@@ -64,6 +64,7 @@ pub enum Message {
|
||||
ssid: String,
|
||||
ip: String,
|
||||
},
|
||||
ConfigReloaded(serde_json::Value),
|
||||
ConfigReloadRequest,
|
||||
Shutdown,
|
||||
PluginReady(String),
|
||||
@@ -104,6 +105,20 @@ impl FfiString {
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// 复制为 Rust String(不释放底层内存)
|
||||
///
|
||||
/// # Safety
|
||||
/// ptr 必须指向有效的 null-terminated C 字符串
|
||||
pub unsafe fn to_string(&self) -> Option<String> {
|
||||
if self.ptr.is_null() {
|
||||
return None;
|
||||
}
|
||||
unsafe { std::ffi::CStr::from_ptr(self.ptr) }
|
||||
.to_str()
|
||||
.ok()
|
||||
.map(str::to_owned)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -144,6 +159,7 @@ pub struct PluginVTable {
|
||||
pub handle_message:
|
||||
unsafe extern "C" fn(handle: PluginHandle, message_json: FfiStr) -> FfiResult,
|
||||
pub stop: unsafe extern "C" fn(handle: PluginHandle) -> FfiResult,
|
||||
pub free_string: unsafe extern "C" fn(s: FfiString),
|
||||
pub destroy: unsafe extern "C" fn(handle: PluginHandle),
|
||||
pub get_capabilities: unsafe extern "C" fn(handle: PluginHandle) -> FfiString,
|
||||
pub self_test: unsafe extern "C" fn(handle: PluginHandle) -> FfiString,
|
||||
@@ -371,6 +387,12 @@ macro_rules! export_plugin {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn __showen_free_string(s: $crate::FfiString) {
|
||||
if !s.ptr.is_null() {
|
||||
drop(unsafe { std::ffi::CString::from_raw(s.ptr) });
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn __showen_get_capabilities(
|
||||
handle: $crate::PluginHandle,
|
||||
) -> $crate::FfiString {
|
||||
@@ -409,6 +431,7 @@ macro_rules! export_plugin {
|
||||
start: __showen_start,
|
||||
handle_message: __showen_handle_message,
|
||||
stop: __showen_stop,
|
||||
free_string: __showen_free_string,
|
||||
destroy: __showen_destroy,
|
||||
get_capabilities: __showen_get_capabilities,
|
||||
self_test: __showen_self_test,
|
||||
|
||||
Reference in New Issue
Block a user