summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 12:05:53 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 12:05:53 +0000
commit82f62ff041ddc665b102fb6fe9b855d82e2f6903 (patch)
tree2aa892d46d0601982441eb78174de82600e63b3c
parentc4551f2393a1ccb3b9ffbc3d75069ac78a8b762a (diff)
merge revision(s) 15856:
* class.c (clone_method): should copy cref as well. [ruby-core:15833] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@17220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--class.c50
-rw-r--r--version.h2
3 files changed, 46 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c8690a..7808220 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -82,6 +82,11 @@ Sat Jun 14 16:12:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
Fri Jun 13 13:10:12 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/dl/ptr.c (dlmem_each_i): typo fixed. a patch from IKOMA
+Sun Jun 15 21:01:56 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * class.c (clone_method): should copy cref as well.
+ [ruby-core:15833]
+
Yoshiki <ikoma@mb.i-chubu.ne.jp> in [ruby-dev:33776].
Fri Jun 13 12:10:58 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
diff --git a/class.c b/class.c
index 9e41b1e..ca2516d 100644
--- a/class.c
+++ b/class.c
@@ -48,13 +48,26 @@ rb_class_new(super)
return rb_class_boot(super);
}
+struct clone_method_data {
+ st_table *tbl;
+ VALUE klass;
+};
+
static int
-clone_method(mid, body, tbl)
+clone_method(mid, body, data)
ID mid;
NODE *body;
- st_table *tbl;
+ struct clone_method_data *data;
{
- st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
+ NODE *fbody = body->nd_body;
+
+ if (fbody && nd_type(fbody) == NODE_SCOPE) {
+ VALUE cref = data->klass ?
+ (VALUE)NEW_NODE(NODE_CREF,data->klass,0,fbody->nd_rval) :
+ fbody->nd_rval;
+ fbody = NEW_NODE(NODE_SCOPE, fbody->nd_tbl, cref, fbody->nd_next);
+ }
+ st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
return ST_CONTINUE;
}
@@ -65,7 +78,8 @@ rb_mod_init_copy(clone, orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = rb_singleton_class_clone(orig);
+ RBASIC(clone)->klass = RBASIC(orig)->klass;
+ RBASIC(clone)->klass = rb_singleton_class_clone(clone);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -78,9 +92,12 @@ rb_mod_init_copy(clone, orig)
st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
}
if (RCLASS(orig)->m_tbl) {
- RCLASS(clone)->m_tbl = st_init_numtable();
- st_foreach(RCLASS(orig)->m_tbl, clone_method,
- (st_data_t)RCLASS(clone)->m_tbl);
+ struct clone_method_data data;
+
+ data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
+ data.klass = (VALUE)clone;
+
+ st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
}
return clone;
@@ -126,9 +143,22 @@ rb_singleton_class_clone(obj)
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
}
- clone->m_tbl = st_init_numtable();
- st_foreach(RCLASS(klass)->m_tbl, clone_method,
- (st_data_t)clone->m_tbl);
+ {
+ struct clone_method_data data;
+
+ data.tbl = clone->m_tbl = st_init_numtable();
+ switch (TYPE(obj)) {
+ case T_CLASS:
+ case T_MODULE:
+ data.klass = obj;
+ break;
+ default:
+ data.klass = 0;
+ break;
+ }
+
+ st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
+ }
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
diff --git a/version.h b/version.h
index b528ba0..113b1b9 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-15"
#define RUBY_VERSION_CODE 185
#define RUBY_RELEASE_CODE 20080615
-#define RUBY_PATCHLEVEL 188
+#define RUBY_PATCHLEVEL 189
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8