summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorLars Kanis <kanis@comcard.de>2021-08-16 13:11:30 +0200
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-08-22 10:33:22 +0900
commit6594623f623a0982da62cc105094da0701d499da (patch)
tree75d34cda3a7c66ed4ce62bbe2f172876b0bbdcdd /io.c
parentc527d278a3dd94b9f5b82769fb69ee7b92b6d6a9 (diff)
Fix Marshal.dump(closed_io) to raise TypeError and allow encoding on closed IO
Mashalling a closed IO object raised "closed stream (IOError)" before instead of TypeError. This changes IO#(in|ex)ternal_encoding to still return the encoding even if the underlying FD is closed. Fixes bug #18077
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4758
Diffstat (limited to 'io.c')
-rw-r--r--io.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/io.c b/io.c
index 533542b297..2e4c335aae 100644
--- a/io.c
+++ b/io.c
@@ -12092,9 +12092,8 @@ rb_io_s_copy_stream(int argc, VALUE *argv, VALUE io)
static VALUE
rb_io_external_encoding(VALUE io)
{
- rb_io_t *fptr;
+ rb_io_t *fptr = RFILE(rb_io_taint_check(io))->fptr;
- GetOpenFile(io, fptr);
if (fptr->encs.enc2) {
return rb_enc_from_encoding(fptr->encs.enc2);
}
@@ -12117,9 +12116,8 @@ rb_io_external_encoding(VALUE io)
static VALUE
rb_io_internal_encoding(VALUE io)
{
- rb_io_t *fptr;
+ rb_io_t *fptr = RFILE(rb_io_taint_check(io))->fptr;
- GetOpenFile(io, fptr);
if (!fptr->encs.enc2) return Qnil;
return rb_enc_from_encoding(io_read_encoding(fptr));
}