# \[ruby-Bugs:19377\] Marshall.load of serialized instance of singleton class returns new instance

**URL:** <https://www.ruby-forum.com/t/ruby-bugs-19377-marshall-load-of-serialized-instance-of-singleton-class-returns-new-instance/137441>\
**Category:** Development\
**Created:** [May 13, 2008, 7:07am UTC](https://www.ruby-forum.com/t/ruby-bugs-19377-marshall-load-of-serialized-instance-of-singleton-class-returns-new-instance/137441 "2008-05-13T07:07:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [May 13, 2008, 7:07am UTC](https://www.ruby-forum.com/t/ruby-bugs-19377-marshall-load-of-serialized-instance-of-singleton-class-returns-new-instance/137441/1 "2008-05-13T07:07:38Z")

</div>

e$B$J$+$@$G$9!#e(B

# e$B=P$7$?$D$b$j$GK:$l$F$?$h$&$G$9!#e(B

[ruby-Bugs:19377]e$B$NLdBj$O!“e(BSingletonClassMethods#\_loade$B$,e(Bprivate  
e$B$K$J$C$F$$$k$N$Ge(Brb\_respond\_toe$B$,e(Bfalsee$B$rJV$9$H$$$&$3$H$,860x$G$9!#e(B  
singleton.rbe$B$+$ie(Bprivatee$B$r\<h$j=|$/$N$G$b$$$$$N$G$9$,!”\<B:]$K8F$Se(B  
e$B=P$9e(Brb\_funcalle$B$Oe(Bprivatee$B$G$bL54X78$K8F$S=P$7$F$7$^$&$o$1$J$N$G!"e(B  
privatee$B%a%=%C%I$bC5$9$Y$-$J$s$G$O$J$$$G$7$g$&$+!#e(B

e$B$=$b$=$b!"$3$&$$$C$?FbItE\*$K8F$P$l$k%a%=%C%I$N2D;k@-$O!"$I$&$9$Ye(B  
e$B$-$J$N$G$7$g$&$+!#e(B

# Index: marshal.c

— marshal.c (revision 15931)  
+++ marshal.c (working copy)  
@@ -590,5 +590,5 @@ w\_object(VALUE obj, struct dump\_arg \*arg  
}

- if (rb\_respond\_to(obj, s\_mdump)) {

- if (rb\_obj\_respond\_to(obj, s\_mdump, Qtrue)) {  
VALUE v;

@@ -599,5 +599,5 @@ w\_object(VALUE obj, struct dump\_arg \*arg  
return;  
}

- if (rb\_respond\_to(obj, s\_dump)) {

- if (rb\_obj\_respond\_to(obj, s\_dump, Qtrue)) {  
VALUE v;  
st\_table \*ivtbl2 = 0;  
@@ -746,5 +746,5 @@ w\_object(VALUE obj, struct dump\_arg \*arg  
VALUE v;

- if (!rb\_respond\_to(obj, s\_dump\_data)) {

- if (!rb\_obj\_respond\_to(obj, s\_dump\_data, Qtrue)) {  
rb\_raise(rb\_eTypeError,  
“no marshal\_dump is defined for class %s”,  
@@ -841,5 +841,5 @@ marshal\_dump(int argc, VALUE \*argv)  
arg.dest = 0;  
if (!NIL\_P(port)) {

- if (!rb\_respond\_to(port, s\_write)) {

- if (!rb\_obj\_respond\_to(port, s\_write, Qtrue)) {  
type\_error:  
rb\_raise(rb\_eTypeError, “instance of IO needed”);  
@@ -847,5 +847,5 @@ marshal\_dump(int argc, VALUE \*argv)  
arg.str = rb\_str\_buf\_new(0);  
arg.dest = port;

- if (rb\_respond\_to(port, s\_binmode)) {

- if (rb\_obj\_respond\_to(port, s\_binmode, Qtrue)) {  
rb\_funcall2(port, s\_binmode, 0, 0);  
}  
@@ -1392,5 +1392,5 @@ r\_object0(struct load\_arg \*arg, int \*ivp  
VALUE data;

- 

```
 if (!rb_respond_to(klass, s_load)) {

```

- 

```
 if (!rb_obj_respond_to(klass, s_load, Qtrue)) {

```

rb\_raise(rb\_eTypeError, “class %s needs to have method `\_load’”,  
rb\_class2name(klass));  
@@ -1419,5 +1419,5 @@ r\_object0(struct load\_arg \*arg, int \*ivp  
}  
}

- 

```
 if (!rb_respond_to(v, s_mload)) {

```

- 

```
 if (!rb_obj_respond_to(v, s_mload, Qtrue)) {

```

rb\_raise(rb\_eTypeError, “instance of %s needs to have method  
`marshal\_load’”,  
rb\_class2name(klass));  
@@ -1445,5 +1445,5 @@ r\_object0(struct load\_arg \*arg, int \*ivp  
{  
VALUE klass = path2class(r\_unique(arg));

- 

```
      if (rb_respond_to(klass, s_alloc)) {

```

- 

```
      if (rb_obj_respond_to(klass, s_alloc, Qtrue)) {
    static int warn = Qtrue;
    if (warn) {

```

@@ -1460,5 +1460,5 @@ r\_object0(struct load\_arg \*arg, int \*ivp  
}  
v = r\_entry(v, arg);

- 

```
      if (!rb_respond_to(v, s_load_data)) {

```

- 

```
      if (!rb_obj_respond_to(v, s_load_data, Qtrue)) {
          rb_raise(rb_eTypeError,
                   "class %s needs to have instance method 

```

`\_load\_data’",  
@@ -1558,10 +1558,11 @@ marshal\_load(int argc, VALUE \*argv)

```
 rb_scan_args(argc, argv, "11", &port, &proc);

```

- if (rb\_respond\_to(port, rb\_intern(“to\_str”))) {

- v = rb\_check\_string\_type(port);
- if (!NIL\_P(v)) {  
arg.taint = OBJ\_TAINTED(port); /\* original taintedness \*/

- StringValue(port); /\* possible conversion \*/

- port = v;  
}

- else if (rb\_respond\_to(port, s\_getbyte) && rb\_respond\_to(port,  
s\_read)) {
- if (rb\_respond\_to(port, s\_binmode)) {

- else if (rb\_obj\_respond\_to(port, s\_getbyte, Qtrue) &&  
rb\_obj\_respond\_to(port, s\_read, Qtrue)) {

- if (rb\_obj\_respond\_to(port, s\_binmode, Qtrue)) {  
rb\_funcall2(port, s\_binmode, 0, 0);  
}  
Index: object.c  
===================================================================  
— object.c (revision 15931)  
+++ object.c (working copy)  
@@ -1893,5 +1893,5 @@ convert\_type(VALUE val, const char \*tnam

- if (!rb\_respond\_to(val, m)) {

- if (!rb\_obj\_respond\_to(val, m, Qtrue)) {  
if (raise) {  
rb\_raise(rb\_eTypeError, “can’t convert %s into %s”,

---

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [May 28, 2008, 2:06am UTC](https://www.ruby-forum.com/t/ruby-bugs-19377-marshall-load-of-serialized-instance-of-singleton-class-returns-new-instance/137441/2 "2008-05-28T02:06:11Z")

</div>

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

In message “Re: [ruby-dev:34671] [ruby-Bugs:19377] Marshall.load of  
serialized instance of singleton class returns new instance”  
on Tue, 13 May 2008 14:07:06 +0900, Nobuyoshi N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|# e$B=P$7$?$D$b$j$GK:$l$F$?$h$&$G$9!#e(B

e$B$5$i$K;d$b8+Mn$H$7$F$$$?$h$&$G$9!#e(B

|[ruby-Bugs:19377]e$B$NLdBj$O!“e(BSingletonClassMethods#\_loade$B$,e(Bprivate  
|e$B$K$J$C$F$$$k$N$Ge(Brb\_respond\_toe$B$,e(Bfalsee$B$rJV$9$H$$$&$3$H$,860x$G$9!#e(B  
|singleton.rbe$B$+$ie(Bprivatee$B$r\<h$j=|$/$N$G$b$$$$$N$G$9$,!”\<B:]$K8F$Se(B  
|e$B=P$9e(Brb\_funcalle$B$Oe(Bprivatee$B$G$bL54X78$K8F$S=P$7$F$7$^$&$o$1$J$N$G!"e(B  
|privatee$B%a%=%C%I$bC5$9$Y$-$J$s$G$O$J$$$G$7$g$&$+!#e(B

e$B$=$&$G$9$M!#%3%\_%C%H$7$F$/$@$5$$!#e(B

|e$B$=$b$=$b!“$3$&$$$C$?FbItE\*$K8F$P$l$k%a%=%C%I$N2D;k@-$O!”$I$&$9$Ye(B  
|e$B$-$J$N$G$7$g$&$+!#e(B

e$BK\Mh$Oe(Bpublice$B$G$"$k$Y$-$G$7$g$&$M!#e(Bprivatee$B$b\<h$j=|$-$^$7$g$&!#e(B
