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

ruby-changes:14779

From: nobu <ko1@a...>
Date: Thu, 11 Feb 2010 14:43:36 +0900 (JST)
Subject: [ruby-changes:14779] Ruby:r26640 (trunk): * marshal.c (r_object0): replace non-1.8 escapes directly.

nobu	2010-02-11 14:43:19 +0900 (Thu, 11 Feb 2010)

  New Revision: 26640

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

  Log:
    * marshal.c (r_object0): replace non-1.8 escapes directly.

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26639)
+++ ChangeLog	(revision 26640)
@@ -1,8 +1,10 @@
-Thu Feb 11 14:37:39 2010  Nobuyoshi Nakada  <nobu@r...>
+Thu Feb 11 14:43:16 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* marshal.c (r_object0): read sequentially since marshal source
 	  may not be possible to rewind.  [ruby-dev:40386]
 
+	* marshal.c (r_object0): replace non-1.8 escapes directly.
+
 Thu Feb 11 09:49:31 2010  Tanaka Akira  <akr@f...>
 
 	* lib/resolv.rb: fix [ruby-core:28144] reported by Hans de Graaff.
Index: marshal.c
===================================================================
--- marshal.c	(revision 26639)
+++ marshal.c	(revision 26640)
@@ -1501,13 +1501,23 @@
 		*ivp = FALSE;
 	    }
 	    if (!has_encoding) {
-		VALUE pat;
-		VALUE dst;
-		static const char rsrc[] =
-		    "(?<!\\\\)((?:\\\\\\\\)*)\\\\([ghijklmopquyEFHIJKLNOPQRSTUVXY])";
-		pat = rb_reg_new(rsrc, sizeof(rsrc)-1, 0);
-		dst = rb_usascii_str_new_cstr("\\1\\2");
-		rb_funcall(str, rb_intern("gsub!"), 2, pat, dst);
+		/* 1.8 compatibility; remove escapes undefined in 1.8 */
+		char *ptr = RSTRING_PTR(str), *dst = ptr, *src = ptr;
+		long len = RSTRING_LEN(str);
+		long bs = 0;
+		for (; len-- > 0; *dst++ = *src++) {
+		    switch (*src) {
+		      case '\\': bs++; break;
+		      case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+		      case 'm': case 'o': case 'p': case 'q': case 'u': case 'y':
+		      case 'E': case 'F': case 'H': case 'I': case 'J': case 'K':
+		      case 'L': case 'N': case 'O': case 'P': case 'Q': case 'R':
+		      case 'S': case 'T': case 'U': case 'V': case 'X': case 'Y':
+			if (bs & 1) --dst;
+		      default: bs = 0; break;
+		    }
+		}
+		rb_str_set_len(str, dst - ptr);
 	    }
 	    v = r_entry(rb_reg_new_str(str, options), arg);
 	    v = r_leave(v, arg);

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

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