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

ruby-changes:31811

From: nobu <ko1@a...>
Date: Thu, 28 Nov 2013 16:16:05 +0900 (JST)
Subject: [ruby-changes:31811] nobu:r43890 (trunk): win32.c: rb_w32_dup2

nobu	2013-11-28 16:15:56 +0900 (Thu, 28 Nov 2013)

  New Revision: 43890

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

  Log:
    win32.c: rb_w32_dup2
    
    * win32/win32.c (rb_w32_dup2): extract from rb_cloexec_dup2() and
      redirect_dup2().

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/win32.h
    trunk/io.c
    trunk/process.c
    trunk/win32/win32.c
Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 43889)
+++ include/ruby/win32.h	(revision 43890)
@@ -346,6 +346,7 @@ extern int rb_w32_access(const char *, i https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L346
 extern int rb_w32_uaccess(const char *, int);
 extern char rb_w32_fd_is_text(int);
 extern int rb_w32_fstati64(int, struct stati64 *);
+extern int rb_w32_dup2(int, int);
 
 #ifdef __BORLANDC__
 extern off_t _lseeki64(int, off_t, int);
@@ -734,6 +735,9 @@ extern char *rb_w32_strerror(int); https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L735
 
 #undef times
 #define times(t)		rb_w32_times(t)
+
+#undef dup2
+#define dup2(o, n)		rb_w32_dup2(o, n)
 #endif
 
 struct tms {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43889)
+++ ChangeLog	(revision 43890)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov 28 16:15:47 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (rb_w32_dup2): extract from rb_cloexec_dup2() and
+	  redirect_dup2().
+
 Tue Nov 28 14:40:00 2013  Akira Matsuda  <ronnie@d...>
 
 	* lib/drb/ssl.rb:  [Doc] Fix typo
Index: io.c
===================================================================
--- io.c	(revision 43889)
+++ io.c	(revision 43890)
@@ -275,10 +275,6 @@ rb_cloexec_dup2(int oldfd, int newfd) https://github.com/ruby/ruby/blob/trunk/io.c#L275
         }
 #else
         ret = dup2(oldfd, newfd);
-# ifdef _WIN32
-	if (newfd >= 0 && newfd <= 2)
-	    SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)rb_w32_get_osfhandle(newfd));
-# endif
 #endif
         if (ret == -1) return -1;
     }
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 43889)
+++ win32/win32.c	(revision 43890)
@@ -79,6 +79,7 @@ static char *w32_getenv(const char *name https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L79
 #undef fclose
 #undef close
 #undef setsockopt
+#undef dup2
 
 #if defined __BORLANDC__
 #  define _filbuf _fgetc
@@ -5465,6 +5466,28 @@ rb_w32_getppid(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5466
     return ppid;
 }
 
+STATIC_ASSERT(std_handle, (STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)==(STD_ERROR_HANDLE-STD_OUTPUT_HANDLE));
+
+/* License: Ruby's */
+#define set_new_std_handle(newfd, handle) do { \
+	if ((unsigned)(newfd) > 2) break; \
+	SetStdHandle(STD_INPUT_HANDLE+(STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)*(newfd), \
+		     (handle)); \
+    } while (0)
+#define set_new_std_fd(newfd) set_new_std_handle(newfd, (HANDLE)rb_w32_get_osfhandle(newfd))
+
+/* License: Ruby's */
+int
+rb_w32_dup2(int oldfd, int newfd)
+{
+    int ret;
+
+    if (oldfd == newfd) return newfd;
+    ret = dup2(oldfd, newfd);
+    set_new_std_fd(newfd);
+    return ret;
+}
+
 /* License: Ruby's */
 int
 rb_w32_uopen(const char *file, int oflag, ...)
Index: process.c
===================================================================
--- process.c	(revision 43889)
+++ process.c	(revision 43890)
@@ -2500,28 +2500,16 @@ redirect_dup(int oldfd) https://github.com/ruby/ruby/blob/trunk/process.c#L2500
     ttyprintf("dup(%d) => %d\n", oldfd, ret);
     return ret;
 }
-#else
-#define redirect_dup(oldfd) dup(oldfd)
-#endif
 
-#if defined(DEBUG_REDIRECT) || defined(_WIN32)
 static int
 redirect_dup2(int oldfd, int newfd)
 {
     int ret;
     ret = dup2(oldfd, newfd);
-    if (newfd >= 0 && newfd <= 2)
-	SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)rb_w32_get_osfhandle(newfd));
-#if defined(DEBUG_REDIRECT)
     ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
-#endif
     return ret;
 }
-#else
-#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
-#endif
 
-#if defined(DEBUG_REDIRECT)
 static int
 redirect_close(int fd)
 {
@@ -2541,6 +2529,8 @@ redirect_open(const char *pathname, int https://github.com/ruby/ruby/blob/trunk/process.c#L2529
 }
 
 #else
+#define redirect_dup(oldfd) dup(oldfd)
+#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
 #define redirect_close(fd) close(fd)
 #define redirect_open(pathname, flags, perm) open((pathname), (flags), (perm))
 #endif

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

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