なかだです。

_dumpでインスタンス変数をつけたStringを返しても、_loadで渡され
るStringにはついて来ないようです。

  class Foo
    def _dump(lv)
      s = ""
      s.instance_eval { @a = 1 }
      s
    end
    def self._load(str)
      p str.instance_eval { @a }	# => nil
    end
  end

[ruby-list:38484]の線で行くと、こんな感じでしょうか。


* marshal.c (w_object): TYPE_IVAR and ivtbl have to correspond.

* marshal.c (w_object): dump ivtbl of _dump/marshal_dump instead of
  the object itself.  [ruby-list:38484]

* marshal.c (marshal_dump): uninitiliazed member.  [ruby-dev:21560]


Index: marshal.c =================================================================== RCS file: /cvs/ruby/src/ruby/marshal.c,v retrieving revision 1.104 diff -u -2 -p -r1.104 marshal.c --- marshal.c 9 Oct 2003 06:46:40 -0000 1.104 +++ marshal.c 9 Oct 2003 11:45:21 -0000 @@ -442,5 +442,5 @@ w_object(obj, arg, limit, weak) c_arg.weak = weak; - if (ivtbl = rb_generic_ivar_table(obj)) { + if (SPECIAL_CONST_P(obj) && (ivtbl = rb_generic_ivar_table(obj))) { w_byte(TYPE_IVAR, arg); } @@ -486,15 +486,8 @@ w_object(obj, arg, limit, weak) VALUE v; - if (TYPE(obj) == T_OBJECT) { - w_byte(TYPE_IVAR, arg); - ivtbl = ROBJECT(obj)->iv_tbl; - } v = rb_funcall(obj, s_mdump, 0, 0); w_byte(TYPE_USRMARSHAL, arg); w_unique(rb_class2name(CLASS_OF(obj)), arg); w_object(v, arg, limit, weak); - c_arg.weak = Qtrue; - ivtbl = rb_generic_ivar_table(v); - if (ivtbl) w_ivar(ivtbl, &c_arg); return; } @@ -506,12 +499,18 @@ w_object(obj, arg, limit, weak) rb_raise(rb_eTypeError, "_dump() must return string"); } + if (ivtbl = rb_generic_ivar_table(v)) { + w_byte(TYPE_IVAR, arg); + } w_class(TYPE_USERDEF, obj, arg); w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg); c_arg.weak = Qtrue; - ivtbl = rb_generic_ivar_table(v); if (ivtbl) w_ivar(ivtbl, &c_arg); return; } + if (ivtbl = rb_generic_ivar_table(obj)) { + w_byte(TYPE_IVAR, arg); + } + switch (BUILTIN_TYPE(obj)) { case T_CLASS: @@ -744,4 +743,5 @@ marshal_dump(argc, argv) c_arg.arg = &arg; c_arg.limit = limit; + c_arg.weak = Qfalse; w_byte(MARSHAL_MAJOR, &arg); @@ -1217,8 +1217,4 @@ r_object0(arg, proc, ivp) r_entry(v, arg); data = r_object(arg); - if (ivp) { - r_ivar(v, arg); - *ivp = Qfalse; - } rb_funcall(v, s_mload, 1, data); }
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦