Skip to content

Commit 135ef31

Browse files
committed
Fix IO#{autoclose=,autoclose?} and raise IOError when io is closed
1 parent ceac0cf commit 135ef31

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Compatibility:
3535
* Joni has been updated from 2.1.44 to 2.2.1 (@andrykonchin).
3636
* Fix `Hash#to_h` called with a block and pass key and value to the block as separate arguments (#3607, @andrykonchin).
3737
* Fix `StringIO#initialize` and preserve initial string's encoding when mode is `w` so the initial string is truncated (#3599, @andrykonchin).
38+
* Fix `IO#{autoclose=,autoclose?}` and raise `IOError` when io is closed (@andrykonchin).
3839

3940
Performance:
4041

spec/tags/core/io/autoclose_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/ruby/truffleruby/core/io.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,12 @@ def advise(advice, offset = 0, len = 0)
908908
# which is not really the owner of the fd should not actually close
909909
# the fd.
910910
def autoclose?
911+
ensure_open
911912
@autoclose
912913
end
913914

914915
def autoclose=(autoclose)
916+
ensure_open
915917
@autoclose = Primitive.as_boolean(autoclose)
916918
end
917919

@@ -2417,7 +2419,7 @@ def close
24172419
if fd >= 0
24182420
# Need to set even if the instance is frozen
24192421
Primitive.io_set_fd(self, -1)
2420-
if fd >= 3 && autoclose?
2422+
if fd >= 3 && @autoclose
24212423
ret = Truffle::POSIX.close(fd)
24222424
Errno.handle if ret < 0
24232425
end

0 commit comments

Comments
 (0)