|
30 | 30 | #include "internal/hash.h" |
31 | 31 | #include "internal/numeric.h" |
32 | 32 | #include "internal/object.h" |
| 33 | +#include "internal/re.h" |
33 | 34 | #include "internal/struct.h" |
34 | 35 | #include "internal/symbol.h" |
35 | 36 | #include "internal/util.h" |
@@ -1731,7 +1732,10 @@ r_ivar_encoding(VALUE obj, struct load_arg *arg, VALUE sym, VALUE val) |
1731 | 1732 | int idx = sym2encidx(sym, val); |
1732 | 1733 | if (idx >= 0) { |
1733 | 1734 | if (rb_enc_capable(obj)) { |
1734 | | - rb_enc_associate_index(obj, idx); |
| 1735 | + // Check if needed to avoid rb_check_frozen() check for Regexps |
| 1736 | + if (rb_enc_get_index(obj) != idx) { |
| 1737 | + rb_enc_associate_index(obj, idx); |
| 1738 | + } |
1735 | 1739 | } |
1736 | 1740 | else { |
1737 | 1741 | rb_raise(rb_eArgError, "%"PRIsVALUE" is not enc_capable", obj); |
@@ -1854,17 +1858,17 @@ append_extmod(VALUE obj, VALUE extmod) |
1854 | 1858 | override_ivar_error(type, str); \ |
1855 | 1859 | } while (0) |
1856 | 1860 |
|
1857 | | -static VALUE r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE extmod, int type); |
| 1861 | +static VALUE r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE klass, VALUE extmod, int type); |
1858 | 1862 |
|
1859 | 1863 | static VALUE |
1860 | 1864 | r_object0(struct load_arg *arg, bool partial, int *ivp, VALUE extmod) |
1861 | 1865 | { |
1862 | 1866 | int type = r_byte(arg); |
1863 | | - return r_object_for(arg, partial, ivp, extmod, type); |
| 1867 | + return r_object_for(arg, partial, ivp, 0, extmod, type); |
1864 | 1868 | } |
1865 | 1869 |
|
1866 | 1870 | static VALUE |
1867 | | -r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE extmod, int type) |
| 1871 | +r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE klass, VALUE extmod, int type) |
1868 | 1872 | { |
1869 | 1873 | VALUE (*hash_new_with_size)(st_index_t) = rb_hash_new_with_size; |
1870 | 1874 | VALUE v = Qnil; |
@@ -1940,12 +1944,12 @@ r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE extmod, int typ |
1940 | 1944 | } |
1941 | 1945 | type = r_byte(arg); |
1942 | 1946 | if ((c == rb_cHash) && |
1943 | | - /* Hack for compare_by_identify */ |
| 1947 | + /* Hack for compare_by_identity */ |
1944 | 1948 | (type == TYPE_HASH || type == TYPE_HASH_DEF)) { |
1945 | 1949 | hash_new_with_size = rb_ident_hash_new_with_size; |
1946 | 1950 | goto type_hash; |
1947 | 1951 | } |
1948 | | - v = r_object_for(arg, partial, 0, extmod, type); |
| 1952 | + v = r_object_for(arg, partial, 0, c, extmod, type); |
1949 | 1953 | if (RB_SPECIAL_CONST_P(v) || RB_TYPE_P(v, T_OBJECT) || RB_TYPE_P(v, T_CLASS)) { |
1950 | 1954 | goto format_error; |
1951 | 1955 | } |
@@ -2082,7 +2086,10 @@ r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE extmod, int typ |
2082 | 2086 | } |
2083 | 2087 | rb_str_set_len(str, dst - ptr); |
2084 | 2088 | } |
2085 | | - VALUE regexp = rb_reg_new_str(str, options); |
| 2089 | + if (!klass) { |
| 2090 | + klass = rb_cRegexp; |
| 2091 | + } |
| 2092 | + VALUE regexp = rb_reg_init_str(rb_reg_s_alloc(klass), str, options); |
2086 | 2093 | r_copy_ivar(regexp, str); |
2087 | 2094 |
|
2088 | 2095 | v = r_entry0(regexp, idx, arg); |
|
0 commit comments