From 7558136984c6c8d57f30831f1f328e7f5b3f99c9 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Oct 2008 09:57:38 +0000 Subject: [PATCH] * marshal.c (marshal_dump): initializes dump_arg before any funcall. [ruby-dev:36648] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ marshal.c | 36 +++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b41bda559..84a0fd8649 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Oct 1 18:57:31 2008 Nobuyoshi Nakada + + * marshal.c (marshal_dump): initializes dump_arg before any funcall. + [ruby-dev:36648] + Wed Oct 1 00:54:32 2008 Yukihiro Matsumoto * string.c (rb_str_split_m): should use rb_str_subseq() which use diff --git a/marshal.c b/marshal.c index 352ab443e9..557bb353e4 100644 --- a/marshal.c +++ b/marshal.c @@ -865,29 +865,30 @@ marshal_dump(int argc, VALUE *argv) else port = a1; } arg.dest = 0; - if (!NIL_P(port)) { - if (!rb_respond_to(port, s_write)) { - type_error: - rb_raise(rb_eTypeError, "instance of IO needed"); - } - arg.str = rb_str_buf_new(0); - arg.dest = port; - if (rb_respond_to(port, s_binmode)) { - rb_funcall2(port, s_binmode, 0, 0); - } - } - else { - port = rb_str_buf_new(0); - arg.str = port; - } - arg.symbols = st_init_numtable(); arg.data = st_init_numtable(); arg.taint = Qfalse; arg.untrust = Qfalse; arg.compat_tbl = st_init_numtable(); - arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg); arg.encodings = 0; + arg.str = rb_str_buf_new(0); + RBASIC(arg.str)->klass = 0; + arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg); + if (!NIL_P(port)) { + if (!rb_respond_to(port, s_write)) { + type_error: + rb_raise(rb_eTypeError, "instance of IO needed"); + } + arg.dest = port; + if (rb_respond_to(port, s_binmode)) { + rb_funcall2(port, s_binmode, 0, 0); + check_dump_arg(&arg, s_dump_data); + } + } + else { + port = arg.str; + } + c_arg.obj = obj; c_arg.arg = &arg; c_arg.limit = limit; @@ -896,6 +897,7 @@ marshal_dump(int argc, VALUE *argv) w_byte(MARSHAL_MINOR, &arg); rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg); + RBASIC(arg.str)->klass = rb_cString; return port; }