From 2d1d6c470563375ec4d71353fdf8de3aa4c40ef2 Mon Sep 17 00:00:00 2001
From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Wed, 17 Oct 2007 02:30:57 +0000
Subject: [PATCH] * encoding.c (rb_enc_from_encoding, rb_enc_register):
 associate index   to self.

* encoding.c (enc_capable): Encoding objects are encoding capable.

* re.c (rb_reg_s_union): check if encoding matching by exact encoding
  objects.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 ChangeLog  | 10 ++++++++++
 encoding.c | 14 +++++++++++---
 re.c       |  6 +++---
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e72f23e62e..b646fa33b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Oct 17 11:30:55 2007  Nobuyoshi Nakada  <nobu@ruby-lang.org>
+
+	* encoding.c (rb_enc_from_encoding, rb_enc_register): associate index
+	  to self.
+
+	* encoding.c (enc_capable): Encoding objects are encoding capable.
+
+	* re.c (rb_reg_s_union): check if encoding matching by exact encoding
+	  objects.
+
 Wed Oct 17 06:18:06 2007  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 
 	* encoding.c (rb_enc_alias, rb_enc_find_index): changed
diff --git a/encoding.c b/encoding.c
index e2d3cdd8da..289fba72f9 100644
--- a/encoding.c
+++ b/encoding.c
@@ -45,9 +45,14 @@ enc_new(rb_encoding *encoding)
 }
 
 VALUE
-rb_enc_from_encoding(rb_encoding *enc)
+rb_enc_from_encoding(rb_encoding *encoding)
 {
-    return enc_initialized_p(enc) ? ENC_FROM_ENCODING(enc) : enc_new(enc);
+    VALUE enc;
+    if (enc_initialized_p(encoding))
+	return ENC_FROM_ENCODING(encoding);
+    enc = enc_new(encoding);
+    rb_enc_associate(enc, encoding);
+    return enc;
 }
 
 static rb_encoding *
@@ -136,7 +141,8 @@ rb_enc_register(const char *name, rb_encoding *encoding)
     encoding = ent->enc;
     encoding->name = name;
     if (rb_cEncoding) {
-	enc_new(encoding);
+	VALUE enc = enc_new(encoding);
+	rb_enc_associate_index(enc, newsize);
     }
     else {
 	encoding->auxiliary_data = ENC_UNINITIALIZED;
@@ -229,6 +235,8 @@ enc_capable(VALUE obj)
       case T_REGEXP:
       case T_FILE:
 	return Qtrue;
+      case T_DATA:
+	if (RDATA(obj)->dmark == enc_mark) return Qtrue;
       default:
 	return Qfalse;
     }
diff --git a/re.c b/re.c
index 605c40f176..c5679718c4 100644
--- a/re.c
+++ b/re.c
@@ -1783,7 +1783,7 @@ rb_reg_s_union(VALUE self, VALUE args0)
     else {
 	int i;
 	VALUE source = rb_str_buf_new(0);
-	VALUE tmp = rb_ary_entry(args0, 0);
+	VALUE enc0 = rb_obj_encoding(rb_ary_entry(args0, 0));
 
 	for (i = 0; i < argc; i++) {
 	    volatile VALUE v;
@@ -1792,12 +1792,12 @@ rb_reg_s_union(VALUE self, VALUE args0)
 		rb_str_buf_cat2(source, "|");
 	    v = rb_check_regexp_type(e);
 	    if (!NIL_P(v)) {
-		rb_enc_check(tmp, v);
+		rb_enc_check(enc0, v);
 		v = rb_reg_to_s(v);
 	    }
 	    else {
-		rb_enc_check(tmp, e);
 		v = rb_reg_s_quote(Qnil, e);
+		rb_enc_check(enc0, rb_obj_encoding(v));
 	    }
 	    rb_str_append(source, v);
 	}