我正在尝试构建一个共享库模块,以供Kamailio使用rust-bindgen
加载。模块接口需要符号exports
指向Kamailio
中定义的C结构。
此结构包含一些函数指针和其他指针字段(声明为const *T
),因此无法实现Sync
。如何在安全或不安全的Rust中导出此类符号?
我是否需要为我的Rust共享库模块编写包装C对象,只是为了导出该符号?
我正在使用稳定的Rust 2018 Edition和最新的rust-bindgen
。
这是模块导出符号的结构类型的声明。由bindgen
生成并由我修改。
#[doc = " kamailio/openser module exports version"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct kam_module_exports {
#[doc = "< null terminated module name"]
pub name: *const ::std::os::raw::c_char,
#[doc = "< flags for dlopen"]
pub dlflags: ::std::os::raw::c_uint,
#[doc = "< null terminated array of the exported"]
#[doc = "commands"]
pub cmds: *const kam_cmd_export_t,
#[doc = "< null terminated array of the exported"]
#[doc = "module parameters"]
pub params: *const param_export_t,
#[doc = "< null terminated array of the exported"]
#[doc = "module statistics"]
pub stats: *const stat_export_t,
#[doc = "< null terminated array of the exported"]
#[doc = "NN functions"]
pub nn_cmds: *const nn_export_t,
#[doc = "< null terminated array of the exported"]
#[doc = "module items (pseudo-variables)"]
pub items: *const pv_export_t,
#[doc = "< null terminated array of the"]
#[doc = "additional processes required by the"]
#[doc = "module"]
pub procs: *const proc_export_t,
#[doc = "< Initialization function"]
pub init_f: init_function,
#[doc = "< function used for responses,"]
#[doc = "returns yes or no; can be null"]
pub response_f: response_function,
#[doc = "< function called when the module should"]
#[doc = "be \"destroyed\", e.g: on ser exit;"]
#[doc = "can be null"]
pub destroy_f: destroy_function,
#[doc = "< function called by all processes"]
#[doc = "after the fork"]
pub init_child_f: child_init_function,
}
出口符号声明如下:
#[no_mangle]
pub static exports: *const ::kamailio_mod::kam_module_exports =
&::kamailio_mod::kam_module_exports {
name: &name[0],
dlflags: 0,
cmds: &cmd_exports[0],
params: ::std::ptr::null_mut(),
stats: ::std::ptr::null_mut(),
nn_cmds: ::std::ptr::null_mut(),
items: ::std::ptr::null_mut(),
procs: ::std::ptr::null_mut(),
init_f: None,
response_f: None,
destroy_f: None,
init_child_f: None,
};
错误[E0277]:* const kamailio_mod :: kam_module_exports无法在线程之间安全共享