[#122973] [PATCH] Add Gem.default_install — Felipe Contreras via ruby-core <ruby-core@...>
We need a way to enable user installs by default so that tools like
3 messages
2025/08/17
[ruby-core:122910] [Ruby Bug#21530] Is IO#eof? supposed to always block and read?
From:
"tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@...>
Date:
2025-08-04 18:57:27 UTC
List:
ruby-core #122910
Issue #21530 has been reported by tenderlovemaking (Aaron Patterson).
----------------------------------------
Bug #21530: Is IO#eof? supposed to always block and read?
https://bugs.ruby-lang.org/issues/21530
* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
I'm not sure whether or not this is expected behavior, but it seems like eof? blocks when called on $stdin.
For example:
```ruby
if (str = $stdin.gets)
$stderr.puts "read #{str}"
end
if $stdin.eof? # this call waits for input
$stderr.puts "stdin is eof"
end
```
I think this is kind of odd behavior because if you input a string but _do not_ input a newline, then hit ^D twice, `$stdin` should be at EOF, but `eof?` will block and wait for input. If you hit ^D a third time, $stdin will be EOF, but if you input a different character it will not be EOF.
Compare this C program:
```c
#include <stdio.h>
#include <stdlib.h>
#define BUF_SIZE 4096
int main(int argc, char *argv[]) {
char buf[BUF_SIZE];
if (fgets(buf, BUF_SIZE, stdin)) {
fprintf(stderr, "read %s\n", buf);
}
if (feof(stdin)) { // Does not block
fprintf(stderr, "stdin is EOF\n");
}
}
```
If you hit ^D twice with this C program, `feof` will return true for `stdin`. I would have expected the Ruby program and the C program to behave similarly, but they don't. Is this expected? The documentation indeed says that `eof?` will read, but shouldn't the IO be at EOF after the second ^D?
Thank you.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/