[前][次][番号順一覧][スレッド一覧]

ruby-changes:8616

From: matz <ko1@a...>
Date: Sat, 8 Nov 2008 17:48:53 +0900 (JST)
Subject: [ruby-changes:8616] Ruby:r20151 (ruby_1_8): * ext/stringio/stringio.c (strio_ungetc): should allow ungetc at

matz	2008-11-08 17:48:43 +0900 (Sat, 08 Nov 2008)

  New Revision: 20151

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20151

  Log:
    * ext/stringio/stringio.c (strio_ungetc): should allow ungetc at
      the top of the buffer.  ref #701

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/ext/stringio/stringio.c

Index: ruby_1_8/ext/stringio/stringio.c
===================================================================
--- ruby_1_8/ext/stringio/stringio.c	(revision 20150)
+++ ruby_1_8/ext/stringio/stringio.c	(revision 20151)
@@ -781,15 +781,24 @@
     int cc = NUM2INT(ch);
     long len, pos = ptr->pos;
 
-    if (cc != EOF && pos > 0) {
-	if ((len = RSTRING(ptr->string)->len) < pos-- ||
-	    (unsigned char)RSTRING(ptr->string)->ptr[pos] !=
-	    (unsigned char)cc) {
-	    strio_extend(ptr, pos, 1);
-	    RSTRING(ptr->string)->ptr[pos] = cc;
-	    OBJ_INFECT(ptr->string, self);
+    if (cc != EOF) {
+	len = RSTRING(ptr->string)->len;
+	if (pos == 0) {
+	    char *p;
+	    rb_str_resize(ptr->string, len + 1);
+	    p = RSTRING(ptr->string)->ptr;
+	    memmove(p + 1, p, len);
 	}
-	--ptr->pos;
+	else {
+	    if (len < pos-- ||
+		(unsigned char)RSTRING(ptr->string)->ptr[pos] !=
+		(unsigned char)cc) {
+		strio_extend(ptr, pos, 1);
+	    }
+	    --ptr->pos;
+	}
+	RSTRING(ptr->string)->ptr[pos] = cc;
+	OBJ_INFECT(ptr->string, self);
 	ptr->flags &= ~STRIO_EOF;
     }
     return Qnil;
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 20150)
+++ ruby_1_8/ChangeLog	(revision 20151)
@@ -1,3 +1,8 @@
+Sat Nov  8 17:47:28 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* ext/stringio/stringio.c (strio_ungetc): should allow ungetc at
+	  the top of the buffer.  ref #701
+
 Sat Nov  8 01:38:07 2008  NARUSE, Yui  <naruse@r...>
 
 	* ext/nkf/nkf-utf8/nkf.c (h_conv): can't guess UTF-8 input in

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]