# \[ruby-core:16238\]$B$N8!\>Z(B

**URL:** <https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823>\
**Category:** Development\
**Created:** [April 25, 2008, 11:13am UTC](https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823 "2008-04-25T11:13:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 25, 2008, 11:13am UTC](https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823/1 "2008-04-25T11:13:09Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

e$B%U%i%s%9HG%Q%C%A%b%s%9%?!\<$G$"$k$H$3$m$Ne(BGuy Decouxe$B$K$h$k%Q%Ce(B  
e$B%Ae(B[ruby-core:16238]e$B$re(B1.8.7e$B$K\<h$j9~$\_$?$$$s$G$9$,!"$3$l$N%A%’%Ce(B  
e$B%/$r9T$&;~4V$N$"$k?M$O$$$^$9$+!)e(B

e$B;d\<+?H$Oe(B1.8.7e$B$K4V$K9g$&$h$&$K;~4V$,\<h$l$k\<+?.$,$"$j$^$;$s!#e(B

---

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 26, 2008, 1:02pm UTC](https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823/2 "2008-04-26T13:02:15Z")

</div>

At Fri, 25 Apr 2008 22:11:27 +0900,  
I wrote:

> ã„ã„ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“ã€‚  
> ã€€ruby\_1\_8 ã®æ–¹ã« commit ã—ã¾ã—ãŸã€‚

ã€€ã—ã°ã‚‰ããƒ†ã‚¹ãƒˆã—ã¦ã¿ã¦ ruby\_1\_8\_7 ã«ã‚‚é©ç”¨ã—ã€ preview3 ã«  
å…¥ã‚Œã‚‹ã¤ã‚‚ã‚Šã§ã™ã€‚

---

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 25, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823/3 "2008-04-25T15:11:56Z")

</div>

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)

- VALUE self;
- VALUE klass;
- VALUE cref;  
+{
- VALUE clone;
- struct METHOD \*orig, \*data;
- 
- Data\_Get\_Struct(self, struct METHOD, orig);
- clone = Data\_Make\_Struct(CLASS\_OF(self),struct METHOD, bm\_mark,  
free, data);
- \*data = \*orig;
- data-\>rklass = klass;
- if (data-\>body-\>nd\_rval) {
- NODE \*tmp = NEW\_NODE(nd\_type(data-\>body-\>u2.node), cref,
- 

```
      data->body->u2.node->u2.node,

```

- 

```
      data->body->u2.node->u3.node);

```

- data-\>body = NEW\_NODE(nd\_type(data-\>body), data-\>body-\>u1.node, tmp,
- 

```
       data->body->u3.node);

```

- }
- return clone;  
+}
- 

/\*

- call-seq:
- 

```
meth.call(args, ...) => obj

```

# Index: class.c

— class.c (revision 16192)  
+++ class.c (working copy)  
@@ -51,6 +51,7 @@  
struct clone\_method\_data {  
st\_table \*tbl;  
VALUE klass;

- VALUE cref;  
};

static int  
@@ -61,16 +62,33 @@  
{  
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);

- 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;

- 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;

---

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 26, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/ruby-core-16238-b-n8-z-b/135823/4 "2008-04-26T16:07:30Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:34514] Re: [ruby-core:16238]e$B$N8!\>Ze(B”  
on Fri, 25 Apr 2008 22:11:27 +0900, “Akinori MUSHA”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|\> e$B;d\<+?H$Oe(B1.8.7e$B$K4V$K9g$&$h$&$K;~4V$,\<h$l$k\<+?.$,$“$j$^$;$s!#e(B  
|  
|e$B!!\<c43%9%?%$%k$r=$@5$7$D$D!”:9J,$,$o$+$j$d$9$$$h$&$K$9$k$H$3$s$Je(B  
|e$B46$8$G$9!#e(BBASE e$B$H$N:9J,$h$j$b!"E,MQ8e$Ke(B PREV e$B$H$N:9J,$r8+$?J}$,e(B  
|e$B$$$$$+$b$7$l$^$;$s!#e(B  
|  
|e$B!!e(BBoundMethod, UnboundMethod e$B$NBP1~!"e(B cref e$B$NEAC#!"e(B klass e$B$N=$@5!"e(B  
|e$B$G$7$g$&$+$M!#Bg\>fIW$=$&$G$9$,!"e(B(e$B$3$3$GK\2H%b%s%9%?!\<$de(BRHGe$BFI=q2qe(B  
|e$B%a%s%P!\<$,EP\>le(B)

e$B$A$g$C$H8+$F$\_$^$7$?!#Bg\>fIW$=$&$J$N$G\<h$j9~$s$G$$$?$@$1$^$;e(B  
e$B$s$G$7$g$&$+!#e(B
