diff options
| author | Étienne Barrié <etienne.barrie@gmail.com> | 2024-05-27 11:22:39 +0200 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2024-05-28 07:32:33 +0200 |
| commit | 1376881e9afe6ff673f64afa791cf30f57147ee2 (patch) | |
| tree | a5ad297473381ac00c593ca2ca1ef93381fd3a00 /include/ruby/internal | |
| parent | 2114d0af1e5790da365584a38ea7ee58670dc11b (diff) | |
Stop marking chilled strings as frozen
They were initially made frozen to avoid false positives for cases such
as:
str = str.dup if str.frozen?
But this may cause bugs and is generally confusing for users.
[Feature #20205]
Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
Diffstat (limited to 'include/ruby/internal')
| -rw-r--r-- | include/ruby/internal/intern/error.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/ruby/internal/intern/error.h b/include/ruby/internal/intern/error.h index 11e147a121..c56db91b4f 100644 --- a/include/ruby/internal/intern/error.h +++ b/include/ruby/internal/intern/error.h @@ -190,6 +190,7 @@ RBIMPL_ATTR_NONNULL(()) */ void rb_error_frozen(const char *what); +RBIMPL_ATTR_NORETURN() /** * Identical to rb_error_frozen(), except it takes arbitrary Ruby object * instead of C's string. @@ -236,6 +237,9 @@ RBIMPL_ATTR_NORETURN() */ void rb_error_arity(int argc, int min, int max); +bool rb_str_chilled_p(VALUE str); +void rb_str_modify(VALUE str); + RBIMPL_SYMBOL_EXPORT_END() /** @@ -248,12 +252,18 @@ RBIMPL_SYMBOL_EXPORT_END() if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \ rb_error_frozen_object(frozen_obj); \ } \ + if (RB_UNLIKELY(rb_str_chilled_p(frozen_obj))) { \ + rb_str_modify(frozen_obj); \ + } \ } while (0) /** @alias{rb_check_frozen} */ static inline void rb_check_frozen_inline(VALUE obj) { + if (rb_str_chilled_p(obj)) { + rb_str_modify(obj); + } if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) { rb_error_frozen_object(obj); } |
