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

ruby-changes:42789

From: usa <ko1@a...>
Date: Sun, 1 May 2016 19:46:05 +0900 (JST)
Subject: [ruby-changes:42789] usa:r54863 (trunk): * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4

usa	2016-05-01 20:42:41 +0900 (Sun, 01 May 2016)

  New Revision: 54863

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54863

  Log:
    * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4
      support leftovers.
      [fix GH-1328] patched by @cremno

  Modified files:
    trunk/ChangeLog
    trunk/cont.c
    trunk/hash.c
    trunk/random.c
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54862)
+++ ChangeLog	(revision 54863)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May  1 20:39:47 2016  NAKAMURA Usaku  <usa@r...>
+
+	* cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4
+	  support leftovers.
+	  [fix GH-1328] patched by @cremno
+
 Sun May  1 07:30:44 2016  NARUSE, Yui  <naruse@r...>
 
 	* string.c (search_nonascii): use nlz on big endian environments.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 54862)
+++ win32/win32.c	(revision 54863)
@@ -580,18 +580,6 @@ init_env(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L580
 #undef set_env_val
 }
 
-
-typedef BOOL (WINAPI *cancel_io_t)(HANDLE);
-static cancel_io_t cancel_io = NULL;
-
-/* License: Ruby's */
-static void
-init_func(void)
-{
-    if (!cancel_io)
-	cancel_io = (cancel_io_t)get_proc_address("kernel32", "CancelIo", NULL);
-}
-
 static void init_stdhandle(void);
 
 #if RUBY_MSVCRT_VERSION >= 80
@@ -790,8 +778,6 @@ rb_w32_sysinit(int *argc, char ***argv) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L778
 
     init_env();
 
-    init_func();
-
     init_stdhandle();
 
     atexit(exit_handler);
@@ -2452,7 +2438,7 @@ static int is_console(SOCKET); https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2438
 int
 rb_w32_io_cancelable_p(int fd)
 {
-    return cancel_io != NULL && (is_socket(TO_SOCKET(fd)) || !is_console(TO_SOCKET(fd)));
+    return is_socket(TO_SOCKET(fd)) || !is_console(TO_SOCKET(fd));
 }
 
 /* License: Ruby's */
@@ -3340,7 +3326,7 @@ finish_overlapped_socket(BOOL input, SOC https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3326
 	  case WAIT_OBJECT_0 + 1:
 	    /* interrupted */
 	    *len = -1;
-	    cancel_io((HANDLE)s);
+	    CancelIo((HANDLE)s);
 	    break;
 	}
     }
@@ -3374,7 +3360,7 @@ overlapped_socket_io(BOOL input, int fd, https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3360
 
     s = TO_SOCKET(fd);
     socklist_lookup(s, &mode);
-    if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) {
+    if (GET_FLAGS(mode) & O_NONBLOCK) {
 	RUBY_CRITICAL({
 	    if (input) {
 		if (addr && addrlen)
@@ -3525,7 +3511,7 @@ recvmsg(int fd, struct msghdr *msg, int https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3511
     wsamsg.dwFlags |= flags;
 
     socklist_lookup(s, &mode);
-    if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) {
+    if (GET_FLAGS(mode) & O_NONBLOCK) {
 	RUBY_CRITICAL({
 	    if ((ret = pWSARecvMsg(s, &wsamsg, &len, NULL, NULL)) == SOCKET_ERROR) {
 		errno = map_errno(WSAGetLastError());
@@ -3582,7 +3568,7 @@ sendmsg(int fd, const struct msghdr *msg https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3568
     msghdr_to_wsamsg(msg, &wsamsg);
 
     socklist_lookup(s, &mode);
-    if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) {
+    if (GET_FLAGS(mode) & O_NONBLOCK) {
 	RUBY_CRITICAL({
 	    if ((ret = pWSASendMsg(s, &wsamsg, flags, &len, NULL, NULL)) == SOCKET_ERROR) {
 		errno = map_errno(WSAGetLastError());
@@ -4740,21 +4726,7 @@ kill(int pid, int sig) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4726
 static int
 wlink(const WCHAR *from, const WCHAR *to)
 {
-    typedef BOOL (WINAPI link_func)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
-    static link_func *pCreateHardLinkW = NULL;
-    static int myerrno = 0;
-
-    if (!pCreateHardLinkW && !myerrno) {
-	pCreateHardLinkW = (link_func *)get_proc_address("kernel32", "CreateHardLinkW", NULL);
-	if (!pCreateHardLinkW)
-	    myerrno = ENOSYS;
-    }
-    if (!pCreateHardLinkW) {
-	errno = myerrno;
-	return -1;
-    }
-
-    if (!pCreateHardLinkW(to, from, NULL)) {
+    if (!CreateHardLinkW(to, from, NULL)) {
 	errno = map_errno(GetLastError());
 	return -1;
     }
@@ -4821,25 +4793,12 @@ reparse_symlink(const WCHAR *path, rb_w3 https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4793
     DWORD ret;
     int e = 0;
 
-    typedef BOOL (WINAPI *device_io_control_func)(HANDLE, DWORD, LPVOID,
-						  DWORD, LPVOID, DWORD,
-						  LPDWORD, LPOVERLAPPED);
-    static device_io_control_func device_io_control = (device_io_control_func)-1;
-
-    if (device_io_control == (device_io_control_func)-1) {
-	device_io_control = (device_io_control_func)
-	    get_proc_address("kernel32", "DeviceIoControl", NULL);
-    }
-    if (!device_io_control) {
-	return ENOSYS;
-    }
-
     f = open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
     if (f == INVALID_HANDLE_VALUE) {
 	return GetLastError();
     }
 
-    if (!device_io_control(f, FSCTL_GET_REPARSE_POINT, NULL, 0,
+    if (!DeviceIoControl(f, FSCTL_GET_REPARSE_POINT, NULL, 0,
 			   rp, size, &ret, NULL)) {
 	e = GetLastError();
     }
@@ -5974,23 +5933,21 @@ rb_w32_getppid(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5933
     static query_func *pNtQueryInformationProcess = NULL;
     rb_pid_t ppid = 0;
 
-    if (rb_w32_osver() >= 5) {
-	if (!pNtQueryInformationProcess)
-	    pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
-	if (pNtQueryInformationProcess) {
-	    struct {
-		long ExitStatus;
-		void* PebBaseAddress;
-		uintptr_t AffinityMask;
-		uintptr_t BasePriority;
-		uintptr_t UniqueProcessId;
-		uintptr_t ParentProcessId;
-	    } pbi;
-	    ULONG len;
-	    long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi, sizeof(pbi), &len);
-	    if (!ret) {
-		ppid = pbi.ParentProcessId;
-	    }
+    if (!pNtQueryInformationProcess)
+	pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
+    if (pNtQueryInformationProcess) {
+	struct {
+	    long ExitStatus;
+	    void* PebBaseAddress;
+	    uintptr_t AffinityMask;
+	    uintptr_t BasePriority;
+	    uintptr_t UniqueProcessId;
+	    uintptr_t ParentProcessId;
+	} pbi;
+	ULONG len;
+	long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi, sizeof(pbi), &len);
+	if (!ret) {
+	    ppid = pbi.ParentProcessId;
 	}
     }
 
@@ -6303,10 +6260,6 @@ rb_w32_pipe(int fds[2]) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6260
     int fdRead, fdWrite;
     int ret;
 
-    /* if doesn't have CancelIo, use default pipe function */
-    if (!cancel_io)
-	return _pipe(fds, 65536L, _O_NOINHERIT);
-
     memcpy(name, prefix, width_of_prefix);
     snprintf(name + width_of_prefix, width_of_ids, "%.*"PRI_PIDT_PREFIX"x-%.*lx",
 	     width_of_pid, rb_w32_getpid(), width_of_serial, serial++);
@@ -6830,7 +6783,7 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6783
     DWORD err;
     size_t len;
     size_t ret;
-    OVERLAPPED ol, *pol = NULL;
+    OVERLAPPED ol;
     BOOL isconsole;
     BOOL islineinput = FALSE;
     int start = 0;
@@ -6877,17 +6830,12 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6830
 	len = size;
     size -= len;
 
-    /* if have cancel_io, use Overlapped I/O */
-    if (cancel_io) {
-	if (setup_overlapped(&ol, fd, FALSE)) {
-	    rb_acrt_lowio_unlock_fh(fd);
-	    return -1;
-	}
-
-	pol = &ol;
+    if (setup_overlapped(&ol, fd, FALSE)) {
+	rb_acrt_lowio_unlock_fh(fd);
+	return -1;
     }
 
-    if (!ReadFile((HANDLE)_osfhnd(fd), buf, len, &read, pol)) {
+    if (!ReadFile((HANDLE)_osfhnd(fd), buf, len, &read, &ol)) {
 	err = GetLastError();
 	if (err == ERROR_NO_DATA && (_osfile(fd) & FPIPE)) {
 	    DWORD state;
@@ -6901,7 +6849,7 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6849
 	    return -1;
 	}
 	else if (err != ERROR_IO_PENDING) {
-	    if (pol) CloseHandle(ol.hEvent);
+	    CloseHandle(ol.hEvent);
 	    if (err == ERROR_ACCESS_DENIED)
 		errno = EBADF;
 	    else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {
@@ -6915,31 +6863,29 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6863
 	    return -1;
 	}
 
-	if (pol) {
-	    wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
-	    if (wait != WAIT_OBJECT_0) {
-		if (wait == WAIT_OBJECT_0 + 1)
-		    errno = EINTR;
-		else
-		    errno = map_errno(GetLastError());
-		CloseHandle(ol.hEvent);
-		cancel_io((HANDLE)_osfhnd(fd));
-		rb_acrt_lowio_unlock_fh(fd);
-		return -1;
-	    }
+	wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
+	if (wait != WAIT_OBJECT_0) {
+	    if (wait == WAIT_OBJECT_0 + 1)
+		errno = EINTR;
+	    else
+		errno = map_errno(GetLastError());
+	    CloseHandle(ol.hEvent);
+	    CancelIo((HANDLE)_osfhnd(fd));
+	    rb_acrt_lowio_unlock_fh(fd);
+	    return -1;
+	}
 
-	    if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &read, TRUE) &&
-		(err = GetLastError()) != ERROR_HANDLE_EOF) {
-		int ret = 0;
-		if (err != ERROR_BROKEN_PIPE) {
-		    errno = map_errno(err);
-		    ret = -1;
-		}
-		CloseHandle(ol.hEvent);
-		cancel_io((HANDLE)_osfhnd(fd));
-		rb_acrt_lowio_unlock_fh(fd);
-		return ret;
+	if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &read, TRUE) &&
+	    (err = GetLastError()) != ERROR_HANDLE_EOF) {
+	    int ret = 0;
+	    if (err != ERROR_BROKEN_PIPE) {
+		errno = map_errno(err);
+		ret = -1;
 	    }
+	    CloseHandle(ol.hEvent);
+	    CancelIo((HANDLE)_osfhnd(fd));
+	    rb_acrt_lowio_unlock_fh(fd);
+	    return ret;
 	}
     }
     else {
@@ -6947,9 +6893,7 @@ rb_w32_read(int fd, void *buf, size_t si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6893
 	errno = map_errno(err);
     }
 
-    if (pol) {
-	finish_overlapped(&ol, fd, read);
-    }
+    finish_overlapped(&ol, fd, read);
 
     ret += read;
     if (read >= len) {
@@ -6978,7 +6922,7 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6922
     DWORD err;
     size_t len;
     size_t ret;
-    OVERLAPPED ol, *pol = NULL;
+    OVERLAPPED ol;
 
     if (is_socket(sock))
 	return rb_w32_send(fd, buf, size, 0);
@@ -7007,20 +6951,15 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6951
     size -= len;
   retry2:
 
-    /* if have cancel_io, use Overlapped I/O */
-    if (cancel_io) {
-	if (setup_overlapped(&ol, fd, TRUE)) {
-	    rb_acrt_lowio_unlock_fh(fd);
-	    return -1;
-	}
-
-	pol = &ol;
+    if (setup_overlapped(&ol, fd, TRUE)) {
+	rb_acrt_lowio_unlock_fh(fd);
+	return -1;
     }
 
-    if (!WriteFile((HANDLE)_osfhnd(fd), buf, len, &written, pol)) {
+    if (!WriteFile((HANDLE)_osfhnd(fd), buf, len, &written, &ol)) {
 	err = GetLastError();
 	if (err != ERROR_IO_PENDING) {
-	    if (pol) CloseHandle(ol.hEvent);
+	    CloseHandle(ol.hEvent);
 	    if (err == ERROR_ACCESS_DENIED)
 		errno = EBADF;
 	    else
@@ -7030,34 +6969,29 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6969
 	    return -1;
 	}
 
-	if (pol) {
-	    wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
-	    if (wait != WAIT_OBJECT_0) {
-		if (wait == WAIT_OBJECT_0 + 1)
-		    errno = EINTR;
-		else
-		    errno = map_errno(GetLastError());
-		CloseHandle(ol.hEvent);
-		cancel_io((HANDLE)_osfhnd(fd));
-		rb_acrt_lowio_unlock_fh(fd);
-		return -1;
-	    }
-
-	    if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &written,
-				     TRUE)) {
+	wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
+	if (wait != WAIT_OBJECT_0) {
+	    if (wait == WAIT_OBJECT_0 + 1)
+		errno = EINTR;
+	    else
 		errno = map_errno(GetLastError());
-		CloseHandle(ol.hEvent);
-		cancel_io((HANDLE)_osfhnd(fd));
-		rb_acrt_lowio_unlock_fh(fd);
-		return -1;
-	    }
+	    CloseHandle(ol.hEvent);
+	    CancelIo((HANDLE)_osfhnd(fd));
+	    rb_acrt_lowio_unlock_fh(fd);
+	    return -1;
 	}
-    }
 
-    if (pol) {
-	finish_overlapped(&ol, fd, written);
+	if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &written, TRUE)) {
+	    errno = map_errno(GetLastError());
+	    CloseHandle(ol.hEvent);
+	    CancelIo((HANDLE)_osfhnd(fd));
+	    rb_acrt_lowio_unlock_fh(fd);
+	    return -1;
+	}
     }
 
+    finish_overlapped(&ol, fd, written);
+
     ret += written;
     if (written == len) {
 	buf = (const char *)buf + len;
Index: hash.c
===================================================================
--- hash.c	(revision 54862)
+++ hash.c	(revision 54863)
@@ -3161,7 +3161,7 @@ getenvsize(const WCHAR* p) https://github.com/ruby/ruby/blob/trunk/hash.c#L3161
 static size_t
 getenvblocksize(void)
 {
-    return (rb_w32_osver() >= 5) ? 32767 : 5120;
+    return 32767;
 }
 #endif
 
Index: cont.c
===================================================================
--- cont.c	(revision 54862)
+++ cont.c	(revision 54863)
@@ -54,13 +54,7 @@ https://github.com/ruby/ruby/blob/trunk/cont.c#L54
 #     define FIBER_USE_NATIVE 1
 #   endif
 # elif defined(_WIN32)
-#   if _WIN32_WINNT >= 0x0400
-/* only when _WIN32_WINNT >= 0x0400 on Windows because Fiber APIs are
- * supported only such building (and running) environments.
- * [ruby-dev:41192]
- */
-#     define FIBER_USE_NATIVE 1
-#   endif
+#  define FIBER_USE_NATIVE 1
 # endif
 #endif
 #if !defined(FIBER_USE_NATIVE)
Index: random.c
===================================================================
--- random.c	(revision 54862)
+++ random.c	(revision 54863)
@@ -84,11 +84,6 @@ The original copyright notice follows. https://github.com/ruby/ruby/blob/trunk/random.c#L84
 #endif
 
 #ifdef _WIN32
-# if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400
-#  undef _WIN32_WINNT
-#  define _WIN32_WINNT 0x400
-#  undef __WINCRYPT_H__
-# endif
 #include <windows.h>
 #include <wincrypt.h>
 #endif

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

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