free-audio / clap

Audio Plugin API
https://cleveraudio.org/
MIT License
1.77k stars 100 forks source link

Missing calling conventions for the function pointers #153

Closed robbert-vdh closed 1 year ago

robbert-vdh commented 2 years ago

After pulling my hair out trying to figure out why some plugins would initialize just fine when calling clap_entry->init() in this new Wine CLAP plugin bridge I've been working on while others don't, I finally realized that CLAP doesn't specify any calling conventions. Which means that on 32-bit Windows calling any CLAP functions is currently undefined behavior. This is mostly relevant on 32-bit Windows as 64-bit Windows uses a single calling convention, but having explicit calling conventions is still useful as there already are 32-bit Windows CLAP hosts and plugins. Wine these calling conventions are also mandatory when working with Winelib applications like I was.

The fix for this would be to define something like a CLAP_ABI macro that's set to __cdecl on Windows and and that's empty on other platforms. All function pointers bool(*foo)(int bar) in the CLAP API then need to be changed to bool(CLAP_ABI *foo)(int bar).

EDIT: Fixed some errors, I misremembered some things.

robbert-vdh commented 2 years ago

I just realized that the __stdcall versus __cdecl story is only relevant for 32-bit Windows. But I'd still appreciate a CLAP_ABI in CLAP nonetheless, as it's also required for Wine bridging to work. I'll submit a PR for this soon.

sagamusix commented 2 years ago

For reference, cdecl usage was also discussed in #21 (but nothing came out of it as the other changes were dropped)