ruby-changes:14778
From: nobu <ko1@a...>
Date: Thu, 11 Feb 2010 14:38:01 +0900 (JST)
Subject: [ruby-changes:14778] Ruby:r26639 (trunk): * marshal.c (r_object0): read sequentially since marshal source
nobu 2010-02-11 14:37:43 +0900 (Thu, 11 Feb 2010) New Revision: 26639 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26639 Log: * marshal.c (r_object0): read sequentially since marshal source may not be possible to rewind. [ruby-dev:40386] Modified files: trunk/ChangeLog trunk/marshal.c trunk/test/ruby/test_marshal.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 26638) +++ ChangeLog (revision 26639) @@ -1,3 +1,8 @@ +Thu Feb 11 14:37:39 2010 Nobuyoshi Nakada <nobu@r...> + + * marshal.c (r_object0): read sequentially since marshal source + may not be possible to rewind. [ruby-dev:40386] + Thu Feb 11 09:49:31 2010 Tanaka Akira <akr@f...> * lib/resolv.rb: fix [ruby-core:28144] reported by Hans de Graaff. Index: marshal.c =================================================================== --- marshal.c (revision 26638) +++ marshal.c (revision 26639) @@ -1258,7 +1258,7 @@ } static void -r_ivar(VALUE obj, struct load_arg *arg) +r_ivar(VALUE obj, int *has_encoding, struct load_arg *arg) { long len; @@ -1270,6 +1270,7 @@ int idx = id2encidx(id, val, arg); if (idx >= 0) { rb_enc_associate_index(obj, idx); + if (has_encoding) *has_encoding = TRUE; } else { rb_ivar_set(obj, id, val); @@ -1323,35 +1324,6 @@ return rb_obj_alloc(klass); } -static int -has_encoding(struct load_arg *arg) -{ - int res = FALSE; - long offset = arg->offset; - r_long(arg); - switch (r_byte(arg)) { - case TYPE_SYMBOL: - switch (r_byte(arg)) { - case 6: - if (r_byte(arg) == 'E') res = TRUE; - break; - case 13: - if (r_byte(arg) == 'e') res = TRUE; - break; - } - break; - case TYPE_SYMLINK: - { - ID id = r_symlink(arg); - if (id == rb_intern("E") || id == rb_id_encoding()) - res = TRUE; - } - break; - } - arg->offset = offset; - return res; -} - static VALUE r_object0(struct load_arg *arg, int *ivp, VALUE extmod) { @@ -1378,7 +1350,7 @@ int ivar = TRUE; v = r_object0(arg, &ivar, extmod); - if (ivar) r_ivar(v, arg); + if (ivar) r_ivar(v, NULL, arg); } break; @@ -1522,8 +1494,13 @@ { volatile VALUE str = r_bytes(arg); int options = r_byte(arg); + int has_encoding = FALSE; - if (!ivp || !has_encoding(arg)) { + if (ivp) { + r_ivar(str, &has_encoding, arg); + *ivp = FALSE; + } + if (!has_encoding) { VALUE pat; VALUE dst; static const char rsrc[] = @@ -1617,7 +1594,7 @@ } data = r_string(arg); if (ivp) { - r_ivar(data, arg); + r_ivar(data, NULL, arg); *ivp = FALSE; } v = rb_funcall(klass, s_load, 1, data); @@ -1659,7 +1636,7 @@ rb_raise(rb_eArgError, "dump format error"); } v = r_entry0(v, idx, arg); - r_ivar(v, arg); + r_ivar(v, NULL, arg); v = r_leave(v, arg); } break; Index: test/ruby/test_marshal.rb =================================================================== --- test/ruby/test_marshal.rb (revision 26638) +++ test/ruby/test_marshal.rb (revision 26639) @@ -1,4 +1,5 @@ require 'test/unit' +require 'tempfile' require_relative 'marshaltestlib' class TestMarshal < Test::Unit::TestCase @@ -325,6 +326,15 @@ b = "\x82\xa2".force_encoding(Encoding::Windows_31J) c = [/#{a}/, /#{b}/] assert_equal(c, Marshal.load(Marshal.dump(c)), bug2109) + + assert_nothing_raised(ArgumentError, '[ruby-dev:40386]') do + re = Tempfile.open("marshal_regexp") do |f| + f.binmode.write("\x04\bI/\x00\x00\x06:\rencoding\"\rUS-ASCII") + f.close + Marshal.load(f.open.binmode) + end + assert_equal(//, re) + end end class DumpTest -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/