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

ruby-changes:35306

From: akr <ko1@a...>
Date: Fri, 5 Sep 2014 00:54:32 +0900 (JST)
Subject: [ruby-changes:35306] akr:r47387 (trunk): * configure.in (dirfd): Check function.

akr	2014-09-05 00:54:04 +0900 (Fri, 05 Sep 2014)

  New Revision: 47387

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

  Log:
    * configure.in (dirfd): Check function.
    
    * dir.c (dir_fileno): New method.
      [ruby-dev:48265] [Feature #9880]

  Removed directories:
    trunk/ext/-test-/dir/
  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/configure.in
    trunk/dir.c
    trunk/test/lib/leakchecker.rb
    trunk/test/ruby/test_dir.rb
Index: configure.in
===================================================================
--- configure.in	(revision 47386)
+++ configure.in	(revision 47387)
@@ -1974,6 +1974,7 @@ AC_CHECK_FUNCS(chsize) https://github.com/ruby/ruby/blob/trunk/configure.in#L1974
 AC_CHECK_FUNCS(clock_gettime)
 AC_CHECK_FUNCS(cosh)
 AC_CHECK_FUNCS(daemon)
+AC_CHECK_FUNCS(dirfd)
 AC_CHECK_FUNCS(dl_iterate_phdr)
 AC_CHECK_FUNCS(dlopen)
 AC_CHECK_FUNCS(dladdr)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47386)
+++ ChangeLog	(revision 47387)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep  5 00:29:08 2014  Tanaka Akira  <akr@f...>
+
+	* configure.in (dirfd): Check function.
+
+	* dir.c (dir_fileno): New method.
+	  [ruby-dev:48265] [Feature #9880]
+
 Thu Sep  4 23:39:52 2014  Tanaka Akira  <akr@f...>
 
 	* process.c (has_privilege): New function.
Index: dir.c
===================================================================
--- dir.c	(revision 47386)
+++ dir.c	(revision 47387)
@@ -539,6 +539,37 @@ dir_inspect(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L539
     return rb_funcall(dir, rb_intern("to_s"), 0, 0);
 }
 
+#ifdef HAVE_DIRFD
+/*
+ *  call-seq:
+ *     dir.fileno -> integer
+ *
+ *  Returns the file descriptor used in <em>dir</em>.
+ *
+ *     d = Dir.new("..")
+ *     d.fileno   #=> 8
+ *
+ *  This method uses dirfd() function defined by POSIX 2008.
+ *  NotImplementedError is raised on other platforms, such as Windows,
+ *  which doesn't provide the function.
+ *
+ */
+static VALUE
+dir_fileno(VALUE dir)
+{
+    struct dir_data *dirp;
+    int fd;
+
+    GetDIR(dir, dirp);
+    fd = dirfd(dirp->dir);
+    if (fd == -1)
+	rb_sys_fail("dirfd");
+    return INT2NUM(fd);
+}
+#else
+#define dir_fileno rb_f_notimplement
+#endif
+
 /*
  *  call-seq:
  *     dir.path -> string or nil
@@ -2259,6 +2290,7 @@ Init_Dir(void) https://github.com/ruby/ruby/blob/trunk/dir.c#L2290
     rb_define_singleton_method(rb_cDir, "entries", dir_entries, -1);
 
     rb_define_method(rb_cDir,"initialize", dir_initialize, -1);
+    rb_define_method(rb_cDir,"fileno", dir_fileno, 0);
     rb_define_method(rb_cDir,"path", dir_path, 0);
     rb_define_method(rb_cDir,"to_path", dir_path, 0);
     rb_define_method(rb_cDir,"inspect", dir_inspect, 0);
Index: NEWS
===================================================================
--- NEWS	(revision 47386)
+++ NEWS	(revision 47387)
@@ -20,6 +20,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L20
     * Binding#local_variables
     * Binding#receiver
 
+* Dir
+  * New methods:
+    * Dir#fileno
+
 * Enumerable
   * New methods:
     * Enumerable#slice_after
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 47386)
+++ test/ruby/test_dir.rb	(revision 47387)
@@ -294,4 +294,14 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L294
       end
     end
   end
+
+  def test_fileno
+    Dir.open(".") {|d|
+      if d.respond_to? :fileno
+        assert_kind_of(Integer, d.fileno)
+      else
+        assert_raise(NotImplementedError) { d.fileno }
+      end
+    }
+  end
 end
Index: test/lib/leakchecker.rb
===================================================================
--- test/lib/leakchecker.rb	(revision 47386)
+++ test/lib/leakchecker.rb	(revision 47387)
@@ -15,7 +15,6 @@ class LeakChecker https://github.com/ruby/ruby/blob/trunk/test/lib/leakchecker.rb#L15
   def find_fds
     fd_dir = "/proc/self/fd"
     if File.directory?(fd_dir)
-      require "-test-/dir"
       fds = Dir.open(fd_dir) {|d|
         a = d.grep(/\A\d+\z/, &:to_i)
         if d.respond_to? :fileno

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

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