Issue #7148 has been reported by Glass_saga (Masaki Matsushita). ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148 Author: Glass_saga (Masaki Matsushita) Status: Open Priority: Normal Assignee: Category: lib Target version: I propose improved Tempfile without DelegateClass(). Present Tempfile has following problems. 1) confusing inspect t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to> t.is_a? File #=> false 2) #dup doesn't duplicate IO t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream 3) finalizer performs unlink even when it has been duplicated 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.
on 2012-10-12 07:04
on 2012-10-12 07:19
Hi,
In message "Re: [ruby-core:47930] [ruby-trunk - Feature #7148][Open]
Improved Tempfile w/o DelegateClass"
on Fri, 12 Oct 2012 14:04:08 +0900, "Glass_saga (Masaki Matsushita)"
<glass.saga@gmail.com> writes:
|I propose improved Tempfile without DelegateClass().
|Present Tempfile has following problems.
|
|1) confusing inspect
|2) #dup doesn't duplicate IO
|3) finalizer performs unlink even when it has been duplicated
I have no objection about (1), but what we expect when we call
Tempfile#dup might differ, for example, I'd expect it to copy the
underlying temporary file. So making Tempfile a subclass of File
may not be the ideal solution.
matz.
on 2012-10-16 02:50
Issue #7148 has been updated by Glass_saga (Masaki Matsushita). Hello, Yukihiro Matsumoto wrote: > I'd expect it to copy the underlying temporary file. Is the behavior of #dup you expect like the following? def dup dupe = self.class.new(@basename) IO.copy_stream(self, dupe, 0) dupe end I think the reason why Tempfile uses DelegateClass is that to implement Tempfile#open without it used to be difficult. To implement it as subclass of File, self must be reopened with full configuration, mode and opts. IO#reopen used not to accept them, but now it accepts after r37071. ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148#change-30801 Author: Glass_saga (Masaki Matsushita) Status: Open Priority: Normal Assignee: Category: lib Target version: I propose improved Tempfile without DelegateClass(). Present Tempfile has following problems. 1) confusing inspect t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to> t.is_a? File #=> false 2) #dup doesn't duplicate IO t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream 3) finalizer performs unlink even when it has been duplicated 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.
on 2012-10-17 19:35
Issue #7148 has been updated by headius (Charles Nutter). JRuby has been running with Tempfile < File for a couple years now, and have received only minor bug reports about it. It works very well, and has no delegation cost. ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148#change-30976 Author: Glass_saga (Masaki Matsushita) Status: Open Priority: Normal Assignee: Category: lib Target version: I propose improved Tempfile without DelegateClass(). Present Tempfile has following problems. 1) confusing inspect t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to> t.is_a? File #=> false 2) #dup doesn't duplicate IO t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream 3) finalizer performs unlink even when it has been duplicated 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.
on 2012-11-16 07:02
Issue #7148 has been updated by Glass_saga (Masaki Matsushita). Are there some reasons not to make Tempfile a subclass of File? I think it's a better solution, even if it's not an ideal solution. ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148#change-32955 Author: Glass_saga (Masaki Matsushita) Status: Open Priority: Normal Assignee: Category: lib Target version: I propose improved Tempfile without DelegateClass(). Present Tempfile has following problems. 1) confusing inspect t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to> t.is_a? File #=> false 2) #dup doesn't duplicate IO t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream 3) finalizer performs unlink even when it has been duplicated 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.
on 2012-11-24 02:55
Issue #7148 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee set to matz (Yukihiro Matsumoto) Priority changed from Normal to Low Target version set to next minor ---------------------------------------- Feature #7148: Improved Tempfile w/o DelegateClass https://bugs.ruby-lang.org/issues/7148#change-33721 Author: Glass_saga (Masaki Matsushita) Status: Assigned Priority: Low Assignee: matz (Yukihiro Matsumoto) Category: lib Target version: next minor I propose improved Tempfile without DelegateClass(). Present Tempfile has following problems. 1) confusing inspect t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to> t.is_a? File #=> false 2) #dup doesn't duplicate IO t = Tempfile.new("foo") t.dup.close t.read #=> IOError: closed stream 3) finalizer performs unlink even when it has been duplicated 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.