mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
57c7de44fc
commit
ec2db8decf
3 changed files with 21 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Oct 1 22:03:48 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]
|
||||||
|
|
||||||
Tue Oct 1 20:54:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Oct 1 20:54:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* file.c (stat_new_0): constify.
|
* file.c (stat_new_0): constify.
|
||||||
|
|
|
@ -190,7 +190,6 @@ class Tempfile < DelegateClass(File)
|
||||||
def close!
|
def close!
|
||||||
_close
|
_close
|
||||||
unlink
|
unlink
|
||||||
ObjectSpace.undefine_finalizer(self)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Unlinks (deletes) the file from the filesystem. One should always unlink
|
# Unlinks (deletes) the file from the filesystem. One should always unlink
|
||||||
|
@ -238,6 +237,7 @@ class Tempfile < DelegateClass(File)
|
||||||
# remove tmpname from remover
|
# remove tmpname from remover
|
||||||
@data[0] = @data[1] = nil
|
@data[0] = @data[1] = nil
|
||||||
@tmpname = nil
|
@tmpname = nil
|
||||||
|
ObjectSpace.undefine_finalizer(self)
|
||||||
end
|
end
|
||||||
alias delete unlink
|
alias delete unlink
|
||||||
|
|
||||||
|
|
|
@ -206,6 +206,20 @@ puts Tempfile.new('foo').path
|
||||||
end
|
end
|
||||||
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
|
def test_size_flushes_buffer_before_determining_file_size
|
||||||
t = tempfile("foo")
|
t = tempfile("foo")
|
||||||
t.write("hello")
|
t.write("hello")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue