diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-11-16 19:47:31 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-11-16 19:47:31 +0900 |
| commit | a367373fe3e9fd405bb11b0eafb7b74865d884ad (patch) | |
| tree | 7219d083433a70609aec871de1a0f247d2c4e448 | |
| parent | c9f156ef0c3f6992fa55798a6cbe46e4c94fc23b (diff) | |
| download | mruby-a367373fe3e9fd405bb11b0eafb7b74865d884ad.tar.gz mruby-a367373fe3e9fd405bb11b0eafb7b74865d884ad.zip | |
Revert "Implement Ruby2.7's frozen strings from `Symbol#to_s`"
This feature was reverted from Ruby 2.7.
| -rw-r--r-- | mrbgems/mruby-class-ext/src/class.c | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-symbol-ext/mrblib/symbol.rb | 8 | ||||
| -rw-r--r-- | src/class.c | 25 | ||||
| -rw-r--r-- | src/symbol.c | 10 | ||||
| -rw-r--r-- | src/variable.c | 2 |
5 files changed, 24 insertions, 27 deletions
diff --git a/mrbgems/mruby-class-ext/src/class.c b/mrbgems/mruby-class-ext/src/class.c index 0d27c30ed..02ebf80cc 100644 --- a/mrbgems/mruby-class-ext/src/class.c +++ b/mrbgems/mruby-class-ext/src/class.c @@ -5,7 +5,11 @@ static mrb_value mrb_mod_name(mrb_state *mrb, mrb_value self) { - return mrb_class_path(mrb, mrb_class_ptr(self)); + mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self)); + if (mrb_string_p(name)) { + MRB_SET_FROZEN_FLAG(mrb_basic_ptr(name)); + } + return name; } static mrb_value diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb index 4b4cf83fe..99fa275d5 100644 --- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb +++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb @@ -10,7 +10,7 @@ class Symbol # Same as <code>sym.to_s.capitalize.intern</code>. def capitalize - self.to_s.capitalize.to_sym + (self.to_s.capitalize! || self).to_sym end ## @@ -20,7 +20,7 @@ class Symbol # Same as <code>sym.to_s.downcase.intern</code>. def downcase - self.to_s.downcase.to_sym + (self.to_s.downcase! || self).to_sym end ## @@ -30,7 +30,7 @@ class Symbol # Same as <code>sym.to_s.upcase.intern</code>. def upcase - self.to_s.upcase.to_sym + (self.to_s.upcase! || self).to_sym end ## @@ -41,7 +41,7 @@ class Symbol def casecmp(other) return nil unless other.kind_of?(Symbol) - lhs = self.to_s.upcase + lhs = self.to_s; lhs.upcase! rhs = other.to_s.upcase lhs <=> rhs end diff --git a/src/class.c b/src/class.c index 2656806d2..e731fde59 100644 --- a/src/class.c +++ b/src/class.c @@ -65,23 +65,21 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb name = mrb_symbol_value(id); } else { - const char *n; - mrb_int len; - mrb_value outer_name = mrb_class_path(mrb, outer); - - if (mrb_nil_p(outer_name)) { /* unnamed outer class */ + name = mrb_class_path(mrb, outer); + if (mrb_nil_p(name)) { /* unnamed outer class */ if (outer != mrb->object_class && outer != c) { mrb_obj_iv_set_force(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"), mrb_obj_value(outer)); } return; } - n = mrb_sym_name_len(mrb, id, &len); - name = mrb_str_new_capa(mrb, RSTRING_LEN(outer_name) + 2 + len); - mrb_str_cat_str(mrb, name, outer_name); - mrb_str_cat_lit(mrb, name, "::"); - mrb_str_cat(mrb, name, n, len); - MRB_SET_FROZEN_FLAG(mrb_obj_ptr(name)); + else { + mrb_int len; + const char *n = mrb_sym_name_len(mrb, id, &len); + + mrb_str_cat_lit(mrb, name, "::"); + mrb_str_cat(mrb, name, n, len); + } } mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name); } @@ -1718,7 +1716,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c) /* toplevel class/module */ return mrb_sym_str(mrb, mrb_symbol(path)); } - return path; + return mrb_str_dup(mrb, path); } MRB_API struct RClass* @@ -1885,8 +1883,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) return mrb_str_cat_lit(mrb, str, ">"); } else { - mrb_value str = class_name_str(mrb, mrb_class_ptr(klass)); - return mrb_frozen_p(mrb_basic_ptr(str)) ? mrb_str_dup(mrb, str) : str; + return class_name_str(mrb, mrb_class_ptr(klass)); } } diff --git a/src/symbol.c b/src/symbol.c index 2696b5210..a4c453d32 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -517,18 +517,14 @@ mrb_sym_str(mrb_state *mrb, mrb_sym sym) { mrb_int len; const char *name = mrb_sym_name_len(mrb, sym, &len); - mrb_value str; if (!name) return mrb_undef_value(); /* can't happen */ if (SYMBOL_INLINE_P(sym)) { - str = mrb_str_new(mrb, name, len); + mrb_value str = mrb_str_new(mrb, name, len); RSTR_SET_ASCII_FLAG(mrb_str_ptr(str)); + return str; } - else { - str = mrb_str_new_static(mrb, name, len); - } - MRB_SET_FROZEN_FLAG(mrb_str_ptr(str)); - return str; + return mrb_str_new_static(mrb, name, len); } static const char* diff --git a/src/variable.c b/src/variable.c index 8fc01fe2d..030aa7b00 100644 --- a/src/variable.c +++ b/src/variable.c @@ -1123,7 +1123,7 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c) iv_del(mrb, c->iv, mrb_intern_lit(mrb, "__outer__"), NULL); iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path); mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path); - MRB_SET_FROZEN_FLAG(mrb_obj_ptr(path)); + path = mrb_str_dup(mrb, path); } return path; } |
