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

ruby-changes:26662

From: yugui <ko1@a...>
Date: Sun, 6 Jan 2013 18:48:11 +0900 (JST)
Subject: [ruby-changes:26662] yugui:r38713 (trunk): * bootstraptest/test_io.c: add a test for .

yugui	2013-01-06 18:48:00 +0900 (Sun, 06 Jan 2013)

  New Revision: 38713

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

  Log:
    * bootstraptest/test_io.c: add a test for [ruby-dev:46834].
    
    * io.c (rb_cloexec_fcntl_dupfd) Use an emulation with dup(2) when
      fcntl(2) and/or F_DUPFD is unavailable.
      Suggested by akr.
    
    * configure.in (HAVE_FCNTL): NativeClient does not provide fcntl(2).

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_io.rb
    trunk/configure.in
    trunk/io.c

Index: configure.in
===================================================================
--- configure.in	(revision 38712)
+++ configure.in	(revision 38713)
@@ -1302,6 +1302,7 @@ $POSTLINK" https://github.com/ruby/ruby/blob/trunk/configure.in#L1302
     RUBY_APPEND_OPTION(XCFLAGS, -fPIC)
   fi
   ac_cv_func_shutdown=no
+  ac_cv_func_fcntl=no
   ],
 [	LIBS="-lm $LIBS"])
 AC_CHECK_LIB(crypt, crypt)
@@ -1576,7 +1577,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid https://github.com/ruby/ruby/blob/trunk/configure.in#L1577
 	      setuid setgid daemon select_large_fdset setenv unsetenv\
               mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
               pread sendfile shutdown sigaltstack dl_iterate_phdr\
-              dup3 pipe2 posix_memalign memalign ioctl)
+              dup dup3 pipe2 posix_memalign memalign ioctl)
 
 AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
   [AC_TRY_COMPILE([
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38712)
+++ ChangeLog	(revision 38713)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan  6 18:43:48 2013  Yuki Yugui Sonoda  <yugui@y...>
+
+	* bootstraptest/test_io.c: add a test for [ruby-dev:46834].
+
+	* io.c (rb_cloexec_fcntl_dupfd) Use an emulation with dup(2) when
+	  fcntl(2) and/or F_DUPFD is unavailable.
+	  Suggested by akr.
+
+	* configure.in (HAVE_FCNTL): NativeClient does not provide fcntl(2).
+
 Sun Jan  6 11:11:26 2013  Eric Hodel  <drbrain@s...>
 
 	* doc/syntax/modules_and_classes.rdoc:  Fixed typo.
Index: bootstraptest/test_io.rb
===================================================================
--- bootstraptest/test_io.rb	(revision 38712)
+++ bootstraptest/test_io.rb	(revision 38713)
@@ -74,6 +74,12 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_io.rb#L74
   :ok
 }
 
+assert_equal 'ok', %q{
+  dup = STDIN.dup
+  dupfd = dup.fileno
+  dupfd == STDIN.dup.fileno ? :ng : :ok
+}, '[ruby-dev:46834]'
+
 assert_normal_exit %q{
   ARGF.set_encoding "foo"
 }
Index: io.c
===================================================================
--- io.c	(revision 38712)
+++ io.c	(revision 38713)
@@ -168,7 +168,7 @@ void https://github.com/ruby/ruby/blob/trunk/io.c#L168
 rb_maygvl_fd_fix_cloexec(int fd)
 {
   /* MinGW don't have F_GETFD and FD_CLOEXEC.  [ruby-core:40281] */
-#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) && !defined(__native_client__)
+#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
     int flags, flags2, ret;
     flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
     if (flags == -1) {
@@ -298,7 +298,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd https://github.com/ruby/ruby/blob/trunk/io.c#L298
 {
     int ret;
 
-#if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD) && !defined(__native_client__)
+#if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD)
     static int try_dupfd_cloexec = 1;
     if (try_dupfd_cloexec) {
         ret = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
@@ -318,10 +318,18 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd https://github.com/ruby/ruby/blob/trunk/io.c#L318
     else {
         ret = fcntl(fd, F_DUPFD, minfd);
     }
-#elif defined(HAVE_FCNTL) && defined(F_DUPFD) && !defined(__native_client__)
+#elif defined(HAVE_FCNTL) && defined(F_DUPFD)
     ret = fcntl(fd, F_DUPFD, minfd);
+#elif defined(HAVE_DUP)
+    ret = dup(fd);
+    if (ret != -1 && ret < minfd) {
+        const int prev_fd = ret;
+        ret = rb_cloexec_fcntl_dupfd(fd, minfd);
+        close(prev_fd);
+    }
+    return ret;
 #else
-    ret = dup2(fd, minfd);
+# error "dup() or fcntl(F_DUPFD) must be supported."
 #endif
     if (ret == -1) return -1;
     rb_maygvl_fd_fix_cloexec(ret);

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

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