summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--bootstraptest/test_io.rb10
-rw-r--r--bootstraptest/test_knownbug.rb10
-rw-r--r--io.c45
4 files changed, 31 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a80bb439c..32c869c77c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,10 @@ Tue Dec 25 18:40:46 2007 Koichi Sasada <ko1@atdot.net>
vm.c: comment out debug functions.
+Tue Dec 25 18:37:42 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (appendline): move RS comparison to rb_io_getline_1().
+
Tue Dec 25 18:27:51 2007 Tanaka Akira <akr@fsij.org>
* string.c (rb_str_each_line): don't call rb_enc_codepoint with empty
diff --git a/bootstraptest/test_io.rb b/bootstraptest/test_io.rb
index fa3654379f..019a82d9bd 100644
--- a/bootstraptest/test_io.rb
+++ b/bootstraptest/test_io.rb
@@ -26,3 +26,13 @@ assert_finish 10, %q{
rescue LoadError
end
}, '[ruby-dev:32566]'
+
+assert_finish 1, %q{
+ r, w = IO.pipe
+ Thread.new {
+ w << "ab"
+ sleep 0.1
+ w << "ab"
+ }
+ p r.gets("abab")
+}
diff --git a/bootstraptest/test_knownbug.rb b/bootstraptest/test_knownbug.rb
index 2a70de0269..24e3c5483a 100644
--- a/bootstraptest/test_knownbug.rb
+++ b/bootstraptest/test_knownbug.rb
@@ -3,16 +3,6 @@
# So all tests will cause failure.
#
-assert_finish 1, %q{
- r, w = IO.pipe
- Thread.new {
- w << "ab"
- sleep 0.1
- w << "ab"
- }
- p r.gets("abab")
-}
-
assert_normal_exit %q{
begin
raise
diff --git a/io.c b/io.c
index 41449beb33..7c5ee6f205 100644
--- a/io.c
+++ b/io.c
@@ -1665,12 +1665,11 @@ rscheck(const char *rsptr, long rslen, VALUE rs)
}
static int
-appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE rs, VALUE *strp, long *lp)
+appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE *strp, long *lp)
{
VALUE str = *strp;
int c = EOF;
long limit = *lp;
- rb_encoding *enc = io_input_encoding(fptr);
if (rsptr == 0)
rslen = 1;
@@ -1678,34 +1677,14 @@ appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE rs, VAL
do {
long pending = READ_DATA_PENDING_COUNT(fptr);
if (pending > 0) {
- const char *s = READ_DATA_PENDING_PTR(fptr);
- const char *p, *e, *pp;
+ const char *p = READ_DATA_PENDING_PTR(fptr);
+ const char *e;
long last = 0, len = (c != EOF);
if (limit > 0 && pending > limit) pending = limit;
- pp = p = s;
again:
e = memchr(p, delim, pending);
- if (e) {
- const char *p0 = e - rslen + 1;
- if (p0 < s) {
- p = e + 1;
- goto again;
- }
- pp = rb_enc_left_char_head(pp, p0, enc);
- if (pp != p0) {
- p = e + 1;
- goto again;
- }
- if (rsptr) {
- rscheck(rsptr, rslen, rs);
- if (memcmp(p0, rsptr, rslen) != 0) {
- p = e + 1;
- goto again;
- }
- }
- pending = e - s + 1;
- }
+ if (e) pending = e - p + 1;
len += pending;
if (!NIL_P(str)) {
last = RSTRING_LEN(str);
@@ -1785,7 +1764,7 @@ rb_io_getline_fast(rb_io_t *fptr, unsigned char delim, long limit)
int c, nolimit = 0;
for (;;) {
- c = appendline(fptr, delim, 0, 0, 0, &str, &limit);
+ c = appendline(fptr, delim, 0, 0, &str, &limit);
if (c == EOF || c == delim) break;
if (limit == 0) {
nolimit = 1;
@@ -1853,9 +1832,11 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
VALUE str = Qnil;
rb_io_t *fptr;
int nolimit = 0;
+ rb_encoding *enc;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
+ enc = io_input_encoding(fptr);
if (NIL_P(rs)) {
str = read_all(fptr, 0, Qnil);
if (RSTRING_LEN(str) == 0) return Qnil;
@@ -1888,9 +1869,17 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
}
newline = rsptr[rslen - 1];
- while ((c = appendline(fptr, newline, rsptr, rslen, rs, &str, &limit)) != EOF) {
+ while ((c = appendline(fptr, newline, rsptr, rslen, &str, &limit)) != EOF) {
if (c == newline) {
- break;
+ const char *s, *p, *pp;
+
+ if (RSTRING_LEN(str) < rslen) continue;
+ s = RSTRING_PTR(str);
+ p = s + RSTRING_LEN(str) - rslen;
+ pp = rb_enc_left_char_head(s, p, enc);
+ if (pp != p) continue;
+ if (!rspara) rscheck(rsptr, rslen, rs);
+ if (memcmp(p, rsptr, rslen) == 0) break;
}
if (limit == 0) {
nolimit = 1;