Skip to content

Commit

Permalink
On windows, when using Ruby built with mingw64, FFI:LIBC returns msvc…
Browse files Browse the repository at this point in the history
…rt.dll. When using Ruby built with MSVC, FFI:LIBC returns vcruntime.dll

Neither is correct. Starting in Visual Studio 2015, the C runtime library migrated to ucrtbase.dll. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 for more information. Or https://devblogs.microsoft.com/cppblog/introducing-the-universal-crt/.

I assume this hasn't been reported as a bug since almost no one uses a MSVC Ruby build, and attach_function for functions like malloc does actually work using msvcrt.dll - but does not with vcruntime.dll

This patch changes mingw64 and mswin to use ucrtbase.dll for the C library. Tested both with mswin and mingw64 Ruby builds.

The one downside of this patch is that it would break for anyone running a version of Windows that hasn't been updated since Spring 2015 when Microsoft introduced this change (the dll ships with Windows 10 and was back ported to older windows versions via Windows update). So seems to me a very, very low risk.
  • Loading branch information
cfis committed May 18, 2020
1 parent d9bd3f9 commit c674683
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ffi/platform.rb
Expand Up @@ -129,7 +129,7 @@ def self.is_os(os)
end

LIBC = if IS_WINDOWS
RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll'
"ucrtbase.dll"
elsif IS_GNU
GNU_LIBC
elsif OS == 'cygwin'
Expand Down

0 comments on commit c674683

Please sign in to comment.