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

ruby-changes:31031

From: nobu <ko1@a...>
Date: Tue, 1 Oct 2013 22:04:22 +0900 (JST)
Subject: [ruby-changes:31031] nobu:r43110 (trunk): tempfile.rb: undefine finalizer on unlink

nobu	2013-10-01 22:03:58 +0900 (Tue, 01 Oct 2013)

  New Revision: 43110

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

  Log:
    tempfile.rb: undefine finalizer on unlink
    
    * lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed
      after unlinking.  patched by by normalperson (Eric Wong) at
      [ruby-core:56521] [Bug #8768]

  Modified files:
    trunk/ChangeLog
    trunk/lib/tempfile.rb
    trunk/test/test_tempfile.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43109)
+++ ChangeLog	(revision 43110)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct  1 22:03:48 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed
+	  after unlinking.  patched by by normalperson (Eric Wong) at
+	  [ruby-core:56521] [Bug #8768]
+
 Tue Oct  1 20:54:33 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* file.c (stat_new_0): constify.
Index: lib/tempfile.rb
===================================================================
--- lib/tempfile.rb	(revision 43109)
+++ lib/tempfile.rb	(revision 43110)
@@ -190,7 +190,6 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L190
   def close!
     _close
     unlink
-    ObjectSpace.undefine_finalizer(self)
   end
 
   # Unlinks (deletes) the file from the filesystem. One should always unlink
@@ -238,6 +237,7 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L237
     # remove tmpname from remover
     @data[0] = @data[1] = nil
     @tmpname = nil
+    ObjectSpace.undefine_finalizer(self)
   end
   alias delete unlink
 
Index: test/test_tempfile.rb
===================================================================
--- test/test_tempfile.rb	(revision 43109)
+++ test/test_tempfile.rb	(revision 43110)
@@ -206,6 +206,20 @@ puts Tempfile.new('foo').path https://github.com/ruby/ruby/blob/trunk/test/test_tempfile.rb#L206
     end
   end
 
+  def test_tempfile_finalizer_does_not_run_if_unlinked
+    bug8768 = '[ruby-core:56521] [Bug #8768]'
+    args = %w(--disable-gems -rtempfile)
+    assert_in_out_err(args, <<-'EOS') do |(filename), (error)|
+      tmp = Tempfile.new('foo')
+      puts tmp.path
+      tmp.unlink
+      $DEBUG = true
+      EOS
+      assert_file.not_exist?(filename)
+      assert_nil(error, "#{bug8768} we used to get a confusing 'removing ...done' here")
+    end
+  end
+
   def test_size_flushes_buffer_before_determining_file_size
     t = tempfile("foo")
     t.write("hello")

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

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