[MacRuby] #952: Should set got string to $_ when calls StringIO#gets #readline.
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Test Script: {{{ #!ruby require 'stringio' str = StringIO.new("hello world!") s = str.gets p s p $_ str = StringIO.new("1234") s = str.readline p s p $_ }}} Result: {{{ $ ruby19 -v test_stringio.rb ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0] "hello world!" "hello world!" "1234" "1234" $ macruby test_stringio.rb "hello world!" nil "1234" nil }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/952> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * milestone: => MacRuby 1.0 Comment: Looks like an easy bug to fix, assuming one can change $_ from ruby code. -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:1> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by warpflyght@…): Looks like you can't in MacRuby. The existing implementation tries to assign $_: {{{ def gets(sep=$/) $_ = getline(sep) end }}} You can assign $_ in Snow Leopard's stock Ruby 1.8.7, as well as a Ruby 1.9.2p0 build I installed with MacPorts. So, we have a reduction: {{{ $ ruby -e "\$_ = 'foo'; puts \$_.inspect" "foo" $ ruby1.9 -e "\$_ = 'foo'; puts \$_.inspect" "foo" $ macruby -e "\$_ = 'foo'; puts \$_.inspect" nil }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:2> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by warpflyght@…): This may be the problem. :) From vm.cpp: {{{ extern "C" VALUE rb_lastline_get(void) { // TODO return Qnil; } extern "C" void rb_lastline_set(VALUE val) { // TODO } }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:3> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by warpflyght@…): I've got a fix: [https://github.com/warpflyght/macruby/commit/1026bf7d84ce4744501becc7860f13e...]. Runs the sample script above correctly, and passes two specs in language/predefined_spec.rb that were failing previously. There may be a binary compatibility impact for some native extensions, because it entails adding an instance variable to RoxorVM. -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:4> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Thanks for the patch :) There is only one problem, the last_line instance variable is never initialized in the RoxorVM constructor. This could lead to unexpected results, so you may want to set it to Qnil there. Could you attach a unified diff file to this ticket after? I will then apply your change. Also feel free to remove the language/predefined_spec tags in your patch. -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:5> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): #1008 may be fixed after your patch. -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:6> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by warpflyght@…): Yep, you're absolutely right! Sorry about that. I've been using Objective-C too much! Patch is attached. I didn't change the comments in language/predefined_spec. In order to run the spec, I had to pass -r stringio to mspec, so that remains an issue. (Sorry if I misunderstood your meaning.) -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:7> MacRuby <http://macruby.org/>
#952: Should set got string to $_ when calls StringIO#gets #readline. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: minor | Milestone: MacRuby 0.8 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: MacRuby 1.0 => MacRuby 0.8 Comment: Thanks again for the patch, I applied it in r4986. The test script works as expected now: {{{ $ ./miniruby t.rb "hello world!" "hello world!" "1234" "1234" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/952#comment:8> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby