From 730e3b2ce01915c4a98b79bb281b2c38a9ff1131 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 30 May 2024 14:55:32 +0200 Subject: [PATCH] Stop exposing `rb_str_chilled_p` [Feature #20205] Now that chilled strings no longer appear as frozen, there is no need to offer an API to check for chilled strings. We however need to change `rb_check_frozen_internal` to no longer be a macro, as it needs to check for chilled strings. --- error.c | 10 ++++++++-- ext/-test-/string/chilled.c | 13 ------------- include/ruby/internal/intern/error.h | 27 ++------------------------- include/ruby/internal/intern/string.h | 15 --------------- insns.def | 2 +- string.c | 6 ------ test/-ext-/string/test_chilled.rb | 19 ------------------- variable.c | 2 +- vm_insnhelper.c | 4 ++-- 9 files changed, 14 insertions(+), 84 deletions(-) delete mode 100644 ext/-test-/string/chilled.c delete mode 100644 test/-ext-/string/test_chilled.rb diff --git a/error.c b/error.c index 9890fddcef..bb063a1772 100644 --- a/error.c +++ b/error.c @@ -3914,14 +3914,20 @@ rb_error_frozen_object(VALUE frozen_obj) void rb_check_frozen(VALUE obj) { - rb_check_frozen_internal(obj); + if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) { + rb_error_frozen_object(obj); + } + + if (RB_UNLIKELY(CHILLED_STRING_P(obj))) { + rb_str_modify(obj); + } } void rb_check_copyable(VALUE obj, VALUE orig) { if (!FL_ABLE(obj)) return; - rb_check_frozen_internal(obj); + rb_check_frozen(obj); if (!FL_ABLE(orig)) return; } diff --git a/ext/-test-/string/chilled.c b/ext/-test-/string/chilled.c deleted file mode 100644 index c98fc72c47..0000000000 --- a/ext/-test-/string/chilled.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "ruby.h" - -static VALUE -bug_s_rb_str_chilled_p(VALUE self, VALUE str) -{ - return rb_str_chilled_p(str) ? Qtrue : Qfalse; -} - -void -Init_string_chilled(VALUE klass) -{ - rb_define_singleton_method(klass, "rb_str_chilled_p", bug_s_rb_str_chilled_p, 1); -} diff --git a/include/ruby/internal/intern/error.h b/include/ruby/internal/intern/error.h index c56db91b4f..2ca51d0111 100644 --- a/include/ruby/internal/intern/error.h +++ b/include/ruby/internal/intern/error.h @@ -237,9 +237,6 @@ 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() /** @@ -247,30 +244,10 @@ RBIMPL_SYMBOL_EXPORT_END() * * Does anyone use this? Remain not deleted for compatibility. */ -#define rb_check_frozen_internal(obj) do { \ - VALUE frozen_obj = (obj); \ - 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) +#define rb_check_frozen_internal rb_check_frozen /** @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); - } -} - -/** @alias{rb_check_frozen} */ -#define rb_check_frozen rb_check_frozen_inline +#define rb_check_frozen_inline rb_check_frozen /** * Ensures that the passed integer is in the passed range. When you can use diff --git a/include/ruby/internal/intern/string.h b/include/ruby/internal/intern/string.h index 6827563e8d..37dee45527 100644 --- a/include/ruby/internal/intern/string.h +++ b/include/ruby/internal/intern/string.h @@ -601,21 +601,6 @@ VALUE rb_str_dup(VALUE str); */ VALUE rb_str_resurrect(VALUE str); -/** - * Returns whether a string is chilled or not. - * - * This function is temporary and users must check for its presence using - * #ifdef HAVE_RB_STR_CHILLED_P. If HAVE_RB_STR_CHILLED_P is not defined, then - * strings can't be chilled. - * - * @param[in] str A string. - * @retval 1 The string is chilled. - * @retval 0 Otherwise. - */ -bool rb_str_chilled_p(VALUE str); - -#define HAVE_RB_STR_CHILLED_P 1 - /** * Obtains a "temporary lock" of the string. This advisory locking mechanism * prevents other cooperating threads from tampering the receiver. The same diff --git a/insns.def b/insns.def index 3858ad3c6d..f7df92cf06 100644 --- a/insns.def +++ b/insns.def @@ -222,7 +222,7 @@ setinstancevariable (ID id, IVC ic) (VALUE val) () -// attr bool leaf = false; /* has rb_check_frozen_internal() */ +// attr bool leaf = false; /* has rb_check_frozen() */ { vm_setinstancevariable(GET_ISEQ(), GET_SELF(), id, val, ic); } diff --git a/string.c b/string.c index ad1e76cdc9..acad662e4d 100644 --- a/string.c +++ b/string.c @@ -1898,12 +1898,6 @@ rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str, bool chil return new_str; } -bool -rb_str_chilled_p(VALUE str) -{ - return CHILLED_STRING_P(str); -} - /* * * call-seq: diff --git a/test/-ext-/string/test_chilled.rb b/test/-ext-/string/test_chilled.rb deleted file mode 100644 index dccab61ced..0000000000 --- a/test/-ext-/string/test_chilled.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'test/unit' -require '-test-/string' - -class Test_String_ChilledString < Test::Unit::TestCase - def test_rb_str_chilled_p - str = "" - assert_equal true, Bug::String.rb_str_chilled_p(str) - end - - def test_rb_str_chilled_p_frozen - str = "".freeze - assert_equal false, Bug::String.rb_str_chilled_p(str) - end - - def test_rb_str_chilled_p_mutable - str = "".dup - assert_equal false, Bug::String.rb_str_chilled_p(str) - end -end diff --git a/variable.c b/variable.c index fcde8a603e..657cbdc889 100644 --- a/variable.c +++ b/variable.c @@ -1761,7 +1761,7 @@ rb_obj_ivar_set(VALUE obj, ID id, VALUE val) VALUE rb_vm_set_ivar_id(VALUE obj, ID id, VALUE val) { - rb_check_frozen_internal(obj); + rb_check_frozen(obj); rb_obj_ivar_set(obj, id, val); return val; } diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 70c73955e9..09cca908dc 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1419,7 +1419,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, RB_DEBUG_COUNTER_INC(ivar_set_ic_miss); if (BUILTIN_TYPE(obj) == T_OBJECT) { - rb_check_frozen_internal(obj); + rb_check_frozen(obj); attr_index_t index = rb_obj_ivar_set(obj, id, val); @@ -3767,7 +3767,7 @@ vm_call_attrset_direct(rb_execution_context_t *ec, rb_control_frame_t *cfp, cons attr_index_t index = vm_cc_attr_index(cc); shape_id_t dest_shape_id = vm_cc_attr_index_dest_shape_id(cc); ID id = vm_cc_cme(cc)->def->body.attr.id; - rb_check_frozen_internal(obj); + rb_check_frozen(obj); VALUE res = vm_setivar(obj, id, val, dest_shape_id, index); if (UNDEF_P(res)) { switch (BUILTIN_TYPE(obj)) {