Bug #8768

[PATCH] tempfile: undefine finalizer on unlink

Added by Eric Wong almost 2 years ago. Updated over 1 year ago.

[ruby-core:56521]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
ruby -v:ruby 2.1.0dev (2013-08-10 trunk 42491) [x86_64-linux] Backport:1.9.3: DONE, 2.0.0: DONE

Description

  • lib/tempfile.rb (Tempfile#unlink): undefine finalizer

running the finalizer on an unlinked Tempfile leads to a confusing
"removing ...done" message when using --debug. We can rely on
normal GC to close. rb_io_fptr_finalize will take care of closing
the descriptor without the extra finalizer for Tempfile.

0001-lib-tempfile.rb-Tempfile-unlink-undefine-finalizer.patch Magnifier - patch incuding testcase (1.84 KB) Eric Wong, 08/11/2013 04:41 AM

Associated revisions

Revision 43110
Added by Nobuyoshi Nakada almost 2 years ago

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 [Bug #8768]

Revision 43110
Added by Nobuyoshi Nakada almost 2 years ago

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 [Bug #8768]

History

#1 Updated by Yui NARUSE almost 2 years ago

  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

I know you are not the maintainer but could you review and commit this?

#2 Updated by Nobuyoshi Nakada almost 2 years ago

=begin
I couldn't let the test fail with the current code, but succeeded by setting $DEBUG at the end.

def test_tempfile_finalizer_does_not_run_if_unlinked
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, "we used to get a confusing 'removing ...done' here"
end
end
=end

#3 Updated by Nobuyoshi Nakada almost 2 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED

#4 Updated by Nobuyoshi Nakada almost 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43110.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


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 [Bug #8768]

#5 Updated by Tomoyuki Chikanaga over 1 year ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE

backport r43110 and r43155 to ruby_2_0_0 at r43229.

#6 Updated by Usaku NAKAMURA over 1 year ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE to 1.9.3: DONE, 2.0.0: DONE

Backported to ruby_1_9_3 at r43490.

Also available in: Atom PDF