1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/fiddle] windows: use GetLastError() for win32_last_error

Ruby: [Bug #11579]

Patch by cremno phobia. Thanks!!!

https://github.com/ruby/fiddle/commit/760a8f9b14
This commit is contained in:
Sutou Kouhei 2021-04-20 10:58:23 +09:00 committed by Nobuyoshi Nakada
parent c0f9191ab6
commit d1eeb9fec9
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 16 additions and 1 deletions

View file

@ -378,9 +378,10 @@ function_call(int argc, VALUE argv[], VALUE self)
{
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

View file

@ -9,6 +9,7 @@ module Fiddle
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
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"