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

ruby-changes:29677

From: naruse <ko1@a...>
Date: Mon, 1 Jul 2013 23:30:26 +0900 (JST)
Subject: [ruby-changes:29677] naruse:r41729 (trunk): Revert r41728

naruse	2013-07-01 23:30:04 +0900 (Mon, 01 Jul 2013)

  New Revision: 41729

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

  Log:
    Revert r41728
    
    * string.c (rb_str_inspect): use encoding index macros in encdb.h.
    
    It breaks build because encdb.h requires miniruby and modified
    miniruby requires encdb.h.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41728)
+++ ChangeLog	(revision 41729)
@@ -1,9 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Mon Jul  1 23:08:48 2013  NARUSE, Yui  <naruse@r...>
-
-	* string.c (rb_str_inspect): use encoding index macros in encdb.h.
-
-	* string.c (str_scrub0): ditto.
-
 Mon Jul  1 23:07:38 2013  NARUSE, Yui  <naruse@r...>
 
 	* template/encdb.h.tmpl: define encoding index macros to use the index
Index: string.c
===================================================================
--- string.c	(revision 41728)
+++ string.c	(revision 41729)
@@ -29,14 +29,6 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L29
 #include <unistd.h>
 #endif
 
-#define ENC_REPLICATE(name, orig)
-#define ENC_ALIAS(name, orig)
-#define ENC_DUMMY(name)
-#define ENC_DEFINE(name)
-#define ENC_SET_BASE(name, orig)
-#define ENC_DUMMY_UNICODE(name)
-#include <encdb.h>
-
 #define STRING_ENUMERATORS_WANTARRAY 0 /* next major */
 
 #undef rb_str_new_cstr
@@ -4479,14 +4471,16 @@ VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L4471
 rb_str_inspect(VALUE str)
 {
     rb_encoding *enc = STR_ENC_GET(str);
-    int encidx = rb_enc_to_index(enc);
     const char *p, *pend, *prev;
     char buf[CHAR_ESC_LEN + 1];
     VALUE result = rb_str_buf_new(0);
     rb_encoding *resenc = rb_default_internal_encoding();
     int unicode_p = rb_enc_unicode_p(enc);
     int asciicompat = rb_enc_asciicompat(enc);
+    static rb_encoding *utf16, *utf32;
 
+    if (!utf16) utf16 = rb_enc_find("UTF-16");
+    if (!utf32) utf32 = rb_enc_find("UTF-32");
     if (resenc == NULL) resenc = rb_default_external_encoding();
     if (!rb_enc_asciicompat(resenc)) resenc = rb_usascii_encoding();
     rb_enc_associate(result, resenc);
@@ -4494,7 +4488,7 @@ rb_str_inspect(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L4488
 
     p = RSTRING_PTR(str); pend = RSTRING_END(str);
     prev = p;
-    if (encidx == ENCIDX_UTF_16) {
+    if (enc == utf16) {
 	const unsigned char *q = (const unsigned char *)p;
 	if (q[0] == 0xFE && q[1] == 0xFF)
 	    enc = rb_enc_find("UTF-16BE");
@@ -4503,7 +4497,7 @@ rb_str_inspect(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L4497
 	else
 	    unicode_p = 0;
     }
-    else if (encidx == ENCIDX_UTF_32) {
+    else if (enc == utf32) {
 	const unsigned char *q = (const unsigned char *)p;
 	if (q[0] == 0 && q[1] == 0 && q[2] == 0xFE && q[3] == 0xFF)
 	    enc = rb_enc_find("UTF-32BE");
@@ -7750,7 +7744,6 @@ str_scrub0(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L7744
 {
     int cr = ENC_CODERANGE(str);
     rb_encoding *enc;
-    int encidx;
     VALUE repl;
 
     if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
@@ -7765,7 +7758,6 @@ str_scrub0(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L7758
     if (rb_enc_dummy_p(enc)) {
 	return Qnil;
     }
-    encidx = rb_enc_to_index(enc);
 
 #define DEFAULT_REPLACE_CHAR(str) do { \
 	static const char replace[sizeof(str)-1] = str; \
@@ -7790,7 +7782,7 @@ str_scrub0(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L7782
 	    replen = RSTRING_LEN(repl);
 	    rep7bit_p = (ENC_CODERANGE(repl) == ENC_CODERANGE_7BIT);
 	}
-	else if (encidx == rb_utf8_encindex()) {
+	else if (enc == rb_utf8_encoding()) {
 	    DEFAULT_REPLACE_CHAR("\xEF\xBF\xBD");
 	    rep7bit_p = FALSE;
 	}
@@ -7896,20 +7888,30 @@ str_scrub0(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L7888
 	const char *rep;
 	long replen;
 	long mbminlen = rb_enc_mbminlen(enc);
+	static rb_encoding *utf16be;
+	static rb_encoding *utf16le;
+	static rb_encoding *utf32be;
+	static rb_encoding *utf32le;
+	if (!utf16be) {
+	    utf16be = rb_enc_find("UTF-16BE");
+	    utf16le = rb_enc_find("UTF-16LE");
+	    utf32be = rb_enc_find("UTF-32BE");
+	    utf32le = rb_enc_find("UTF-32LE");
+	}
 	if (!NIL_P(repl)) {
 	    rep = RSTRING_PTR(repl);
 	    replen = RSTRING_LEN(repl);
 	}
-	else if (encidx == ENCIDX_UTF_16BE) {
+	else if (enc == utf16be) {
 	    DEFAULT_REPLACE_CHAR("\xFF\xFD");
 	}
-	else if (encidx == ENCIDX_UTF_16LE) {
+	else if (enc == utf16le) {
 	    DEFAULT_REPLACE_CHAR("\xFD\xFF");
 	}
-	else if (encidx == ENCIDX_UTF_32BE) {
+	else if (enc == utf32be) {
 	    DEFAULT_REPLACE_CHAR("\x00\x00\xFF\xFD");
 	}
-	else if (encidx == ENCIDX_UTF_32LE) {
+	else if (enc == utf32le) {
 	    DEFAULT_REPLACE_CHAR("\xFD\xFF\x00\x00");
 	}
 	else {

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

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