diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 0931de5..0ff947d 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -694,9 +694,13 @@ class TestThreadGroup < Test::Unit::TestCase Process.kill(:SIGINT, pid) Process.wait(pid) s = $? - assert_equal([false, true, false], - [s.exited?, s.signaled?, s.stopped?], - "[s.exited?, s.signaled?, s.stopped?]") + if /mswin|mingw/ =~ RUBY_PLATFORM + assert_equal(pid, s.pid) + else + assert_equal([false, true, false], + [s.exited?, s.signaled?, s.stopped?], + "[s.exited?, s.signaled?, s.stopped?]") + end t1 = Time.now.to_f assert_in_delta(t1 - t0, 1, 1) end diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 4149c8a..8c2fbde 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -691,6 +691,7 @@ if defined? Zlib t.close Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") } f = open(t.path) + f.binmode assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read }) assert_raise(IOError) { f.close } end diff --git a/thread_win32.c b/thread_win32.c index 873d37d..da971e7 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -231,7 +231,7 @@ static void ubf_handle(void *ptr); int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout) { - return w32_wait_events(events, num, timeout, GET_THREAD()); + return w32_wait_events(events, num, timeout, ruby_thread_from_native()); } int @@ -240,7 +240,7 @@ rb_w32_wait_events(HANDLE *events, int num, DWORD timeout) int ret; BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout), - ubf_handle, GET_THREAD()); + ubf_handle, ruby_thread_from_native()); return ret; } @@ -285,7 +285,7 @@ w32_create_thread(DWORD stack_size, w32_thread_start_func func, void *val) int rb_w32_sleep(unsigned long msec) { - return w32_wait_events(0, 0, msec, GET_THREAD()); + return w32_wait_events(0, 0, msec, ruby_thread_from_native()); } int WINAPI @@ -294,7 +294,7 @@ rb_w32_Sleep(unsigned long msec) int ret; BLOCKING_REGION(ret = rb_w32_sleep(msec), - ubf_handle, GET_THREAD()); + ubf_handle, ruby_thread_from_native()); return ret; } diff --git a/win32/win32.c b/win32/win32.c index 7cb1b31..744c614 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1132,7 +1132,7 @@ CreateChild(const WCHAR *cmd, const WCHAR *prog, SECURITY_ATTRIBUTES *psa, aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); } - dwCreationFlags = (NORMAL_PRIORITY_CLASS); + dwCreationFlags = (CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS); if (lstrlenW(cmd) > 32767) { child->pid = 0; /* release the slot */ @@ -4094,7 +4094,13 @@ kill(int pid, int sig) case SIGINT: RUBY_CRITICAL({ - if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, (DWORD)pid)) { + DWORD ctrlEvent = CTRL_C_EVENT; + if (pid != 0) { + /* CTRL+C signal cannot be generated for process groups. + * Instead, we use CTRL+BREAK signal. */ + ctrlEvent = CTRL_BREAK_EVENT; + } + if (!GenerateConsoleCtrlEvent(ctrlEvent, (DWORD)pid)) { if ((err = GetLastError()) == 0) errno = EPERM; else @@ -5569,6 +5575,10 @@ rb_w32_read(int fd, void *buf, size_t size) } } } + else { + err = GetLastError(); + errno = map_errno(err); + } if (pol) { CloseHandle(ol.hEvent); @@ -5585,7 +5595,8 @@ rb_w32_read(int fd, void *buf, size_t size) ret += read; if (read >= len) { buf = (char *)buf + read; - if (!(isconsole && len == 1 && (!islineinput || *((char *)buf - 1) == '\n')) && size > 0) + if (err != ERROR_OPERATION_ABORTED && + !(isconsole && len == 1 && (!islineinput || *((char *)buf - 1) == '\n')) && size > 0) goto retry; } if (read == 0)