From ae71536639d4966c6cf83e347059b5440005ac0c Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 28 Dec 2020 11:47:32 +0100 Subject: [PATCH] Add back __cdecl on older Wine versions --- CHANGELOG.md | 4 +++- meson.build | 14 ++++++++++++++ src/wine-host/group-host.cpp | 6 +++++- src/wine-host/individual-host.cpp | 6 +++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f80448e..f6c51f45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,9 @@ Versioning](https://semver.org/spec/v2.0.0.html). - Changed part of the build process considering [this Wine bug](https://bugs.winehq.org/show_bug.cgi?id=49138). Building with Wine 5.7 and 5.8 required a change, but that change now breaks builds using Wine 6.0 - and up, so this change has been reverted. + and up. We now detect which version of Wine is used to build with, and we then + apply the change conditionally to be able to support building with both older + and newer versions of Wine. ## [2.2.1] - 2020-12-12 diff --git a/meson.build b/meson.build index 3c0fc744..f045d95d 100644 --- a/meson.build +++ b/meson.build @@ -48,6 +48,20 @@ if with_winedbg compiler_options += '-DWITH_WINEDBG' endif +# Wine versions after Wine 5.6 and before 6.0 require a `__cdecl` calling +# convention to be specified on the `main()` functions or else `argc` and `argv` +# will point to the wrong memory. Similarly, with other versions of Wine this +# should _not_ be specified for the same reason. We'll try to figure out the +# current Wine version and add this calling convention based on that. +# +# https://bugs.winehq.org/show_bug.cgi?id=49138 +wine_version = run_command('sh', '-c', '''wine --version | grep --only-matching -E '[0-9]+\.[0-9.]+' | head -n1''') +if wine_version.returncode() == 0 and \ + wine_version.stdout().version_compare('>=5.7') and \ + wine_version.stdout().version_compare('<6.0') + compiler_options += '-DWINE_USE_CDECL' +endif + # Generate header files for configuration variables such as the current git tag # and the name of the host binary subdir('src/common/config') diff --git a/src/wine-host/group-host.cpp b/src/wine-host/group-host.cpp index 03f7ceb4..d276ea6a 100644 --- a/src/wine-host/group-host.cpp +++ b/src/wine-host/group-host.cpp @@ -36,7 +36,11 @@ * this group plugin host will function identically on both the plugin and the * Wine VST host side. */ -int __attribute__((visibility("default"))) main(int argc, char* argv[]) { +int __attribute__((visibility("default"))) +#ifdef WINE_USE_CDECL +__cdecl +#endif + main(int argc, char* argv[]) { set_realtime_priority(); // Instead of directly hosting a plugin, this process will receive a UNIX diff --git a/src/wine-host/individual-host.cpp b/src/wine-host/individual-host.cpp index 3be1b9ae..0693c171 100644 --- a/src/wine-host/individual-host.cpp +++ b/src/wine-host/individual-host.cpp @@ -29,7 +29,11 @@ * plugin, and then connect back to the `libyabridge.so` instance that spawned * this over the socket. */ -int __attribute__((visibility("default"))) main(int argc, char* argv[]) { +int __attribute__((visibility("default"))) +#ifdef WINE_USE_CDECL +__cdecl +#endif + main(int argc, char* argv[]) { set_realtime_priority(); // We pass the name of the VST plugin .dll file to load and the base