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

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

    m = rb_intern(method);

  • 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”,

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.
[email protected] 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