At Fri, 25 Apr 2008 18:12:39 +0900,
matz wrote:
フランス版パッãƒãƒ¢ãƒ³ã‚¹ã‚¿ãƒ¼ã§ã‚ã‚‹ã¨ã“ã‚ã®Guy Decouxã«ã‚ˆã‚‹ãƒ‘ッ
ãƒ[ruby-core:16238]ã‚’1.8.7ã«å–ã‚Šè¾¼ã¿ãŸã„ã‚“ã§ã™ãŒã€ã“ã‚Œã®ãƒã‚§ãƒƒ
クを行ã†æ™‚é–“ã®ã‚る人ã¯ã„ã¾ã™ã‹ï¼Ÿ
ç§è‡ªèº«ã¯1.8.7ã«é–“ã«åˆã†ã‚ˆã†ã«æ™‚é–“ãŒå–れる自信ãŒã‚ã‚Šã¾ã›ã‚“。
 若干スタイルを修æ£ã—ã¤ã¤ã€å·®åˆ†ãŒã‚ã‹ã‚Šã‚„ã™ã„よã†ã«ã™ã‚‹ã¨ã“ã‚“ãª
æ„Ÿã˜ã§ã™ã€‚BASE ã¨ã®å·®åˆ†ã‚ˆã‚Šã‚‚ã€é©ç”¨å¾Œã« PREV ã¨ã®å·®åˆ†ã‚’見ãŸæ–¹ãŒ
ã„ã„ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“。
 BoundMethod, UnboundMethod ã®å¯¾å¿œã€ cref ã®ä¼é”〠klass ã®ä¿®æ£ã€
ã§ã—ょã†ã‹ã。大丈夫ãã†ã§ã™ãŒã€(ã“ã“ã§æœ¬å®¶ãƒ¢ãƒ³ã‚¹ã‚¿ãƒ¼ã‚„RHGèªæ›¸ä¼š
メンãƒãƒ¼ãŒç™»å ´)
Index: intern.h
— intern.h (revision 16192)
+++ intern.h (working copy)
@@ -193,6 +193,8 @@
void rb_obj_call_init _((VALUE, int, VALUE*));
VALUE rb_class_new_instance _((int, VALUE*, VALUE));
VALUE rb_block_proc _((void));
+VALUE rb_block_dup _((VALUE, VALUE, VALUE));
+VALUE rb_method_dup _((VALUE, VALUE, VALUE));
VALUE rb_f_lambda _((void));
VALUE rb_proc_call _((VALUE, VALUE));
VALUE rb_obj_method _((VALUE, VALUE));
Index: eval.c
— eval.c (revision 16192)
+++ eval.c (working copy)
@@ -8414,6 +8414,19 @@
return bind;
}
+VALUE
+rb_block_dup(self, klass, cref)
- VALUE self, klass, cref;
+{
- struct BLOCK *block;
- VALUE obj = proc_dup(self);
- Data_Get_Struct(obj, struct BLOCK, block);
- block->klass = klass;
- block->cref = NEW_NODE(nd_type(block->cref), cref,
block->cref->u2.node,
-
block->cref->u3.node);
- return obj;
+}
-
/*
- call-seq:
-
binding -> a_binding
@@ -9340,6 +9353,29 @@
return clone;
}
+VALUE
+rb_method_dup(self, klass, cref)
/*
Index: class.c
— class.c (revision 16192)
+++ class.c (working copy)
@@ -51,6 +51,7 @@
struct clone_method_data {
st_table *tbl;
VALUE klass;
static int
@@ -61,16 +62,33 @@
{
NODE *fbody = body->nd_body;
- if (fbody && data->cref) {
- VALUE body;
-
- switch (nd_type(fbody)) {
- case NODE_SCOPE:
-
if (fbody->nd_rval) {
- NODE *tmp = NEW_NODE(nd_type(fbody->u2.node), data->cref,
-
fbody->u2.node->u2.node, fbody->u2.node->u3.node);
- fbody = NEW_NODE(nd_type(fbody), fbody->u1.node, tmp,
fbody->u3.node);
-
}
-
break;
- case NODE_BMETHOD:
-
body = rb_block_dup(fbody->nd_cval, data->klass, data->cref);
-
fbody = NEW_BMETHOD(body);
-
break;
- case NODE_DMETHOD:
-
body = rb_method_dup(fbody->nd_cval, data->klass, data->cref);
-
fbody = NEW_DMETHOD(body);
-
break;
- }
}
st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody,
body->nd_noex));
return ST_CONTINUE;
}
+static VALUE singleton_class_clone_int _((VALUE, VALUE));
+
/* :nodoc: */
VALUE
rb_mod_init_copy(clone, orig)
@@ -78,8 +96,7 @@
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = RBASIC(orig)->klass;
- RBASIC(clone)->klass = rb_singleton_class_clone(clone);
- RBASIC(clone)->klass = singleton_class_clone_int(orig, clone);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -94,9 +111,10 @@
if (RCLASS(orig)->m_tbl) {
struct clone_method_data data;
- data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
- data.klass = (VALUE)clone;
-
- RCLASS(clone)->m_tbl = st_init_numtable();
- data.tbl = RCLASS(clone)->m_tbl;
- data.klass = clone;
- data.cref = clone;
st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
}
@@ -117,15 +135,16 @@
return rb_mod_init_copy(clone, orig);
}
-VALUE
-rb_singleton_class_clone(obj)
- VALUE obj;
+static VALUE
+singleton_class_clone_int(obj, cref)
-
VALUE obj, cref;
{
VALUE klass = RBASIC(obj)->klass;
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
-
struct clone_method_data data;
/* copy singleton(unnamed) class */
NEWOBJ(clone, struct RClass);
OBJSETUP(clone, 0, RBASIC(klass)->flags);
@@ -143,28 +162,24 @@
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_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);
- }
- clone->m_tbl = st_init_numtable();
- data.tbl = clone->m_tbl;
- data.klass = (VALUE)clone;
- data.cref = cref;
- 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;
}
}
+VALUE
+rb_singleton_class_clone(obj)
- VALUE obj;
+{
- return singleton_class_clone_int(obj, 0);
+}
-
void
rb_singleton_class_attached(klass, obj)
VALUE klass, obj;