diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-03-28 02:30:46 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-03-27 17:41:38 +0000 |
commit | 51e6becd391eac03fd3842e1db9b6907999d64ba (patch) | |
tree | 677184c50190f3cee6f57072e7bc1474191f6f32 /ext/stringio | |
parent | 06563d78a1e28ad97593c3caaf5137f0c64884bf (diff) |
[ruby/stringio] Extract `readonly_string_p`
https://github.com/ruby/stringio/commit/0da5b725c8
Diffstat (limited to 'ext/stringio')
-rw-r--r-- | ext/stringio/stringio.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index c9f6b38ae6..f0e5ee4e85 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -59,6 +59,12 @@ rb_str_chilled_p(VALUE str) } #endif +static bool +readonly_string_p(VALUE string) +{ + return OBJ_FROZEN_RAW(string) && !rb_str_chilled_p(string); +} + static struct StringIO * strio_alloc(void) { @@ -303,7 +309,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self) string = rb_enc_str_new("", 0, rb_default_external_encoding()); } - if (!NIL_P(string) && OBJ_FROZEN_RAW(string) && !rb_str_chilled_p(string)) { + if (!NIL_P(string) && readonly_string_p(string)) { if (ptr->flags & FMODE_WRITABLE) { rb_syserr_fail(EACCES, 0); } @@ -497,7 +503,7 @@ strio_set_string(VALUE self, VALUE string) rb_io_taint_check(self); ptr->flags &= ~FMODE_READWRITE; StringValue(string); - ptr->flags = OBJ_FROZEN(string) && !rb_str_chilled_p(string) ? FMODE_READABLE : FMODE_READWRITE; + ptr->flags = readonly_string_p(string) ? FMODE_READABLE : FMODE_READWRITE; ptr->pos = 0; ptr->lineno = 0; RB_OBJ_WRITE(self, &ptr->string, string); |