* cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4

support leftovers.
  [fix GH-1328] patched by @cremno


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2016-05-01 11:42:41 +00:00
parent db2c32778d
commit 62b6e90d58
5 changed files with 82 additions and 153 deletions

View File

@ -1,3 +1,9 @@
Sun May 1 20:39:47 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* 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@ruby-lang.org> Sun May 1 07:30:44 2016 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (search_nonascii): use nlz on big endian environments. * string.c (search_nonascii): use nlz on big endian environments.

6
cont.c
View File

@ -54,14 +54,8 @@
# define FIBER_USE_NATIVE 1 # define FIBER_USE_NATIVE 1
# endif # endif
# elif defined(_WIN32) # 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 # define FIBER_USE_NATIVE 1
# endif # endif
# endif
#endif #endif
#if !defined(FIBER_USE_NATIVE) #if !defined(FIBER_USE_NATIVE)
#define FIBER_USE_NATIVE 0 #define FIBER_USE_NATIVE 0

2
hash.c
View File

@ -3161,7 +3161,7 @@ getenvsize(const WCHAR* p)
static size_t static size_t
getenvblocksize(void) getenvblocksize(void)
{ {
return (rb_w32_osver() >= 5) ? 32767 : 5120; return 32767;
} }
#endif #endif

View File

@ -84,11 +84,6 @@ The original copyright notice follows.
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
# if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x400
# undef __WINCRYPT_H__
# endif
#include <windows.h> #include <windows.h>
#include <wincrypt.h> #include <wincrypt.h>
#endif #endif

View File

@ -580,18 +580,6 @@ init_env(void)
#undef set_env_val #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); static void init_stdhandle(void);
#if RUBY_MSVCRT_VERSION >= 80 #if RUBY_MSVCRT_VERSION >= 80
@ -790,8 +778,6 @@ rb_w32_sysinit(int *argc, char ***argv)
init_env(); init_env();
init_func();
init_stdhandle(); init_stdhandle();
atexit(exit_handler); atexit(exit_handler);
@ -2452,7 +2438,7 @@ static int is_console(SOCKET);
int int
rb_w32_io_cancelable_p(int fd) 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 */ /* License: Ruby's */
@ -3340,7 +3326,7 @@ finish_overlapped_socket(BOOL input, SOCKET s, WSAOVERLAPPED *wol, int result, D
case WAIT_OBJECT_0 + 1: case WAIT_OBJECT_0 + 1:
/* interrupted */ /* interrupted */
*len = -1; *len = -1;
cancel_io((HANDLE)s); CancelIo((HANDLE)s);
break; break;
} }
} }
@ -3374,7 +3360,7 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
s = TO_SOCKET(fd); s = TO_SOCKET(fd);
socklist_lookup(s, &mode); socklist_lookup(s, &mode);
if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) { if (GET_FLAGS(mode) & O_NONBLOCK) {
RUBY_CRITICAL({ RUBY_CRITICAL({
if (input) { if (input) {
if (addr && addrlen) if (addr && addrlen)
@ -3525,7 +3511,7 @@ recvmsg(int fd, struct msghdr *msg, int flags)
wsamsg.dwFlags |= flags; wsamsg.dwFlags |= flags;
socklist_lookup(s, &mode); socklist_lookup(s, &mode);
if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) { if (GET_FLAGS(mode) & O_NONBLOCK) {
RUBY_CRITICAL({ RUBY_CRITICAL({
if ((ret = pWSARecvMsg(s, &wsamsg, &len, NULL, NULL)) == SOCKET_ERROR) { if ((ret = pWSARecvMsg(s, &wsamsg, &len, NULL, NULL)) == SOCKET_ERROR) {
errno = map_errno(WSAGetLastError()); errno = map_errno(WSAGetLastError());
@ -3582,7 +3568,7 @@ sendmsg(int fd, const struct msghdr *msg, int flags)
msghdr_to_wsamsg(msg, &wsamsg); msghdr_to_wsamsg(msg, &wsamsg);
socklist_lookup(s, &mode); socklist_lookup(s, &mode);
if (!cancel_io || (GET_FLAGS(mode) & O_NONBLOCK)) { if (GET_FLAGS(mode) & O_NONBLOCK) {
RUBY_CRITICAL({ RUBY_CRITICAL({
if ((ret = pWSASendMsg(s, &wsamsg, flags, &len, NULL, NULL)) == SOCKET_ERROR) { if ((ret = pWSASendMsg(s, &wsamsg, flags, &len, NULL, NULL)) == SOCKET_ERROR) {
errno = map_errno(WSAGetLastError()); errno = map_errno(WSAGetLastError());
@ -4740,21 +4726,7 @@ kill(int pid, int sig)
static int static int
wlink(const WCHAR *from, const WCHAR *to) wlink(const WCHAR *from, const WCHAR *to)
{ {
typedef BOOL (WINAPI link_func)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); if (!CreateHardLinkW(to, from, NULL)) {
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)) {
errno = map_errno(GetLastError()); errno = map_errno(GetLastError());
return -1; return -1;
} }
@ -4821,25 +4793,12 @@ reparse_symlink(const WCHAR *path, rb_w32_reparse_buffer_t *rp, size_t size)
DWORD ret; DWORD ret;
int e = 0; 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); f = open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
if (f == INVALID_HANDLE_VALUE) { if (f == INVALID_HANDLE_VALUE) {
return GetLastError(); 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)) { rp, size, &ret, NULL)) {
e = GetLastError(); e = GetLastError();
} }
@ -5974,7 +5933,6 @@ rb_w32_getppid(void)
static query_func *pNtQueryInformationProcess = NULL; static query_func *pNtQueryInformationProcess = NULL;
rb_pid_t ppid = 0; rb_pid_t ppid = 0;
if (rb_w32_osver() >= 5) {
if (!pNtQueryInformationProcess) if (!pNtQueryInformationProcess)
pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL); pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
if (pNtQueryInformationProcess) { if (pNtQueryInformationProcess) {
@ -5992,7 +5950,6 @@ rb_w32_getppid(void)
ppid = pbi.ParentProcessId; ppid = pbi.ParentProcessId;
} }
} }
}
return ppid; return ppid;
} }
@ -6303,10 +6260,6 @@ rb_w32_pipe(int fds[2])
int fdRead, fdWrite; int fdRead, fdWrite;
int ret; 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); memcpy(name, prefix, width_of_prefix);
snprintf(name + width_of_prefix, width_of_ids, "%.*"PRI_PIDT_PREFIX"x-%.*lx", snprintf(name + width_of_prefix, width_of_ids, "%.*"PRI_PIDT_PREFIX"x-%.*lx",
width_of_pid, rb_w32_getpid(), width_of_serial, serial++); width_of_pid, rb_w32_getpid(), width_of_serial, serial++);
@ -6830,7 +6783,7 @@ rb_w32_read(int fd, void *buf, size_t size)
DWORD err; DWORD err;
size_t len; size_t len;
size_t ret; size_t ret;
OVERLAPPED ol, *pol = NULL; OVERLAPPED ol;
BOOL isconsole; BOOL isconsole;
BOOL islineinput = FALSE; BOOL islineinput = FALSE;
int start = 0; int start = 0;
@ -6877,17 +6830,12 @@ rb_w32_read(int fd, void *buf, size_t size)
len = size; len = size;
size -= len; size -= len;
/* if have cancel_io, use Overlapped I/O */
if (cancel_io) {
if (setup_overlapped(&ol, fd, FALSE)) { if (setup_overlapped(&ol, fd, FALSE)) {
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return -1; return -1;
} }
pol = &ol; if (!ReadFile((HANDLE)_osfhnd(fd), buf, len, &read, &ol)) {
}
if (!ReadFile((HANDLE)_osfhnd(fd), buf, len, &read, pol)) {
err = GetLastError(); err = GetLastError();
if (err == ERROR_NO_DATA && (_osfile(fd) & FPIPE)) { if (err == ERROR_NO_DATA && (_osfile(fd) & FPIPE)) {
DWORD state; DWORD state;
@ -6901,7 +6849,7 @@ rb_w32_read(int fd, void *buf, size_t size)
return -1; return -1;
} }
else if (err != ERROR_IO_PENDING) { else if (err != ERROR_IO_PENDING) {
if (pol) CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
if (err == ERROR_ACCESS_DENIED) if (err == ERROR_ACCESS_DENIED)
errno = EBADF; errno = EBADF;
else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) { else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {
@ -6915,7 +6863,6 @@ rb_w32_read(int fd, void *buf, size_t size)
return -1; return -1;
} }
if (pol) {
wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE); wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
if (wait != WAIT_OBJECT_0) { if (wait != WAIT_OBJECT_0) {
if (wait == WAIT_OBJECT_0 + 1) if (wait == WAIT_OBJECT_0 + 1)
@ -6923,7 +6870,7 @@ rb_w32_read(int fd, void *buf, size_t size)
else else
errno = map_errno(GetLastError()); errno = map_errno(GetLastError());
CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
cancel_io((HANDLE)_osfhnd(fd)); CancelIo((HANDLE)_osfhnd(fd));
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return -1; return -1;
} }
@ -6936,20 +6883,17 @@ rb_w32_read(int fd, void *buf, size_t size)
ret = -1; ret = -1;
} }
CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
cancel_io((HANDLE)_osfhnd(fd)); CancelIo((HANDLE)_osfhnd(fd));
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return ret; return ret;
} }
} }
}
else { else {
err = GetLastError(); err = GetLastError();
errno = map_errno(err); errno = map_errno(err);
} }
if (pol) {
finish_overlapped(&ol, fd, read); finish_overlapped(&ol, fd, read);
}
ret += read; ret += read;
if (read >= len) { if (read >= len) {
@ -6978,7 +6922,7 @@ rb_w32_write(int fd, const void *buf, size_t size)
DWORD err; DWORD err;
size_t len; size_t len;
size_t ret; size_t ret;
OVERLAPPED ol, *pol = NULL; OVERLAPPED ol;
if (is_socket(sock)) if (is_socket(sock))
return rb_w32_send(fd, buf, size, 0); return rb_w32_send(fd, buf, size, 0);
@ -7007,20 +6951,15 @@ rb_w32_write(int fd, const void *buf, size_t size)
size -= len; size -= len;
retry2: retry2:
/* if have cancel_io, use Overlapped I/O */
if (cancel_io) {
if (setup_overlapped(&ol, fd, TRUE)) { if (setup_overlapped(&ol, fd, TRUE)) {
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return -1; return -1;
} }
pol = &ol; if (!WriteFile((HANDLE)_osfhnd(fd), buf, len, &written, &ol)) {
}
if (!WriteFile((HANDLE)_osfhnd(fd), buf, len, &written, pol)) {
err = GetLastError(); err = GetLastError();
if (err != ERROR_IO_PENDING) { if (err != ERROR_IO_PENDING) {
if (pol) CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
if (err == ERROR_ACCESS_DENIED) if (err == ERROR_ACCESS_DENIED)
errno = EBADF; errno = EBADF;
else else
@ -7030,7 +6969,6 @@ rb_w32_write(int fd, const void *buf, size_t size)
return -1; return -1;
} }
if (pol) {
wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE); wait = rb_w32_wait_events_blocking(&ol.hEvent, 1, INFINITE);
if (wait != WAIT_OBJECT_0) { if (wait != WAIT_OBJECT_0) {
if (wait == WAIT_OBJECT_0 + 1) if (wait == WAIT_OBJECT_0 + 1)
@ -7038,25 +6976,21 @@ rb_w32_write(int fd, const void *buf, size_t size)
else else
errno = map_errno(GetLastError()); errno = map_errno(GetLastError());
CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
cancel_io((HANDLE)_osfhnd(fd)); CancelIo((HANDLE)_osfhnd(fd));
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return -1; return -1;
} }
if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &written, if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &written, TRUE)) {
TRUE)) {
errno = map_errno(GetLastError()); errno = map_errno(GetLastError());
CloseHandle(ol.hEvent); CloseHandle(ol.hEvent);
cancel_io((HANDLE)_osfhnd(fd)); CancelIo((HANDLE)_osfhnd(fd));
rb_acrt_lowio_unlock_fh(fd); rb_acrt_lowio_unlock_fh(fd);
return -1; return -1;
} }
} }
}
if (pol) {
finish_overlapped(&ol, fd, written); finish_overlapped(&ol, fd, written);
}
ret += written; ret += written;
if (written == len) { if (written == len) {