diff --git a/ChangeLog b/ChangeLog index a28e4a3131..83d876b020 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Oct 12 03:47:42 2009 NARUSE, Yui + + * marshal.c (has_encoding): added for check the regexp + is dumped by 1.8 or 1.9. + + * marshal.c (r_object0): use has_encoding. + Sun Oct 11 15:54:52 2009 Nobuyoshi Nakada * ext/gdbm/gdbm.c (fgdbm_select): fixed rdoc. a patch from Justin 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 (!ivp || !has_encoding(arg)) { + VALUE pat; + VALUE dst; + char *rsrc = + "(?