ruby-changes:66255
From: Sutou <ko1@a...>
Date: Tue, 18 May 2021 12:49:05 +0900 (JST)
Subject: [ruby-changes:66255] 71d4a493b8 (master): [ruby/fiddle] windows: add Fiddle.win32_last_socket_error{, =}
https://git.ruby-lang.org/ruby.git/commit/?id=71d4a493b8 From 71d4a493b890a21fdf3b302849d6d60c11ba1d9e Mon Sep 17 00:00:00 2001 From: Sutou Kouhei <kou@c...> Date: Mon, 19 Apr 2021 16:37:17 +0900 Subject: [ruby/fiddle] windows: add Fiddle.win32_last_socket_error{,=} GitHub: fix GH-72 Users can't use WSAGetLastError() with Ruby 3.0 or later because rb_funcall() resets the last socket error internally. Users can get the last socket error by Fiddle.win32_last_socket_error. Reported by Kentaro Hayashi. Thanks!!! https://github.com/ruby/fiddle/commit/76158db00a --- ext/fiddle/function.c | 11 +++++++++-- ext/fiddle/lib/fiddle.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c index 1d82bc8..d15a54b 100644 --- a/ext/fiddle/function.c +++ b/ext/fiddle/function.c @@ -375,10 +375,17 @@ function_call(int argc, VALUE argv[], VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/function.c#L375 (void)rb_thread_call_without_gvl(nogvl_ffi_call, &args, 0, 0); } - rb_funcall(mFiddle, rb_intern("last_error="), 1, INT2NUM(errno)); + { + int errno_keep = errno; #if defined(_WIN32) - rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, INT2NUM(errno)); + int socket_error = WSAGetLastError(); + rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, + INT2NUM(errno_keep)); + rb_funcall(mFiddle, rb_intern("win32_last_socket_error="), 1, + INT2NUM(socket_error)); #endif + rb_funcall(mFiddle, rb_intern("last_error="), 1, INT2NUM(errno_keep)); + } ALLOCV_END(alloc_buffer); diff --git a/ext/fiddle/lib/fiddle.rb b/ext/fiddle/lib/fiddle.rb index 3fdf525..4512989 100644 --- a/ext/fiddle/lib/fiddle.rb +++ b/ext/fiddle/lib/fiddle.rb @@ -17,6 +17,18 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/ext/fiddle/lib/fiddle.rb#L17 def self.win32_last_error= error Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error end + + # Returns the last win32 socket +Error+ of the current executing + # +Thread+ or nil if none + def self.win32_last_socket_error + Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] + end + + # Sets the last win32 socket +Error+ of the current executing + # +Thread+ to +error+ + def self.win32_last_socket_error= error + Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error + end end # Returns the last +Error+ of the current executing +Thread+ or nil if none -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/