ruby-changes:29004
From: nagachika <ko1@a...>
Date: Tue, 4 Jun 2013 00:49:18 +0900 (JST)
Subject: [ruby-changes:29004] nagachika:r41056 (ruby_2_0_0): merge revision(s) 40887,40888,40894,40896: [Backport #8431]
nagachika 2013-06-04 00:49:06 +0900 (Tue, 04 Jun 2013) New Revision: 41056 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41056 Log: merge revision(s) 40887,40888,40894,40896: [Backport #8431] * win32/win32.c (setup_overlapped, finish_overlapped): extract from rb_w32_read() and rb_w32_write(). * win32/win32.c (setup_overlapped): check the error code in addition to the result of SetFilePointer() to determine if an error occurred, because INVALID_SET_FILE_POINTER is a valid value. [ruby-core:55098] [Bug #8431] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/test/ruby/test_io.rb branches/ruby_2_0_0/version.h branches/ruby_2_0_0/win32/win32.c Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 41055) +++ ruby_2_0_0/ChangeLog (revision 41056) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Tue Jun 4 00:46:05 2013 Nobuyoshi Nakada <nobu@r...> + + * win32/win32.c (setup_overlapped, finish_overlapped): extract from + rb_w32_read() and rb_w32_write(). + Tue Jun 4 00:02:45 2013 Nobuyoshi Nakada <nobu@r...> * vm_core.h (rb_vm_tag): move jmpbuf between tag and prev so ensure to Index: ruby_2_0_0/win32/win32.c =================================================================== --- ruby_2_0_0/win32/win32.c (revision 41055) +++ ruby_2_0_0/win32/win32.c (revision 41056) @@ -5867,6 +5867,49 @@ rb_w32_close(int fd) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L5867 return 0; } +static int +setup_overlapped(OVERLAPPED *ol, int fd) +{ + memset(ol, 0, sizeof(*ol)); + if (!(_osfile(fd) & (FDEV | FPIPE))) { + LONG high = 0; + DWORD method = _osfile(fd) & FAPPEND ? FILE_END : FILE_CURRENT; + DWORD low = SetFilePointer((HANDLE)_osfhnd(fd), 0, &high, method); +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#endif + if (low == INVALID_SET_FILE_POINTER) { + DWORD err = GetLastError(); + if (err != NO_ERROR) { + errno = map_errno(err); + return -1; + } + } + ol->Offset = low; + ol->OffsetHigh = high; + } + ol->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); + if (!ol->hEvent) { + errno = map_errno(GetLastError()); + return -1; + } + return 0; +} + +static void +finish_overlapped(OVERLAPPED *ol, int fd, DWORD size) +{ + CloseHandle(ol->hEvent); + + if (!(_osfile(fd) & (FDEV | FPIPE))) { + LONG high = ol->OffsetHigh; + DWORD low = ol->Offset + size; + if (low < ol->Offset) + ++high; + SetFilePointer((HANDLE)_osfhnd(fd), low, &high, FILE_BEGIN); + } +} + #undef read /* License: Ruby's */ ssize_t @@ -5927,25 +5970,7 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L5970 /* if have cancel_io, use Overlapped I/O */ if (cancel_io) { - memset(&ol, 0, sizeof(ol)); - if (!(_osfile(fd) & (FDEV | FPIPE))) { - LONG high = 0; - DWORD low = SetFilePointer((HANDLE)_osfhnd(fd), 0, &high, - FILE_CURRENT); -#ifndef INVALID_SET_FILE_POINTER -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#endif - if (low == INVALID_SET_FILE_POINTER) { - errno = map_errno(GetLastError()); - MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); - return -1; - } - ol.Offset = low; - ol.OffsetHigh = high; - } - ol.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - if (!ol.hEvent) { - errno = map_errno(GetLastError()); + if (setup_overlapped(&ol, fd)) { MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); return -1; } @@ -6003,15 +6028,7 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L6028 } if (pol) { - CloseHandle(ol.hEvent); - - if (!(_osfile(fd) & (FDEV | FPIPE))) { - LONG high = ol.OffsetHigh; - DWORD low = ol.Offset + read; - if (low < ol.Offset) - ++high; - SetFilePointer((HANDLE)_osfhnd(fd), low, &high, FILE_BEGIN); - } + finish_overlapped(&ol, fd, read); } ret += read; @@ -6071,25 +6088,7 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L6088 /* if have cancel_io, use Overlapped I/O */ if (cancel_io) { - memset(&ol, 0, sizeof(ol)); - if (!(_osfile(fd) & (FDEV | FPIPE))) { - LONG high = 0; - DWORD method = _osfile(fd) & FAPPEND ? FILE_END : FILE_CURRENT; - DWORD low = SetFilePointer((HANDLE)_osfhnd(fd), 0, &high, method); -#ifndef INVALID_SET_FILE_POINTER -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#endif - if (low == INVALID_SET_FILE_POINTER) { - errno = map_errno(GetLastError()); - MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); - return -1; - } - ol.Offset = low; - ol.OffsetHigh = high; - } - ol.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - if (!ol.hEvent) { - errno = map_errno(GetLastError()); + if (setup_overlapped(&ol, fd)) { MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); return -1; } @@ -6135,15 +6134,7 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/win32/win32.c#L6134 } if (pol) { - CloseHandle(ol.hEvent); - - if (!(_osfile(fd) & (FDEV | FPIPE))) { - LONG high = ol.OffsetHigh; - DWORD low = ol.Offset + written; - if (low < ol.Offset) - ++high; - SetFilePointer((HANDLE)_osfhnd(fd), low, &high, FILE_BEGIN); - } + finish_overlapped(&ol, fd, written); } ret += written; Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 41055) +++ ruby_2_0_0/version.h (revision 41056) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-06-04" -#define RUBY_PATCHLEVEL 200 +#define RUBY_PATCHLEVEL 201 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_0_0/test/ruby/test_io.rb =================================================================== --- ruby_2_0_0/test/ruby/test_io.rb (revision 41055) +++ ruby_2_0_0/test/ruby/test_io.rb (revision 41056) @@ -2655,4 +2655,35 @@ End https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_io.rb#L2655 IO.select(tempfiles) }, bug8080 end + + def test_read_32bit_boundary + bug8431 = '[ruby-core:55098] [Bug #8431]' + make_tempfile {|t| + assert_separately(["-", bug8431, t.path], <<-"end;") + msg = ARGV.shift + f = open(ARGV[0], "rb") + f.seek(0xffff_ffff) + assert_nil(f.read(1), msg) + end; + } + end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_write_32bit_boundary + bug8431 = '[ruby-core:55098] [Bug #8431]' + make_tempfile {|t| + assert_separately(["-", bug8431, t.path], <<-"end;", timeout: 30) + msg = ARGV.shift + f = open(ARGV[0], "wb") + f.seek(0xffff_ffff) + begin + # this will consume very long time or fail by ENOSPC on a + # filesystem which sparse file is not supported + f.write('1') + rescue SystemCallError + else + assert_equal(0x1_0000_0000, f.tell, msg) + end + end; + } + end if /mswin|mingw/ =~ RUBY_PLATFORM end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r40887-40888,40894,40896 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/