use crate::EMPTY_CSTRING_DATA;
use crate::cstr;
use std::mem;
use std::ffi::CString;
#[derive(Copy, Clone)]
pub struct PluginInfo {
pub name: *mut *const libc::c_char,
pub desc: *mut *const libc::c_char,
pub vers: *mut *const libc::c_char,
}
impl PluginInfo {
pub unsafe fn new(name: *mut *const libc::c_char, desc: *mut *const libc::c_char, vers: *mut *const libc::c_char) -> Option<PluginInfo> {
if name.is_null() || desc.is_null() || vers.is_null() || name == desc || desc == vers || name == vers {
None
} else {
Some(PluginInfo::new_unchecked(name, desc, vers))
}
}
pub unsafe fn new_unchecked(name: *mut *const libc::c_char, desc: *mut *const libc::c_char, vers: *mut *const libc::c_char) -> PluginInfo {
PluginInfo {
name, desc, vers
}
}
pub unsafe fn drop_info(&mut self) {
if !(*self.name).is_null() {
mem::drop(CString::from_raw(*self.name as *mut _));
*self.name = cstr(EMPTY_CSTRING_DATA);
}
if !(*self.desc).is_null() {
mem::drop(CString::from_raw(*self.desc as *mut _));
*self.desc = cstr(EMPTY_CSTRING_DATA);
}
if !(*self.vers).is_null() {
mem::drop(CString::from_raw(*self.vers as *mut _));
*self.vers = cstr(EMPTY_CSTRING_DATA);
}
}
}