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

ruby-changes:5287

From: shyouhei <ko1@a...>
Date: Tue, 3 Jun 2008 16:16:44 +0900 (JST)
Subject: [ruby-changes:5287] Ruby:r16786 (ruby_1_8_5): merge revision(s) 13513:

shyouhei	2008-06-03 16:15:05 +0900 (Tue, 03 Jun 2008)

  New Revision: 16786

  Modified files:
    branches/ruby_1_8_5/ChangeLog
    branches/ruby_1_8_5/parse.y
    branches/ruby_1_8_5/regex.c
    branches/ruby_1_8_5/version.h

  Log:
    merge revision(s) 13513:
    * parse.y (yyerror): limit error message length.  [ruby-dev:31848]
    * regex.c (re_mbc_startpos): separated from re_adjust_startpos.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/regex.c?r1=16786&r2=16785&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/version.h?r1=16786&r2=16785&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/parse.y?r1=16786&r2=16785&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/ChangeLog?r1=16786&r2=16785&diff_format=u

Index: ruby_1_8_5/parse.y
===================================================================
--- ruby_1_8_5/parse.y	(revision 16785)
+++ ruby_1_8_5/parse.y	(revision 16786)
@@ -2521,7 +2521,9 @@
 yyerror(msg)
     const char *msg;
 {
-    char *p, *pe, *buf;
+    const int max_line_margin = 30;
+    const char *p, *pe;
+    char *buf;
     int len, i;
 
     rb_compile_error("%s", msg);
@@ -2540,17 +2542,32 @@
 
     len = pe - p;
     if (len > 4) {
+	char *p2;
+	const char *pre = "", *post = "";
+
+	if (len > max_line_margin * 2 + 10) {
+	    int re_mbc_startpos _((const char *, int, int, int));
+	    if ((len = lex_p - p) > max_line_margin) {
+		p = p + re_mbc_startpos(p, len, len - max_line_margin, 0);
+		pre = "...";
+	    }
+	    if ((len = pe - lex_p) > max_line_margin) {
+		pe = lex_p + re_mbc_startpos(lex_p, len, max_line_margin, 1);
+		post = "...";
+	    }
+	    len = pe - p;
+	}
 	buf = ALLOCA_N(char, len+2);
 	MEMCPY(buf, p, char, len);
 	buf[len] = '\0';
-	rb_compile_error_append("%s", buf);
+	rb_compile_error_append("%s%s%s", pre, buf, post);
 
 	i = lex_p - p;
-	p = buf; pe = p + len;
+	p2 = buf; pe = buf + len;
 
-	while (p < pe) {
-	    if (*p != '\t') *p = ' ';
-	    p++;
+	while (p2 < pe) {
+	    if (*p2 != '\t') *p2 = ' ';
+	    p2++;
 	}
 	buf[i] = '^';
 	buf[i+1] = '\0';
Index: ruby_1_8_5/ChangeLog
===================================================================
--- ruby_1_8_5/ChangeLog	(revision 16785)
+++ ruby_1_8_5/ChangeLog	(revision 16786)
@@ -1,3 +1,9 @@
+Tue Jun  3 16:13:40 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (yyerror): limit error message length.  [ruby-dev:31848]
+
+	* regex.c (re_mbc_startpos): separated from re_adjust_startpos.
+
 Tue Jun  3 15:27:11 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* gc.c (os_obj_of, os_each_obj): hide objects to be finalized.
Index: ruby_1_8_5/version.h
===================================================================
--- ruby_1_8_5/version.h	(revision 16785)
+++ ruby_1_8_5/version.h	(revision 16786)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2008-06-03"
 #define RUBY_VERSION_CODE 185
 #define RUBY_RELEASE_CODE 20080603
-#define RUBY_PATCHLEVEL 123
+#define RUBY_PATCHLEVEL 124
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_5/regex.c
===================================================================
--- ruby_1_8_5/regex.c	(revision 16785)
+++ ruby_1_8_5/regex.c	(revision 16786)
@@ -3109,6 +3109,28 @@
 
 /* adjust startpos value to the position between characters. */
 int
+re_mbc_startpos(string, size, startpos, range)
+     const char *string;
+     int size, startpos, range;
+{
+  int i = mbc_startpos(string, startpos);
+
+  if (i < startpos) {
+    if (range > 0) {
+      startpos = i + mbclen(string[i]);
+    }
+    else {
+      int len = mbclen(string[i]);
+      if (i + len <= startpos)
+	startpos = i + len;
+      else
+	startpos = i;
+    }
+  }
+  return startpos;
+}
+
+int
 re_adjust_startpos(bufp, string, size, startpos, range)
      struct re_pattern_buffer *bufp;
      const char *string;
@@ -3121,20 +3143,7 @@
 
   /* Adjust startpos for mbc string */
   if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
-    int i = mbc_startpos(string, startpos);
-
-    if (i < startpos) {
-      if (range > 0) {
-	startpos = i + mbclen(string[i]);
-      }
-      else {
-	int len = mbclen(string[i]);
-	if (i + len <= startpos)
-	  startpos = i + len;
-	else
-	  startpos = i;
-      }
-    }
+    startpos = re_mbc_startpos(string, size, startpos, range);
   }
   return startpos;
 }

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

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