diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/tempfile.rb | 2 | ||||
-rw-r--r-- | test/test_tempfile.rb | 15 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 23 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Thu Oct 31 23:42:39 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed + after unlinking. patched by by normalperson (Eric Wong) at + [ruby-core:56521] [Bug #8768] + Thu Oct 31 23:40:43 2013 Zachary Scott <e@zzak.io> * lib/gserver.rb: [DOC] correct gserver.rb license [Bug #8913] diff --git a/lib/tempfile.rb b/lib/tempfile.rb index b34251ebb6..a34e178edb 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -190,7 +190,6 @@ class Tempfile < DelegateClass(File) 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) # remove tmpname from remover @data[0] = @data[1] = nil @tmpname = nil + ObjectSpace.undefine_finalizer(self) end alias delete unlink diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb index 1462a981f7..c6cbbeeeeb 100644 --- a/test/test_tempfile.rb +++ b/test/test_tempfile.rb @@ -206,6 +206,21 @@ puts Tempfile.new('foo').path 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.close + tmp.unlink + $DEBUG = true + EOS + refute File.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") @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 478 +#define RUBY_PATCHLEVEL 479 #define RUBY_RELEASE_DATE "2013-10-31" #define RUBY_RELEASE_YEAR 2013 |