Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Win32API with Fiddle, update appveyor.yml #1053

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ on_failure:
- find tmp -name "*.log" | xargs cat
environment:
matrix:
- ruby_version: "26-x64"
MINGW_PACKAGE_PREFIX: "mingw-w64-x86_64"
- ruby_version: "25-x64"
MINGW_PACKAGE_PREFIX: "mingw-w64-x86_64"
- ruby_version: "24-x64"
MINGW_PACKAGE_PREFIX: "mingw-w64-x86_64"
- ruby_version: "24"
Expand Down
9 changes: 6 additions & 3 deletions lib/mysql2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
end

if dll_path
require 'Win32API'
LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I')
if LoadLibrary.call(dll_path).zero?
require 'fiddle'
kernel32 = Fiddle.dlopen 'kernel32'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should still be initial cap Kernel32 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, not reusing it are we?

Copy link
Collaborator

@sodabrew sodabrew Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the library:Win32API.new('Kernel32', ...
vs. Fiddle.dlopen 'kernel32'

Maybe irrelevant because of case insensitivity? But if there's a "correct" convention I'd like to use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. between multi-tasking & bouncing between languages, I often miss the obvious.

Actually, the file is kernel32.dll, and as you know, Windows file system is case-insensitive (which can cause issues when comparing paths, use casecmp...)

Also, ruby/reline essentially created its own Win32API class to avoid the deprecation warnings, and it's all lower case. See lib/reline/windows.rb

Long story short, I think we're ok...

load_library = Fiddle::Function.new(
kernel32['LoadLibraryW'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT,
)
if load_library.call(dll_path.encode('utf-16le')).zero?
abort "Failed to load libmysql.dll from #{dll_path}"
end
end
Expand Down