From 8ab0220352de7d4acfcbb45a25ef3de54233c8c5 Mon Sep 17 00:00:00 2001 From: naruse Date: Sun, 11 Oct 2009 18:49:41 +0000 Subject: * marshal.c (has_encoding): added for check the regexp is dumped by 1.8 or 1.9. * marshal.c (r_object0): use has_encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- marshal.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'marshal.c') diff --git a/marshal.c b/marshal.c index fb2cd7e5d7..f6e1e386a8 100644 --- a/marshal.c +++ b/marshal.c @@ -1304,6 +1304,35 @@ obj_alloc_by_path(VALUE path, struct load_arg *arg) #define div0(x) ruby_div0(x) +static int +has_encoding(struct load_arg *arg) +{ + int res = FALSE; + long offset = arg->offset; + r_long(arg); + switch (r_byte(arg)) { + case ':': + 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 ';': + { + 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) { @@ -1474,21 +1503,17 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) { volatile VALUE str = r_bytes(arg); int options = r_byte(arg); - VALUE args[2]; - args[0] = str; - args[1] = INT2FIX(options); - v = r_entry(rb_obj_alloc(rb_cRegexp), arg); - if (ivp) { - r_ivar(v, arg); - *ivp = FALSE; - } - if (rb_enc_get_index(v) != rb_usascii_encindex()) - rb_enc_copy(str, v); - if (rb_enc_get_index(str) != rb_utf8_encindex()) { -#define f_gsub_bang(x,y,z) rb_funcall(x, rb_intern("gsub!"), 2, y, z) - f_gsub_bang(str, rb_reg_new("\\\\u", 3, 0), rb_usascii_str_new_cstr("u")); + + if (!ivp || !has_encoding(arg)) { + VALUE pat; + VALUE dst; + char *rsrc = + "(?