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.
This commit is contained in:
parent
3eba84fba0
commit
730e3b2ce0
10
error.c
10
error.c
@ -3914,14 +3914,20 @@ rb_error_frozen_object(VALUE frozen_obj)
|
|||||||
void
|
void
|
||||||
rb_check_frozen(VALUE obj)
|
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
|
void
|
||||||
rb_check_copyable(VALUE obj, VALUE orig)
|
rb_check_copyable(VALUE obj, VALUE orig)
|
||||||
{
|
{
|
||||||
if (!FL_ABLE(obj)) return;
|
if (!FL_ABLE(obj)) return;
|
||||||
rb_check_frozen_internal(obj);
|
rb_check_frozen(obj);
|
||||||
if (!FL_ABLE(orig)) return;
|
if (!FL_ABLE(orig)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -237,9 +237,6 @@ RBIMPL_ATTR_NORETURN()
|
|||||||
*/
|
*/
|
||||||
void rb_error_arity(int argc, int min, int max);
|
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()
|
RBIMPL_SYMBOL_EXPORT_END()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,30 +244,10 @@ RBIMPL_SYMBOL_EXPORT_END()
|
|||||||
*
|
*
|
||||||
* Does anyone use this? Remain not deleted for compatibility.
|
* Does anyone use this? Remain not deleted for compatibility.
|
||||||
*/
|
*/
|
||||||
#define rb_check_frozen_internal(obj) do { \
|
#define rb_check_frozen_internal rb_check_frozen
|
||||||
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)
|
|
||||||
|
|
||||||
/** @alias{rb_check_frozen} */
|
/** @alias{rb_check_frozen} */
|
||||||
static inline void
|
#define rb_check_frozen_inline rb_check_frozen
|
||||||
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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the passed integer is in the passed range. When you can use
|
* Ensures that the passed integer is in the passed range. When you can use
|
||||||
|
@ -601,21 +601,6 @@ VALUE rb_str_dup(VALUE str);
|
|||||||
*/
|
*/
|
||||||
VALUE rb_str_resurrect(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
|
* Obtains a "temporary lock" of the string. This advisory locking mechanism
|
||||||
* prevents other cooperating threads from tampering the receiver. The same
|
* prevents other cooperating threads from tampering the receiver. The same
|
||||||
|
@ -222,7 +222,7 @@ setinstancevariable
|
|||||||
(ID id, IVC ic)
|
(ID id, IVC ic)
|
||||||
(VALUE val)
|
(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);
|
vm_setinstancevariable(GET_ISEQ(), GET_SELF(), id, val, ic);
|
||||||
}
|
}
|
||||||
|
6
string.c
6
string.c
@ -1898,12 +1898,6 @@ rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str, bool chil
|
|||||||
return new_str;
|
return new_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
rb_str_chilled_p(VALUE str)
|
|
||||||
{
|
|
||||||
return CHILLED_STRING_P(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
|
@ -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
|
|
@ -1761,7 +1761,7 @@ rb_obj_ivar_set(VALUE obj, ID id, VALUE val)
|
|||||||
VALUE
|
VALUE
|
||||||
rb_vm_set_ivar_id(VALUE obj, ID id, VALUE val)
|
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);
|
rb_obj_ivar_set(obj, id, val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss);
|
||||||
|
|
||||||
if (BUILTIN_TYPE(obj) == T_OBJECT) {
|
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);
|
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);
|
attr_index_t index = vm_cc_attr_index(cc);
|
||||||
shape_id_t dest_shape_id = vm_cc_attr_index_dest_shape_id(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;
|
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);
|
VALUE res = vm_setivar(obj, id, val, dest_shape_id, index);
|
||||||
if (UNDEF_P(res)) {
|
if (UNDEF_P(res)) {
|
||||||
switch (BUILTIN_TYPE(obj)) {
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user