https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112010-01-23T01:30:50ZRuby Issue Tracking SystemRuby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=77682010-01-23T01:30:50Zhongli (Hongli Lai)hongli@phusion.nl
<ul></ul><p>=begin<br>
I don't think this can be implemented easily. This can be implemented if the IO object in question is a File for which you know the filename. For sockets, pipes and other stuff it becomes tricker: one can emulate it backing up the underlying file descriptor by dup()ing it, but in my opinion that goes against my expectation of what #reopen should do: to replace the file descriptor with something else.<br>
=end</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=77732010-01-23T04:28:01Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/27702">[ruby-core:27702]</a> [Feature <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Allow IO#reopen to take a block (Assigned)" href="https://redmine.ruby-lang.org/issues/2631">#2631</a>] Allow IO#reopen to take a block"<br>
on Sat, 23 Jan 2010 01:30:53 +0900, Hongli Lai <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<blockquote>
<p>I don't think this can be implemented easily. This can be implemented if the IO object in question is a File for which you know the filename. For sockets, pipes and other stuff it becomes tricker: one can emulate it backing up the underlying file descriptor by dup()ing it, but in my opinion that goes against my expectation of what #reopen should do: to replace the file descriptor with something else.</p>
</blockquote>
<p>Agreed. Besides that behavior would not be thread safe.</p>
<pre><code> matz.
</code></pre> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=77772010-01-23T14:56:06Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>+1, The idea of temporary intercepting any output to another IO is worth considering. Though I doubt to name that feature a "reopen".</p>
<p>So my suggestion is: create a new method, that takes a block, to intercept an IO.</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=78052010-01-24T23:07:45Zdjberg96 (Daniel Berger)
<ul></ul><p>On Fri, Jan 22, 2010 at 10:56 PM, Shyouhei Urabe <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Allow IO#reopen to take a block (Assigned)" href="https://redmine.ruby-lang.org/issues/2631">#2631</a> has been updated by Shyouhei Urabe.</p>
<p>+1, The idea of temporary intercepting any output to another IO is worth considering. Though I doubt to name that feature a "reopen".</p>
</blockquote>
<p>How about <code>IO#redirect</code>.</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=96952010-04-02T08:46:25Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Target version</strong> set to <i>2.0.0</i></li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=246992012-03-18T14:58:51Znahi (Hiroshi Nakamura)nakahiro@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/24699/diff?detail_id=17984">diff</a>)</li><li><strong>Assignee</strong> set to <i>shyouhei (Shyouhei Urabe)</i></li></ul><p>Method name?</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=247032012-03-18T15:12:48Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>I don't feel changing <code>IO#reopen</code> is great way to solve this issue.</p>
<p>How about <code>spawn()</code>?</p>
<p>Since Ruby 1.9, <code>spawn</code> provides a primitive for redirection.<br>
It is thread safe.</p>
<p>Apart from that, I think <code>$stdin</code>, <code>$stdout</code>, <code>$stderr</code> can be thread-local<br>
variables, though.</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=248562012-03-18T18:46:38Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=316522012-10-27T05:51:24Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>2.0.0</i> to <i>2.6</i></li></ul><p>I was poked by _ko1. But we lack a implementation proposal.</p>
<p>So I move its target to next minor. It might happen to be implemented some time later but not today.</p>
<p>Any opinions?</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654382017-06-22T06:50:39ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r59142.</p>
<hr>
<p>Allow IO#reopen to take a block</p>
<ul>
<li>
<p>io.c (rb_io_reopen): take a block and ensure the IO closed<br>
[Feature <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Allow IO#reopen to take a block (Assigned)" href="https://redmine.ruby-lang.org/issues/2631">#2631</a>]</p>
</li>
<li>
<p>test/ruby/test_io.rb: add a test</p>
</li>
<li>
<p>NEWS: add an entry for this change</p>
</li>
</ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654422017-06-22T08:35:20Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li></ul><p>匿名ユーザー wrote:</p>
<blockquote>
<p>Applied in changeset trunk|r59142.</p>
<hr>
<p>Allow IO#reopen to take a block</p>
<ul>
<li>
<p>io.c (rb_io_reopen): take a block and ensure the IO closed<br>
[Feature <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Allow IO#reopen to take a block (Assigned)" href="https://redmine.ruby-lang.org/issues/2631">#2631</a>]</p>
</li>
<li>
<p>test/ruby/test_io.rb: add a test</p>
</li>
<li>
<p>NEWS: add an entry for this change</p>
</li>
</ul>
</blockquote>
<p>This patch looks doesn't recover the original $stdout.</p>
<p>Morever though this was approved before, this is strange because block changes global state.<br>
If this is introduced in 7 years ago, it may be acceptable.<br>
But in this 201x year Ruby really should support multithread unsafe code?<br>
People who want to write unsafe code should explicitly write code like following.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'mkmf'</span>
<span class="c1"># stdout redirected within block only</span>
<span class="n">orig_stdout</span> <span class="o">=</span> <span class="vg">$stdout</span>
<span class="nb">open</span><span class="p">(</span><span class="no">IO</span><span class="ss">:NULL</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span>
<span class="vg">$stdout</span> <span class="o">=</span> <span class="n">f</span>
<span class="k">if</span> <span class="n">have_header</span><span class="p">(</span><span class="s1">'foo.h'</span><span class="p">)</span>
<span class="c1"># Do stuff</span>
<span class="k">end</span>
<span class="k">ensure</span>
<span class="vg">$stdout</span> <span class="o">=</span> <span class="n">orig_stdout</span>
<span class="k">end</span>
</code></pre> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654432017-06-22T08:35:35Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> changed from <i>2.6</i> to <i>2.5</i></li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654442017-06-23T03:38:00ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>Assignee</strong> changed from <i>shyouhei (Shyouhei Urabe)</i> to <i>Glass_saga (Masaki Matsushita)</i></li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654452017-06-23T03:38:50ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Assigned</i></li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=654462017-06-23T04:20:05ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul></ul><p>It was thoughtless. Let me revert it.</p> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=684272017-12-14T18:23:54Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.5</i></del>)</li></ul> Ruby master - Feature #2631: Allow IO#reopen to take a blockhttps://redmine.ruby-lang.org/issues/2631?journal_id=722432018-05-24T13:22:01ZBookgoogleflights (google flights)
<ul></ul><p>The idea of temporary intercepting any output to another IO is worth considering. Though I doubt to name that feature a "reopen".est/ruby/test_io.rb: add a test NEWS: add an entry for this change, he new Google Flights offers all of the speed and usability of the old Google Flights, but with some great new features added on top book flights using "bookgoogleflights.wordpress.com":<a href="https://bookgoogleflights.wordpress.com/" class="external">https://bookgoogleflights.wordpress.com/</a></p>