[#3726] Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...>

Hi --

15 messages 2004/11/12
[#3749] Re: Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...> 2004/11/16

Hi --

[#3751] Re: Fixnum#clone and Float#clone raise different exceptions — Yukihiro Matsumoto <matz@...> 2004/11/16

Hi,

[#3752] Re: Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...> 2004/11/16

Hi --

[#3785] The latest 1.8.2 cvs prints parse error when starting extension compiling — Yukihiro Matsumoto <matz@...>

Hi,

13 messages 2004/11/23
[#3787] Re: The latest 1.8.2 cvs prints parse error when starting extension compiling — Johan Holmberg <holmberg@...> 2004/11/23

Re: Bug in IO#gets("") in 1.9 ?

From: Minero Aoki <aamine@...>
Date: 2004-11-20 13:18:23 UTC
List: ruby-core #3779
Hi,

  In mail "Bug in IO#gets("") in 1.9 ?"
    Johan Holmberg <holmberg@iar.se> wrote:

> Is the following change in IO#gets intentional, or is it a bug? 
> Example script:

> output in 1.8.2:
> 
>      "paragraph\n1\n\n"
>      "paragraph\n2\n"
> 
> output in 1.9:
> 
>      "paragraph\n1\n\nparagraph\n2\n"

Following patch may help you.

Sat Nov 20 22:12:44 2004  Minero Aoki  <aamine@loveruby.net>

	* io.c (rb_io_getline): io.gets("") did not work. [ruby-core:03771]


--- io.c	19 Nov 2004 16:59:11 -0000	1.320
+++ io.c	20 Nov 2004 13:10:29 -0000
@@ -1448,10 +1448,14 @@
 	}
 	newline = rsptr[rslen - 1];
 
-	while ((c = appendline(fptr, newline, &str)) != EOF &&
-	       (c != newline || RSTRING(str)->len < rslen ||
-		(rspara || rscheck(rsptr,rslen,rs)) ||
-		memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen)));
+	while ((c = appendline(fptr, newline, &str)) != EOF) {
+	    if (c == newline) {
+		if (RSTRING(str)->len < rslen) continue;
+		if (!rspara) rscheck(rsptr, rslen, rs);
+		if (memcmp(RSTRING(str)->ptr + RSTRING(str)->len - rslen,
+			   rsptr, rslen) == 0) break;
+	    }
+	}
 
 	if (rspara) {
 	    if (c != EOF) {
--- test/ruby/test_io.rb	9 Oct 2004 11:53:11 -0000	1.1
+++ test/ruby/test_io.rb	20 Nov 2004 13:10:29 -0000
@@ -2,10 +2,37 @@
 
 class TestIO < Test::Unit::TestCase
   def test_gets_rs
+    # default_rs
+    r, w = IO.pipe
+    w.print "aaa\nbbb\n"
+    w.close
+    assert_equal "aaa\n", r.gets
+    assert_equal "bbb\n", r.gets
+    assert_nil r.gets
+    r.close
+
+    # nil
+    r, w = IO.pipe
+    w.print "a\n\nb\n\n"
+    w.close
+    assert_equal "a\n\nb\n\n", r.gets(nil)
+    assert_nil r.gets("")
+    r.close
+
+    # "\377" [ruby-dev:24460]
     r, w = IO.pipe
     w.print "\377xyz"
     w.close
     assert_equal("\377", r.gets("\377"), "[ruby-dev:24460]")
+    r.close
+
+    # "" [ruby-core:03771]
+    r, w = IO.pipe
+    w.print "a\n\nb\n\n"
+    w.close
+    assert_equal "a\n\n", r.gets("")
+    assert_equal "b\n\n", r.gets("")
+    assert_nil r.gets("")
     r.close
   end
 end


Regards,
Minero Aoki

In This Thread