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

ruby-changes:10010

From: yugui <ko1@a...>
Date: Fri, 16 Jan 2009 00:38:15 +0900 (JST)
Subject: [ruby-changes:10010] Ruby:r21549 (ruby_1_9_1): merges r21487 from trunk into ruby_1_9_1.

yugui	2009-01-16 00:37:20 +0900 (Fri, 16 Jan 2009)

  New Revision: 21549

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21549

  Log:
    merges r21487 from trunk into ruby_1_9_1.
    * include/ruby/intern.h, thread.c, win32/Makefile.sub (rb_fdset_t,
      rb_fd_init, rb_fd_term, rb_fd_zero, rb_fd_set, rb_fd_clr, rb_fd_isset,
      rb_fd_select, rb_fd_ptr, rb_fd_max, HAVE_RB_FD_INIT): new type,
      functions, and macros for Windows.
    * win32/win32.c (extract_fd, rb_w32_select): use rb_fdset_t to expand
      fd_array if needed.  [ruby-core:19946]
    
    * win32/win32.c (copy_fd): new funcion for rb_w32_select().

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/include/ruby/intern.h
    branches/ruby_1_9_1/thread.c
    branches/ruby_1_9_1/win32/Makefile.sub
    branches/ruby_1_9_1/win32/win32.c

Index: ruby_1_9_1/include/ruby/intern.h
===================================================================
--- ruby_1_9_1/include/ruby/intern.h	(revision 21548)
+++ ruby_1_9_1/include/ruby/intern.h	(revision 21549)
@@ -218,6 +218,24 @@
 #define rb_fd_ptr(f)	((f)->fdset)
 #define rb_fd_max(f)	((f)->maxfd)
 
+#elif defined(_WIN32)
+
+typedef struct {
+    int capa;
+    fd_set *fdset;
+} rb_fdset_t;
+
+void rb_fd_init(volatile rb_fdset_t *);
+void rb_fd_term(rb_fdset_t *);
+#define rb_fd_zero(f)		((f)->fdset->fd_count = 0)
+void rb_fd_set(int, rb_fdset_t *);
+#define rb_fd_clr(n, f)		rb_w32_fdclr(n, (f)->fdset)
+#define rb_fd_isset(n, f)	rb_w32_fdisset(n, (f)->fdset)
+#define rb_fd_select(n, rfds, wfds, efds, timeout)	rb_w32_select(n, (rfds) ? ((rb_fdset_t*)rfds)->fdset : NULL, (wfds) ? ((rb_fdset_t*)wfds)->fdset : NULL, (efds) ? ((rb_fdset_t*)efds)->fdset: NULL, timeout)
+
+#define rb_fd_ptr(f)	((f)->fdset)
+#define rb_fd_max(f)	((f)->fdset->fd_count)
+
 #else
 
 typedef fd_set rb_fdset_t;
Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 21548)
+++ ruby_1_9_1/ChangeLog	(revision 21549)
@@ -1,3 +1,15 @@
+Tue Jan 13 16:39:11 2009  NAKAMURA Usaku  <usa@r...>
+
+	* include/ruby/intern.h, thread.c, win32/Makefile.sub (rb_fdset_t,
+	  rb_fd_init, rb_fd_term, rb_fd_zero, rb_fd_set, rb_fd_clr, rb_fd_isset,
+	  rb_fd_select, rb_fd_ptr, rb_fd_max, HAVE_RB_FD_INIT): new type,
+	  functions, and macros for Windows.
+
+	* win32/win32.c (extract_fd, rb_w32_select): use rb_fdset_t to expand
+	  fd_array if needed.  [ruby-core:19946]
+
+	* win32/win32.c (copy_fd): new funcion for rb_w32_select().
+
 Tue Jan 13 12:31:54 2009  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* tool/file2lastrev.rb (get_revisions): fixes problem with
Index: ruby_1_9_1/thread.c
===================================================================
--- ruby_1_9_1/thread.c	(revision 21548)
+++ ruby_1_9_1/thread.c	(revision 21549)
@@ -2244,6 +2244,52 @@
 #define FD_CLR(i, f)	rb_fd_clr(i, f)
 #define FD_ISSET(i, f)	rb_fd_isset(i, f)
 
+#elif defined(_WIN32)
+
+void
+rb_fd_init(volatile rb_fdset_t *set)
+{
+    set->capa = FD_SETSIZE;
+    set->fdset = ALLOC(fd_set);
+    FD_ZERO(set->fdset);
+}
+
+void
+rb_fd_term(rb_fdset_t *set)
+{
+    xfree(set->fdset);
+    set->fdset = NULL;
+    set->capa = 0;
+}
+
+void
+rb_fd_set(int fd, rb_fdset_t *set)
+{
+    unsigned int i;
+    SOCKET s = rb_w32_get_osfhandle(fd);
+
+    for (i = 0; i < set->fdset->fd_count; i++) {
+        if (set->fdset->fd_array[i] == s) {
+            return;
+        }
+    }
+    if (set->fdset->fd_count >= set->capa) {
+	set->capa = (set->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
+	set->fdset = xrealloc(set->fdset, sizeof(unsigned int) + sizeof(SOCKET) * set->capa);
+    }
+    set->fdset->fd_array[set->fdset->fd_count++] = s;
+}
+
+#undef FD_ZERO
+#undef FD_SET
+#undef FD_CLR
+#undef FD_ISSET
+
+#define FD_ZERO(f)	rb_fd_zero(f)
+#define FD_SET(i, f)	rb_fd_set(i, f)
+#define FD_CLR(i, f)	rb_fd_clr(i, f)
+#define FD_ISSET(i, f)	rb_fd_isset(i, f)
+
 #endif
 
 #if defined(__CYGWIN__) || defined(_WIN32)
Index: ruby_1_9_1/win32/win32.c
===================================================================
--- ruby_1_9_1/win32/win32.c	(revision 21548)
+++ ruby_1_9_1/win32/win32.c	(revision 21549)
@@ -1990,11 +1990,8 @@
 
     for (i = 0; i < set->fd_count; i++) {
         if (set->fd_array[i] == s) {
-            while (i < set->fd_count - 1) {
-                set->fd_array[i] = set->fd_array[i + 1];
-                i++;
-            }
-            set->fd_count--;
+	    memmove(&set->fd_array[i], &set->fd_array[i+1],
+		    sizeof(set->fd_array[0]) * (--set->fd_count - i));
             break;
         }
     }
@@ -2022,7 +2019,7 @@
 #undef select
 
 static int
-extract_fd(fd_set *dst, fd_set *src, int (*func)(SOCKET))
+extract_fd(rb_fdset_t *dst, fd_set *src, int (*func)(SOCKET))
 {
     int s = 0;
     if (!src || !dst) return 0;
@@ -2033,11 +2030,16 @@
 	if (!func || (*func)(fd)) { /* move it to dst */
 	    int d;
 
-	    for (d = 0; d < dst->fd_count; d++) {
-		if (dst->fd_array[d] == fd) break;
+	    for (d = 0; d < dst->fdset->fd_count; d++) {
+		if (dst->fdset->fd_array[d] == fd)
+		    break;
 	    }
-	    if (d == dst->fd_count && dst->fd_count < FD_SETSIZE) {
-		dst->fd_array[dst->fd_count++] = fd;
+	    if (d == dst->fdset->fd_count) {
+		if (dst->fdset->fd_count >= dst->capa) {
+		    dst->capa = (dst->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
+		    dst->fdset = xrealloc(dst->fdset, sizeof(unsigned int) + sizeof(SOCKET) * dst->capa);
+		}
+		dst->fdset->fd_array[dst->fdset->fd_count++] = fd;
 	    }
 	    memmove(
 		&src->fd_array[s],
@@ -2047,6 +2049,27 @@
 	else s++;
     }
 
+    return dst->fdset->fd_count;
+}
+
+static int
+copy_fd(fd_set *dst, fd_set *src)
+{
+    int s;
+    if (!src || !dst) return 0;
+
+    for (s = 0; s < src->fd_count; ++s) {
+	SOCKET fd = src->fd_array[s];
+	int d;
+	for (d = 0; d < dst->fd_count; ++d) {
+	    if (dst->fd_array[d] == fd)
+		break;
+	}
+	if (d == dst->fd_count && d < FD_SETSIZE) {
+	    dst->fd_array[dst->fd_count++] = fd;
+	}
+    }
+
     return dst->fd_count;
 }
 
@@ -2187,11 +2210,11 @@
 	      struct timeval *timeout)
 {
     int r;
-    fd_set pipe_rd;
-    fd_set cons_rd;
-    fd_set else_rd;
-    fd_set else_wr;
-    fd_set except;
+    rb_fdset_t pipe_rd;
+    rb_fdset_t cons_rd;
+    rb_fdset_t else_rd;
+    rb_fdset_t else_wr;
+    rb_fdset_t except;
     int nonsock = 0;
     struct timeval limit;
 
@@ -2226,19 +2249,19 @@
     // until some data is read from pipe. but ruby is single threaded system,
     // so whole system will be blocked forever.
 
-    else_rd.fd_count = 0;
+    rb_fd_init(&else_rd);
     nonsock += extract_fd(&else_rd, rd, is_not_socket);
 
-    pipe_rd.fd_count = 0;
-    extract_fd(&pipe_rd, &else_rd, is_pipe); // should not call is_pipe for socket
+    rb_fd_init(&pipe_rd);
+    extract_fd(&pipe_rd, else_rd.fdset, is_pipe); // should not call is_pipe for socket
 
-    cons_rd.fd_count = 0;
-    extract_fd(&cons_rd, &else_rd, is_console); // ditto
+    rb_fd_init(&cons_rd);
+    extract_fd(&cons_rd, else_rd.fdset, is_console); // ditto
 
-    else_wr.fd_count = 0;
+    rb_fd_init(&else_wr);
     nonsock += extract_fd(&else_wr, wr, is_not_socket);
 
-    except.fd_count = 0;
+    rb_fd_init(&except);
     extract_fd(&except, ex, is_not_socket); // drop only
 
     r = 0;
@@ -2257,15 +2280,17 @@
 	    if (nonsock) {
 		// modifying {else,pipe,cons}_rd is safe because
 		// if they are modified, function returns immediately.
-		extract_fd(&else_rd, &pipe_rd, is_readable_pipe);
-		extract_fd(&else_rd, &cons_rd, is_readable_console);
+		extract_fd(&else_rd, pipe_rd.fdset, is_readable_pipe);
+		extract_fd(&else_rd, cons_rd.fdset, is_readable_console);
 	    }
 
-	    if (else_rd.fd_count || else_wr.fd_count) {
+	    if (else_rd.fdset->fd_count || else_wr.fdset->fd_count) {
 		r = do_select(nfds, rd, wr, ex, &zero); // polling
 		if (r < 0) break; // XXX: should I ignore error and return signaled handles?
-		r += extract_fd(rd, &else_rd, NULL); // move all
-		r += extract_fd(wr, &else_wr, NULL); // move all
+		r = copy_fd(rd, else_rd.fdset);
+		r += copy_fd(wr, else_wr.fdset);
+		if (ex)
+		    r += ex->fd_count;
 		break;
 	    }
 	    else {
@@ -2295,6 +2320,12 @@
 	}
     }
 
+    rb_fd_term(&except);
+    rb_fd_term(&else_wr);
+    rb_fd_term(&cons_rd);
+    rb_fd_term(&pipe_rd);
+    rb_fd_term(&else_rd);
+
     return r;
 }
 
@@ -4345,10 +4376,6 @@
     if (_get_osfhandle(fd) == -1) {
 	return -1;
     }
-    if (!(_osfile(fd) & FOPEN)) {
-	errno = EBADF;
-	return -1;
-    }
 
     if (_osfile(fd) & FTEXT) {
 	return _read(fd, buf, size);
@@ -4467,10 +4494,6 @@
     if (_get_osfhandle(fd) == -1) {
 	return -1;
     }
-    if (!(_osfile(fd) & FOPEN)) {
-	errno = EBADF;
-	return -1;
-    }
 
     if (_osfile(fd) & FTEXT) {
 	return _write(fd, buf, size);
@@ -4703,10 +4726,6 @@
     if (_get_osfhandle(fd) == -1) {
 	return 0;
     }
-    if (!(_osfile(fd) & FOPEN)) {
-	errno = EBADF;
-	return 0;
-    }
     if (!(_osfile(fd) & FDEV)) {
 	errno = ENOTTY;
 	return 0;
Index: ruby_1_9_1/win32/Makefile.sub
===================================================================
--- ruby_1_9_1/win32/Makefile.sub	(revision 21548)
+++ ruby_1_9_1/win32/Makefile.sub	(revision 21549)
@@ -223,7 +223,11 @@
 !endif
 
 !if !defined(STACK)
+!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
+STACK = 0x400000
+!else
 STACK = 0x200000
+!endif
 !if defined(STACK_COMMIT)
 STACK = $(STACK),$(STACK_COMMIT)
 !endif
@@ -454,6 +458,7 @@
 #define RSHIFT(x,y) ((x)>>(int)y)
 #define FILE_COUNT _cnt
 #define FILE_READPTR _ptr
+#define HAVE_RB_FD_INIT 1
 #define RUBY_SETJMP(env) _setjmp(env)
 #define RUBY_LONGJMP(env,val) longjmp(env,val)
 #define RUBY_JMP_BUF jmp_buf

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

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