summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--dir.c14
-rw-r--r--test/ruby/test_dir.rb1
3 files changed, 16 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a93c03..da778a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Mar 23 23:18:27 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* win32/file.c (rb_readlink): move from file.c for better buffer
diff --git a/dir.c b/dir.c
index 9fbbcb1..ab36950 100644
--- a/dir.c
+++ b/dir.c
@@ -543,11 +543,16 @@ dir_closed(void)
}
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)
{
struct dir_data *dirp;
- GetDIR(dir, dirp);
+ dirp = dir_get(dir);
+ if (!dirp->dir) return Qnil;
closedir(dirp->dir);
dirp->dir = NULL;
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 69ea57d..85247af 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -126,6 +126,7 @@ class TestDir < Test::Unit::TestCase
def test_close
d = Dir.open(@root)
d.close
+ assert_nothing_raised(IOError) { d.close }
assert_raise(IOError) { d.read }
end