RustAudio / vst-rs

VST 2.4 API implementation in rust. Create plugins or hosts. Previously rust-vst on the RustDSP group.
MIT License
1.04k stars 91 forks source link

Calling convention of `HostCallbackProc` causes warnings #157

Closed Boscop closed 3 years ago

Boscop commented 3 years ago

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 https://github.com/RustAudio/vst-rs/blob/3f88b991640c989eb3ed412c59bb87124a940dfb/src/lib.rs#L165-L186 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?

glowcoil commented 3 years ago

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.