[前][次][番号順一覧][スレッド一覧]

ruby-changes:71427

From: YO4 <ko1@a...>
Date: Wed, 16 Mar 2022 10:28:46 +0900 (JST)
Subject: [ruby-changes:71427] 5d90c60109 (master): Avoid console input behavior in windows 10 [Bug #18588]

https://git.ruby-lang.org/ruby.git/commit/?id=5d90c60109

From 5d90c6010999ac11d25822f13f0b29d377f81755 Mon Sep 17 00:00:00 2001
From: YO4 <ysno@a...>
Date: Wed, 16 Mar 2022 10:28:35 +0900
Subject: Avoid console input behavior in windows 10 [Bug #18588]

When ANSI versions of PeekConsoleInput read multibyte charactor
partially, subsequent ReadFile returns wrong data on newer Windows
10 versions (probably since Windows Terminal introduced).  To
avoid this, use Unicode version of of PeekConsoleInput/ReadConsole.
---
 win32/win32.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/win32/win32.c b/win32/win32.c
index 832725a645..c202e65e92 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3085,7 +3085,7 @@ is_console(SOCKET sock) /* DONT call this for SOCKET! */ https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3085
     INPUT_RECORD ir;
 
     RUBY_CRITICAL {
-	ret = (PeekConsoleInput((HANDLE)sock, &ir, 1, &n));
+	ret = (PeekConsoleInputW((HANDLE)sock, &ir, 1, &n));
     }
 
     return ret;
@@ -3100,13 +3100,13 @@ is_readable_console(SOCKET sock) /* call this for console only */ https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3100
     INPUT_RECORD ir;
 
     RUBY_CRITICAL {
-	if (PeekConsoleInput((HANDLE)sock, &ir, 1, &n) && n > 0) {
+	if (PeekConsoleInputW((HANDLE)sock, &ir, 1, &n) && n > 0) {
 	    if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
 		ir.Event.KeyEvent.uChar.AsciiChar) {
 		ret = 1;
 	    }
 	    else {
-		ReadConsoleInput((HANDLE)sock, &ir, 1, &n);
+		ReadConsoleInputW((HANDLE)sock, &ir, 1, &n);
 	    }
 	}
     }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]