fix: use c_char instead of i8/u8

This commit is contained in:
Kingtous 2023-04-10 16:54:50 +08:00
parent 1883c05b76
commit dc7692952b
2 changed files with 8 additions and 6 deletions

View File

@ -1,8 +1,10 @@
use std::ffi::c_char;
use crate::plugins::PLUGIN_REGISTRAR;
// API provided by RustDesk.
pub type LoadPluginFunc = fn(*const i8) -> i32;
pub type UnloadPluginFunc = fn(*const i8) -> i32;
pub type LoadPluginFunc = fn(*const c_char) -> i32;
pub type UnloadPluginFunc = fn(*const c_char) -> i32;
#[repr(C)]
pub struct RustDeskApiTable {
@ -11,12 +13,12 @@ pub struct RustDeskApiTable {
}
#[no_mangle]
fn load_plugin(path: *const i8) -> i32 {
fn load_plugin(path: *const c_char) -> i32 {
PLUGIN_REGISTRAR.load_plugin(path)
}
#[no_mangle]
fn unload_plugin(path: *const i8) -> i32 {
fn unload_plugin(path: *const c_char) -> i32 {
PLUGIN_REGISTRAR.unload_plugin(path)
}

View File

@ -75,7 +75,7 @@ pub struct PluginRegistar<P: Plugin> {
}
impl<P: Plugin> PluginRegistar<P> {
pub fn load_plugin(&self, path: *const i8) -> i32 {
pub fn load_plugin(&self, path: *const c_char) -> i32 {
let p = unsafe { CStr::from_ptr(path) };
let lib_path = p.to_str().unwrap_or("").to_owned();
let lib = unsafe { libloading::Library::new(lib_path.as_str()) };
@ -100,7 +100,7 @@ impl<P: Plugin> PluginRegistar<P> {
-1
}
pub fn unload_plugin(&self, path: *const i8) -> i32 {
pub fn unload_plugin(&self, path: *const c_char) -> i32 {
let p = unsafe { CStr::from_ptr(path) };
let lib_path = p.to_str().unwrap_or("").to_owned();
match PLUGIN_REGISTRAR.plugins.write().unwrap().remove(&lib_path) {