ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "YO4 (Yoshinao Muramatsu) via ruby-dev" <ruby-dev@ml.ruby-lang.org>
To: ruby-dev@ml.ruby-lang.org
Cc: "YO4 (Yoshinao Muramatsu)" <noreply@ruby-lang.org>
Subject: [ruby-dev:52132] [Ruby master Feature#11177] DATAでEOF文字以降が読めない
Date: Thu, 21 Nov 2024 15:02:14 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-110720.20241121150214.18@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-11177.20150524055355.18@ruby-lang.org>

Issue #11177 has been updated by YO4 (Yoshinao Muramatsu).


本件についてDATA.pos が__END__直後を示さないこと、Cのfseek(0, SEEK_CUR)っぽく DATA.seek(0, IO:SEEK_CUR)を行っても改善しないことから
単純なワークアラウンドは存在しないと思っていましたが、
3.4-head で試したところ prismでの仕様の違いか別の理由からかは確認できていませんが DATA.pos が __END__直後を指していたので
```
IO.open(DATA.fileno, "rt") { _1.readlines } # 明示的にuniversal newlineを使用してopen
```
で```\x1A```込みで読み込み可能でした。
```
>less -F data.rb
p IO.open(DATA.fileno, "rt") { _1.readlines }
__END__
textpart1
textpart1^Z
binpart1
binpart2

>ruby data.rb
["textpart1\n", "textpart1\u001A\n", "binpart1\n", "binpart2\n"]
```
上記にて、data.rb の改行は CR+LF です。

----------------------------------------
Feature #11177: DATAでEOF文字以降が読めない
https://bugs.ruby-lang.org/issues/11177#change-110720

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
遠藤です。

Windows で `__END__` 以降に EOF 文字 (`\x1A`) があったとき、それより先が読めないのは仕様でしょうか。

gen.rb:

    puts "p DATA.read"
    puts "__END__"
    puts "foo\x1Abar"

以下のように実行すると再現します。

    > ruby gen.rb > t.rb
    > ruby t.rb
    "foo"

`DATA.binmode.read` などとしてみても同じです。

もちろん、Linux では先まで読めます。Windows でも、ソースコードをパイプで流し込んだ場合はなぜか読めます。

    > ruby < t.rb
    "foo\x1Abar\n"

さらに、EOF 以降に文字がいっぱいあった場合、EOF 以降の一部の文字が抜け落ちるような挙動になるようです。

gen2.rb:

    puts "p DATA.read"
    puts "__END__"
    puts "foo\x1A" + "X" * 8192 + "Z"

    > ruby gen2.rb > t.rb
    > ruby t.rb
    "fooXXXXXXXXXXXXXXXXXXXXXXXXXXXZ\r\n"

バッファリングのバグっぽい挙動ですが、バグでしょうか。

-- 
Yusuke Endoh <mame@ruby-lang.org>



-- 
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org

       reply	other threads:[~2024-11-21 15:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11177.20150524055355.18@ruby-lang.org>
2024-11-21 15:02 ` YO4 (Yoshinao Muramatsu) via ruby-dev [this message]
2024-11-22 14:15 ` [ruby-dev:52133] " YO4 (Yoshinao Muramatsu) via ruby-dev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-110720.20241121150214.18@ruby-lang.org \
    --to=ruby-dev@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).