diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-04-30 18:59:35 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-04-30 18:59:35 -0300 |
commit | 8c2bbf82a4b63668fa5b8a11ed9f98eea79324fb (patch) | |
tree | 40aed8957e26eca61b937e48930ee8cf98aae3fb /src/mock | |
parent | 3badc34d8f963a2b0145440d7908de746cbd9da3 (diff) |
Add progress on mock
It's broken. But we don't plan on finishing anytime soon. Just wanna publish the crate tbh.
Diffstat (limited to 'src/mock')
-rw-r--r-- | src/mock/mod.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/mock/mod.rs b/src/mock/mod.rs index f4193e0..ed41780 100644 --- a/src/mock/mod.rs +++ b/src/mock/mod.rs @@ -38,17 +38,19 @@ //! //! This API is not stable. Do not rely on this API to be stable. +use std::cell::Cell; use std::cell::RefCell; use std::ffi::CStr; use std::ffi::CString; use std::marker::PhantomData; +use std::marker::PhantomPinned; use std::pin::Pin; use std::ptr; use libc::c_char; #[repr(C)] -pub struct MockPlugin { +struct MockPlugin { // NOTE: MUST be first thing in the struct. methods: crate::internals::Ph, filename: *const c_char, @@ -56,6 +58,8 @@ pub struct MockPlugin { plugin_desc: *const c_char, plugin_vers: *const c_char, free_strings: bool, + env: *const PluginEnvironment, + _pin: PhantomPinned, } enum MockCallback { @@ -87,14 +91,18 @@ enum MockCallback { } // This MockHook is deliberately incompatible with hexchat's own hook struct. -struct MockHook { - pl: *mut MockPlugin, +struct MockHook<'hook, 'env> { + pl: &MockPlugin<'env>, cb: RefCell<MockCallback>, name: Option<Box<str>>, pri_or_fd: libc::c_int, + userdata: *mut libc::c_void, } -struct PluginEnvironment { +pub struct PluginEnvironment<'env> { + plugins: Option<Vec<Pin<Box<MockPluginOpaque<'env>>>>>, + hooks: Option<Vec<Pin<Box<MockHookOpaque<'env>>>>>, + depth: usize, } unsafe extern "C" fn hexchat_hook_command( @@ -317,8 +325,20 @@ unsafe extern "C" fn hexchat_event_attrs_free(ph: *mut crate::internals::Hexchat todo!(); } +impl PluginEnvironment { + pub fn new() -> Pin<Box<Self>> { + Box::pin(Self { + plugins: Default::default(), + hooks: Default::default(), + depth: Default::default(), + _pin: PhantomPinned, + }) + } +} + impl MockPlugin { pub fn new<T: for<'ph> crate::Plugin<'ph> + Default>( + env: Pin<&PluginEnvironment>, filename: CString, arg: Option<&CStr>, ) -> Option<Pin<Box<MockPlugin>>> { @@ -373,6 +393,8 @@ impl MockPlugin { plugin_desc: ptr::null(), plugin_vers: ptr::null(), free_strings: false, + env: &*env, + _pin: PhantomPinned, }); if unsafe { let ptr: *mut MockPlugin = &mut *plug; |