summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:21:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:21:32 +0000
commitf2dc5f15bab9b6200b914755c40655b064153d43 (patch)
treea57348f4b33b841f5c3b3c38282ffbb8a7402df7
parent240f3056aa0e095a6b03d5763c2775e97b4ee7d3 (diff)
encoding.c: terminator in enc_set_index
* encoding.c (enc_set_index): deal with terminator so that rb_enc_set_index also works. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--encoding.c20
2 files changed, 15 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index a4c7eede0e3..8ac0b358121 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Jul 15 02:21:29 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@fsij.org>
* configure.in: Check __builtin_popcountl, __builtin_bswap32 and
diff --git a/encoding.c b/encoding.c
index 6e0777d24c9..244ef05f5e1 100644
--- a/encoding.c
+++ b/encoding.c
@@ -755,8 +755,14 @@ rb_enc_get_index(VALUE obj)
}
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
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 idx)
!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;
}