Use Arc instead of Box for the wrapper
We'll need this for the GuiContext.
This commit is contained in:
parent
d1840b8d86
commit
4ceb0efdc4
|
@ -4,6 +4,7 @@ use clap_sys::plugin_factory::clap_plugin_factory;
|
|||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
use std::ptr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::descriptor::PluginDescriptor;
|
||||
use super::plugin::Wrapper;
|
||||
|
@ -60,7 +61,10 @@ impl<P: ClapPlugin> Factory<P> {
|
|||
|
||||
if !plugin_id.is_null() && CStr::from_ptr(plugin_id) == factory.plugin_descriptor.clap_id()
|
||||
{
|
||||
&Box::leak(Wrapper::<P>::new(host)).clap_plugin
|
||||
// Arc does not have a convenient leak function like Box, so this gets a bit awkward
|
||||
// This pointer gets turned into an Arc and its reference count decremented in
|
||||
// [Wrapper::destroy()]
|
||||
&(*Arc::into_raw(Wrapper::<P>::new(host))).clap_plugin
|
||||
} else {
|
||||
ptr::null()
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ use std::ffi::{c_void, CStr};
|
|||
use std::os::raw::c_char;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::thread::{self, ThreadId};
|
||||
|
||||
use super::context::WrapperProcessContext;
|
||||
|
@ -214,7 +215,7 @@ impl<P: ClapPlugin> MainThreadExecutor<Task> for Wrapper<P> {
|
|||
}
|
||||
|
||||
impl<P: ClapPlugin> Wrapper<P> {
|
||||
pub fn new(host_callback: *const clap_host) -> Box<Self> {
|
||||
pub fn new(host_callback: *const clap_host) -> Arc<Self> {
|
||||
let plugin_descriptor = Box::new(PluginDescriptor::default());
|
||||
|
||||
assert!(!host_callback.is_null());
|
||||
|
@ -371,7 +372,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
.map(|(_, hash, ptr)| (*ptr, hash))
|
||||
.collect();
|
||||
|
||||
Box::new(wrapper)
|
||||
Arc::new(wrapper)
|
||||
}
|
||||
|
||||
fn make_process_context(&self) -> WrapperProcessContext<'_, P> {
|
||||
|
@ -515,7 +516,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
}
|
||||
|
||||
unsafe extern "C" fn destroy(plugin: *const clap_plugin) {
|
||||
Box::from_raw(plugin as *mut Self);
|
||||
Arc::from_raw(plugin as *mut Self);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn activate(
|
||||
|
|
Loading…
Reference in a new issue