RustAudio/vst-rs

Calling convention of `HostCallbackProc` causes warnings

Boscop opened this issue · 1 comments

Running cargo test says:

warning: `extern` fn uses type `fn(*mut AEffect, i32, i32, isize, *mut c_void, f32) -> isize`, which is not FFI-safe
   --> src\lib.rs:182:47
    |
179 |         pub extern "system" fn MAIN(callback: $crate::api::HostCallbackProc) -> *mut $crate::api::AEffect {
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
...
325 |     plugin_main!(TestPlugin);
    |     ------------------------- in this macro invocation
    |
    = note: `#[warn(improper_ctypes_definitions)]` on by default
    = help: consider using an `extern fn(...) -> ...` function pointer instead
    = note: this function pointer has Rust-specific calling convention
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

(same warning for VSTPluginMain)

The issue is that HostCallbackProc is defined without extern, defaulting to Rust calling convention:

pub type HostCallbackProc =
    fn(effect: *mut AEffect, opcode: i32, index: i32, value: isize, ptr: *mut c_void, opt: f32) -> isize;

We have

vst-rs/src/lib.rs

Lines 165 to 186 in 3f88b99

macro_rules! plugin_main {
($t:ty) => {
#[cfg(target_os = "macos")]
#[no_mangle]
pub extern "system" fn main_macho(callback: $crate::api::HostCallbackProc) -> *mut $crate::api::AEffect {
VSTPluginMain(callback)
}
#[cfg(target_os = "windows")]
#[allow(non_snake_case)]
#[no_mangle]
pub extern "system" fn MAIN(callback: $crate::api::HostCallbackProc) -> *mut $crate::api::AEffect {
VSTPluginMain(callback)
}
#[allow(non_snake_case)]
#[no_mangle]
pub extern "C" fn VSTPluginMain(callback: $crate::api::HostCallbackProc) -> *mut $crate::api::AEffect {
$crate::main::<$t>(callback)
}
};
}

so the calling conv of HostCallbackProc would have to be "system" for main_macho and MAIN, but "C" for VSTPluginMain.

We can't make HostCallbackProc instantiatable for different calling conventions, but what should we do about the warning?
Should we do anything about it, or just #[allow()] it?

We shouldn't silence the warning; it's incorrect for it not to be extern. But I believe it should just be extern "C" in all three cases. Anyway, #141 fixes this.