1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::cell::Cell;
use std::rc::Rc;
#[allow(unused_imports)]
use std::marker::PhantomData;
#[allow(unused_imports)]
use std::os::raw::c_void;
#[allow(unused_imports)]
use std::mem::transmute;
#[allow(unused_imports)]
use std::ffi::{CStr, CString};
use rute_ffi_base::*;
#[allow(unused_imports)]
use auto::*;
use auto::rute_ffi::*;
static mut G_RUTE_FFI: u64 = 0;
pub fn rute_ffi_get() -> *const RuteFFI {
unsafe {
if G_RUTE_FFI == 0 {
panic!("Global FFI hasn't been setup. This is usually caused by Rute::new() not being called first. Otherwise report a issue at the issue tracker in the README.");
}
G_RUTE_FFI as *const RuteFFI
}
}
pub(crate) unsafe extern "C" fn rute_object_delete_callback(data: *const c_void) {
let d = Rc::from_raw(data as *const Cell<Option<RUBase>>);
d.set(None);
}
pub struct Rute;
impl Rute {
#[cfg(not(feature = "plugin-compatible"))]
pub fn new() {
unsafe { G_RUTE_FFI = rute_static_ffi_get() as u64 };
}
#[cfg(feature = "plugin-compatible")]
pub fn new(rute_ffi: *const RuteFFI) -> Rute {
unsafe { G_RUTE_FFI = rute_ffi as u64 };
}
}