ruby-changes:66765
From: Sutou <ko1@a...>
Date: Tue, 13 Jul 2021 19:38:21 +0900 (JST)
Subject: [ruby-changes:66765] d1eeb9fec9 (master): [ruby/fiddle] windows: use GetLastError() for win32_last_error
https://git.ruby-lang.org/ruby.git/commit/?id=d1eeb9fec9 From d1eeb9fec953c41ebaf312d7a56948bca43e9f93 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei <kou@c...> Date: Tue, 20 Apr 2021 10:58:23 +0900 Subject: [ruby/fiddle] windows: use GetLastError() for win32_last_error Ruby: [Bug #11579] Patch by cremno phobia. Thanks!!! https://github.com/ruby/fiddle/commit/760a8f9b14 --- ext/fiddle/function.c | 3 ++- test/fiddle/test_function.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c index d15a54b..274d181 100644 --- a/ext/fiddle/function.c +++ b/ext/fiddle/function.c @@ -378,9 +378,10 @@ function_call(int argc, VALUE argv[], VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/function.c#L378 { int errno_keep = errno; #if defined(_WIN32) + DWORD error = WSAGetLastError(); int socket_error = WSAGetLastError(); rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, - INT2NUM(errno_keep)); + ULONG2NUM(error)); rb_funcall(mFiddle, rb_intern("win32_last_socket_error="), 1, INT2NUM(socket_error)); #endif diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb index a5284e0..ea5f054 100644 --- a/test/fiddle/test_function.rb +++ b/test/fiddle/test_function.rb @@ -9,6 +9,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L9 def setup super Fiddle.last_error = nil + Fiddle.win32_last_error = nil if WINDOWS end def test_default_abi @@ -94,6 +95,19 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L95 refute_nil Fiddle.last_error end + if WINDOWS + def test_win32_last_error + kernel32 = dlopen('kernel32') + args = [kernel32['SetLastError'], [TYPE_LONG], TYPE_VOID] + args << Function::STDCALL if Function.const_defined?(:STDCALL) + set_last_error = Function.new(*args) + assert_nil(Fiddle.win32_last_error) + n = 1 << 29 | 1 + set_last_error.call(n) + assert_equal(n, Fiddle.win32_last_error) + end + end + def test_strcpy f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) buff = +"000" -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/