From: sowieso@... Date: 2019-03-27T09:51:57+00:00 Subject: [ruby-core:92008] [Ruby trunk Feature#7148] Improved Tempfile w/o DelegateClass Issue #7148 has been updated by sowieso (So Wieso). I guess this is related: ``` ruby tf = Tempfile.new tf.unlink tf2 = tf.dup puts tf.fileno # => 10 puts tf2.fileno # => 11 tf2.close print tf2.fileno # => 11 print tf.fileno IOError: closed stream from /usr/local/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/delegate.rb:349:in `fileno' ``` It closes the wrong fd. Using normal `File` instead of `Tmpfile` makes it work like usual. Libraries that accept an IO object and duplicate it internally don't work correctly with `Tempfile` (in my case rubyzip). This really needs a fix. ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148#change-77337 * Author: Glass_saga (Masaki Matsushita) * Status: Assigned * Priority: Normal * Assignee: Glass_saga (Masaki Matsushita) * Target version: ---------------------------------------- I propose improved `Tempfile` without `DelegateClass()`. Present `Tempfile` has following problems. 1. confusing inspect ~~~ruby t = Tempfile.new("foo") #=> # t.is_a? File #=> false ~~~ 2. `#dup` doesn't duplicate `IO` ~~~ruby t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream ~~~ 3. finalizer performs unlink even when it has been duplicated ~~~ruby t = Tempfile.new("foo") path = t.path #=> "/tmp/foo20121012-7533-1q537gq" File.exist? path #=> true tt = t.dup t = nil GC.start File.exist? path #=> false ~~~ I think these problems caused by using `DelegateClass()`. Therefore, I made a patch to resolve the problems. The patched Tempfile class is a subclass of File. ---Files-------------------------------- patch.diff (3.52 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: