[#92063] [Ruby trunk Misc#15723] Reconsider numbered parameters — zverok.offline@...
SXNzdWUgIzE1NzIzIGhhcyBiZWVuIHVwZGF0ZWQgYnkgenZlcm9rIChWaWN0b3IgU2hlcGVsZXYp
3 messages
2019/03/31
[ruby-core:92008] [Ruby trunk Feature#7148] Improved Tempfile w/o DelegateClass
From:
sowieso@...
Date:
2019-03-27 09:51:57 UTC
List:
ruby-core #92008
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") #=> #<File:/tmp/foo20121012-6762-12w11to>
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: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>