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

ruby-changes:37596

From: naruse <ko1@a...>
Date: Sun, 22 Feb 2015 02:17:14 +0900 (JST)
Subject: [ruby-changes:37596] naruse:r49677 (ruby_2_2): merge revision(s) 49661, 49662, 49664:

naruse	2015-02-22 02:17:08 +0900 (Sun, 22 Feb 2015)

  New Revision: 49677

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

  Log:
    merge revision(s) 49661,49662,49664:
    
    test_file_exhaustive.rb: remove useless assignment
    
    * test/ruby/test_file_exhaustive.rb (make_tmp_filename): not
      assign to instance variable, @hardlinkfile.
    * file.c (rb_file_identical_p): fix handle leak, ensure to close
      the handle of the first argument.

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/file.c
    branches/ruby_2_2/test/ruby/test_file_exhaustive.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 49676)
+++ ruby_2_2/ChangeLog	(revision 49677)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Sun Feb 22 02:16:40 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_file_identical_p): fix handle leak, ensure to close
+	  the handle of the first argument.
+
 Sat Feb 21 13:48:11 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/win32.c (different_device_p): compare by volume serial
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 49676)
+++ ruby_2_2/version.h	(revision 49677)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.0"
 #define RUBY_RELEASE_DATE "2015-02-22"
-#define RUBY_PATCHLEVEL 74
+#define RUBY_PATCHLEVEL 75
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_2/test/ruby/test_file_exhaustive.rb
===================================================================
--- ruby_2_2/test/ruby/test_file_exhaustive.rb	(revision 49676)
+++ ruby_2_2/test/ruby/test_file_exhaustive.rb	(revision 49677)
@@ -46,7 +46,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_file_exhaustive.rb#L46
   end
 
   def make_tmp_filename(prefix)
-    @hardlinkfile = @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
+    "#{@dir}/#{prefix}#{File.basename(__FILE__)}.#{$$}.test"
   end
 
   def test_path
@@ -291,13 +291,30 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_file_exhaustive.rb#L291
     assert_file.not_sticky?(@file)
   end
 
-  def test_identical_p
+  def test_path_identical_p
     assert_file.identical?(@file, @file)
     assert_file.not_identical?(@file, @zerofile)
     assert_file.not_identical?(@file, @nofile)
     assert_file.not_identical?(@nofile, @file)
   end
 
+  def test_io_identical_p
+    open(@file) {|f|
+      assert_file.identical?(f, f)
+      assert_file.identical?(@file, f)
+      assert_file.identical?(f, @file)
+    }
+  end
+
+  def test_closed_io_identical_p
+    io = open(@file) {|f| f}
+    assert_raise(IOError) {
+      File.identical?(@file, io)
+    }
+    File.unlink(@file)
+    assert_file.not_exist?(@file)
+  end
+
   def test_s_size
     assert_integer(File.size(@dir))
     assert_equal(3, File.size(@file))
Index: ruby_2_2/file.c
===================================================================
--- ruby_2_2/file.c	(revision 49676)
+++ ruby_2_2/file.c	(revision 49677)
@@ -1052,6 +1052,25 @@ w32_io_info(VALUE *file, BY_HANDLE_FILE_ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/file.c#L1052
     if (ret) CloseHandle(ret);
     return INVALID_HANDLE_VALUE;
 }
+
+static VALUE
+close_handle(VALUE h)
+{
+    CloseHandle((HANDLE)h);
+    return Qfalse;
+}
+
+struct w32_io_info_args {
+    VALUE *fname;
+    BY_HANDLE_FILE_INFORMATION *st;
+};
+
+static VALUE
+call_w32_io_info(VALUE arg)
+{
+    struct w32_io_info_args *p = (void *)arg;
+    return (VALUE)w32_io_info(p->fname, p->st);
+}
 #endif
 
 /*
@@ -1915,8 +1934,15 @@ rb_file_identical_p(VALUE obj, VALUE fna https://github.com/ruby/ruby/blob/trunk/ruby_2_2/file.c#L1934
 # ifdef _WIN32
     f1 = w32_io_info(&fname1, &st1);
     if (f1 == INVALID_HANDLE_VALUE) return Qfalse;
-    f2 = w32_io_info(&fname2, &st2);
-    if (f1) CloseHandle(f1);
+    if (f1) {
+	struct w32_io_info_args arg;
+	arg.fname = &fname2;
+	arg.st = &st2;
+	f2 = (HANDLE)rb_ensure(call_w32_io_info, (VALUE)&arg, close_handle, (VALUE)f1);
+    }
+    else {
+	f2 = w32_io_info(&fname2, &st2);
+    }
     if (f2 == INVALID_HANDLE_VALUE) return Qfalse;
     if (f2) CloseHandle(f2);
 

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49661-49662,49664


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

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