Skip to content

Commit

Permalink
Remove special handling of chilled strings
Browse files Browse the repository at this point in the history
[Feature #20205]

Followup: #94

They no longer need to be special cases. If StringIO end up
mutating a chilled string, a warning will be emitted.
  • Loading branch information
byroot authored and eregon committed May 30, 2024
1 parent 073172d commit dc62d65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 1 addition & 11 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,11 @@ static long strio_write(VALUE self, VALUE str);
#define IS_STRIO(obj) (rb_typeddata_is_kind_of((obj), &strio_data_type))
#define error_inval(msg) (rb_syserr_fail(EINVAL, msg))
#define get_enc(ptr) ((ptr)->enc ? (ptr)->enc : !NIL_P((ptr)->string) ? rb_enc_get((ptr)->string) : NULL)
#ifndef HAVE_RB_STR_CHILLED_P
static bool
rb_str_chilled_p(VALUE str)
{
return false;
}
#endif

static bool
readonly_string_p(VALUE string)
{
return OBJ_FROZEN_RAW(string) && !rb_str_chilled_p(string);
return OBJ_FROZEN_RAW(string);
}

static struct StringIO *
Expand Down Expand Up @@ -184,9 +177,6 @@ check_modifiable(struct StringIO *ptr)
if (NIL_P(ptr->string)) {
/* Null device StringIO */
}
else if (rb_str_chilled_p(ptr->string)) {
rb_str_modify(ptr->string);
}
else if (OBJ_FROZEN_RAW(ptr->string)) {
rb_raise(rb_eIOError, "not modifiable string");
}
Expand Down
3 changes: 2 additions & 1 deletion test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ def test_coderange_after_overwrite
assert_predicate(s.string, :ascii_only?)
end

if eval(%{ "test".frozen? && !"test".equal?("test") }) # Ruby 3.4+ chilled strings
require "objspace"
if ObjectSpace.respond_to?(:dump) && ObjectSpace.dump(eval(%{"test"})).include?('"chilled":true') # Ruby 3.4+ chilled strings
def test_chilled_string
chilled_string = eval(%{""})
io = StringIO.new(chilled_string)
Expand Down

0 comments on commit dc62d65

Please sign in to comment.