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

ruby-changes:29912

From: nobu <ko1@a...>
Date: Mon, 15 Jul 2013 02:21:43 +0900 (JST)
Subject: [ruby-changes:29912] nobu:r41964 (trunk): encoding.c: terminator in enc_set_index

nobu	2013-07-15 02:21:32 +0900 (Mon, 15 Jul 2013)

  New Revision: 41964

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

  Log:
    encoding.c: terminator in enc_set_index
    
    * encoding.c (enc_set_index): deal with terminator so that
      rb_enc_set_index also works.

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 41963)
+++ encoding.c	(revision 41964)
@@ -755,8 +755,14 @@ rb_enc_get_index(VALUE obj) https://github.com/ruby/ruby/blob/trunk/encoding.c#L755
 }
 
 static void
-enc_set_index(VALUE obj, int idx)
+enc_set_index(VALUE obj, int oldidx, int idx, rb_encoding *enc)
 {
+    int termlen = rb_enc_mbminlen(enc);
+    int oldtermlen = rb_enc_mbminlen(rb_enc_from_index(oldidx));
+
+    if (oldtermlen < termlen && RB_TYPE_P(obj, T_STRING)) {
+	rb_str_fill_terminator(obj, termlen);
+    }
     if (idx < ENCODING_INLINE_MAX) {
 	ENCODING_SET_INLINED(obj, idx);
 	return;
@@ -769,15 +775,14 @@ void https://github.com/ruby/ruby/blob/trunk/encoding.c#L775
 rb_enc_set_index(VALUE obj, int idx)
 {
     rb_check_frozen(obj);
-    must_encindex(idx);
-    enc_set_index(obj, idx);
+    enc_set_index(obj, ENCODING_GET(obj), idx, must_encindex(idx));
 }
 
 VALUE
 rb_enc_associate_index(VALUE obj, int idx)
 {
     rb_encoding *enc;
-    int oldidx, oldtermlen, termlen;
+    int oldidx;
 
 /*    enc_check_capable(obj);*/
     rb_check_frozen(obj);
@@ -792,12 +797,7 @@ rb_enc_associate_index(VALUE obj, int id https://github.com/ruby/ruby/blob/trunk/encoding.c#L797
 	!rb_enc_asciicompat(enc)) {
 	ENC_CODERANGE_CLEAR(obj);
     }
-    termlen = rb_enc_mbminlen(enc);
-    oldtermlen = rb_enc_mbminlen(rb_enc_from_index(oldidx));
-    if (oldtermlen < termlen && RB_TYPE_P(obj, T_STRING)) {
-	rb_str_fill_terminator(obj, termlen);
-    }
-    enc_set_index(obj, idx);
+    enc_set_index(obj, oldidx, idx, enc);
     return obj;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41963)
+++ ChangeLog	(revision 41964)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 15 02:21:29 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* encoding.c (enc_set_index): deal with terminator so that
+	  rb_enc_set_index also works.
+
 Sun Jul 14 23:21:47 2013  Tanaka Akira  <akr@f...>
 
 	* configure.in: Check __builtin_popcountl, __builtin_bswap32 and

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

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