Skip to content

Commit 0da5b72

Browse files
committed
Extract readonly_string_p
1 parent 4e8e82f commit 0da5b72

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ext/stringio/stringio.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ rb_str_chilled_p(VALUE str)
5959
}
6060
#endif
6161

62+
static bool
63+
readonly_string_p(VALUE string)
64+
{
65+
return OBJ_FROZEN_RAW(string) && !rb_str_chilled_p(string);
66+
}
67+
6268
static struct StringIO *
6369
strio_alloc(void)
6470
{
@@ -303,7 +309,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
303309
string = rb_enc_str_new("", 0, rb_default_external_encoding());
304310
}
305311

306-
if (!NIL_P(string) && OBJ_FROZEN_RAW(string) && !rb_str_chilled_p(string)) {
312+
if (!NIL_P(string) && readonly_string_p(string)) {
307313
if (ptr->flags & FMODE_WRITABLE) {
308314
rb_syserr_fail(EACCES, 0);
309315
}
@@ -497,7 +503,7 @@ strio_set_string(VALUE self, VALUE string)
497503
rb_io_taint_check(self);
498504
ptr->flags &= ~FMODE_READWRITE;
499505
StringValue(string);
500-
ptr->flags = OBJ_FROZEN(string) && !rb_str_chilled_p(string) ? FMODE_READABLE : FMODE_READWRITE;
506+
ptr->flags = readonly_string_p(string) ? FMODE_READABLE : FMODE_READWRITE;
501507
ptr->pos = 0;
502508
ptr->lineno = 0;
503509
RB_OBJ_WRITE(self, &ptr->string, string);

0 commit comments

Comments
 (0)