summaryrefslogtreecommitdiff
path: root/ext/fiddle
diff options
context:
space:
mode:
authorSutou Kouhei <kou@clear-code.com>2021-04-19 16:37:17 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-05-18 12:48:40 +0900
commit71d4a493b890a21fdf3b302849d6d60c11ba1d9e (patch)
tree76cb4bdf49d11ea385907efa30a3664f5fc6ed4b /ext/fiddle
parent2579593a56fd96d9085daa7f11dfc2dd231cb70f (diff)
[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
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4506
Diffstat (limited to 'ext/fiddle')
-rw-r--r--ext/fiddle/function.c11
-rw-r--r--ext/fiddle/lib/fiddle.rb12
2 files changed, 21 insertions, 2 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c
index 1d82bc8a3e..d15a54bfa6 100644
--- a/ext/fiddle/function.c
+++ b/ext/fiddle/function.c
@@ -375,10 +375,17 @@ function_call(int argc, VALUE argv[], VALUE self)
(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 3fdf525b4c..4512989310 100644
--- a/ext/fiddle/lib/fiddle.rb
+++ b/ext/fiddle/lib/fiddle.rb
@@ -17,6 +17,18 @@ module Fiddle
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