Skip to content

Unexpected error code with WSAGetLastError even though the previous function calll was failed #72

@kenhys

Description

@kenhys

The problem

There is a case that fiddle fails to get error code with WSAGetLastEror on Win32.

This problem is observed with Ruby 3.0 only.

Expected result

WSAGetLastError returns correct error code when previous function call was failed.

Actual result

WSAGetLastError returns 0 even thought when previous function call was failed.

  • Windows 10 20H2 (19042.870)
  • Ruby installer with fiddle 1.0.7

How to reproduce

Here is the sample code (test-wsagetlasterror.rb) to reproduce issue.

module WinSock
  require 'fiddle/import'
  extend Fiddle::Importer
  dlload 'ws2_32.dll'
  extern 'int bind(int, void *, int)'
  extern 'int WSAGetLastError(void)'
end

p WinSock.bind(0, nil, 0)
p WinSock.WSAGetLastError

When using with Ruby 2.7 https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.2-1/rubyinstaller-2.7.2-1-x64.exe
WinSock.WSAGetLastError returns 10038 (expected)

PS C:\work\fluentd> ridk use
1 - C:/Ruby25-x64       ruby 2.5.8p224 (2020-03-31 revision 67882) [x64-mingw32]
2 - C:/Ruby26-x64       ruby 2.6.6p146 (2020-03-31 revision 67876) [x64-mingw32]
3 - C:/Ruby27-x64       ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
4 - C:/Ruby30-x64       ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32]
Select ruby version to enable: 3
Disable C:/Ruby26-x64
Disable C:/Ruby30-x64
Enable C:/Ruby27-x64
PS C:\work\fluentd> ruby .\test-wsagetlasterror.rb
-1
10038

When using with Ruby 3.0 https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.0.0-1/rubyinstaller-3.0.0-1-x64.exe,
WinSock.WSAGetLastError returns 0 (not expected)

PS C:\work\fluentd> ridk use
1 - C:/Ruby25-x64       ruby 2.5.8p224 (2020-03-31 revision 67882) [x64-mingw32]
2 - C:/Ruby26-x64       ruby 2.6.6p146 (2020-03-31 revision 67876) [x64-mingw32]
3 - C:/Ruby27-x64       ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
4 - C:/Ruby30-x64       ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32]
Select ruby version to enable: 4
Disable C:/Ruby26-x64
Disable C:/Ruby27-x64
Enable C:/Ruby30-x64
PS C:\work\fluentd> ruby .\test-wsagetlasterror.rb
-1
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions