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

ruby-changes:37983

From: nobu <ko1@a...>
Date: Mon, 23 Mar 2015 23:19:00 +0900 (JST)
Subject: [ruby-changes:37983] nobu:r50064 (trunk): dir.c: don't raise after close

nobu	2015-03-23 23:18:30 +0900 (Mon, 23 Mar 2015)

  New Revision: 50064

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

  Log:
    dir.c: don't raise after close
    
    * dir.c (dir_close): don't raise on dobule close for consistent to
      IO#close.

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/test/ruby/test_dir.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50063)
+++ ChangeLog	(revision 50064)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Mar 23 23:18:27 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (dir_close): don't raise on dobule close for consistent to
+	  IO#close.
+
 Mon Mar 23 21:22:07 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/file.c (rb_readlink): move from file.c for better buffer
Index: dir.c
===================================================================
--- dir.c	(revision 50063)
+++ dir.c	(revision 50064)
@@ -543,11 +543,16 @@ dir_closed(void) https://github.com/ruby/ruby/blob/trunk/dir.c#L543
 }
 
 static struct dir_data *
-dir_check(VALUE dir)
+dir_get(VALUE dir)
 {
-    struct dir_data *dirp;
     rb_check_frozen(dir);
-    dirp = rb_check_typeddata(dir, &dir_data_type);
+    return rb_check_typeddata(dir, &dir_data_type);
+}
+
+static struct dir_data *
+dir_check(VALUE dir)
+{
+    struct dir_data *dirp = dir_get(dir);
     if (!dirp->dir) dir_closed();
     return dirp;
 }
@@ -831,7 +836,8 @@ dir_close(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L836
 {
     struct dir_data *dirp;
 
-    GetDIR(dir, dirp);
+    dirp = dir_get(dir);
+    if (!dirp->dir) return Qnil;
     closedir(dirp->dir);
     dirp->dir = NULL;
 
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 50063)
+++ test/ruby/test_dir.rb	(revision 50064)
@@ -126,6 +126,7 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L126
   def test_close
     d = Dir.open(@root)
     d.close
+    assert_nothing_raised(IOError) { d.close }
     assert_raise(IOError) { d.read }
   end
 

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

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