Project

General

Profile

Bug #14338

IO#write without args seems wrong

Added by normalperson (Eric Wong) 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:84703]

Description

"ruby -e STDOUT.write" outputs "#<IO:0x583a2de0>" (without quotes)

"ruby -rstringio -e 'p StringIO.new.write'" shows zero bytes written

The following restores <= 2.4 behavior for IO#write, but other things (StringIO,
OpenSSL, ...) need to be modified, too:

diff --git a/io.c b/io.c
index eeaf0c021c..0d95d12a9b 100644
--- a/io.c
+++ b/io.c
@@ -1675,7 +1675,10 @@ io_writev(int argc, VALUE *argv, VALUE io)
 static VALUE
 io_write_m(int argc, VALUE *argv, VALUE io)
 {
-    if (argc > 1) {
+    if (argc <= 0) {
+   rb_error_arity(argc, 1, UNLIMITED_ARGUMENTS);
+    }
+    else if (argc > 1) {
    return io_writev(argc, argv, io);
     }
     else {

Opinions? Should we raise or just return 0 when no args are given?

Associated revisions

Revision 7292569d
Added by normal 4 months ago

io.c: IO#write without args returns 0

This is consistent with other implementations of .write
in openssl and stringio.

  • io.c (io_write_m): return 0 on argc == 0 [Bug #14338]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62967
Added by normalperson (Eric Wong) 4 months ago

io.c: IO#write without args returns 0

This is consistent with other implementations of .write
in openssl and stringio.

  • io.c (io_write_m): return 0 on argc == 0 [Bug #14338]

History

#1 [ruby-core:86285] Updated by nobu (Nobuyoshi Nakada) 4 months ago

  • Description updated (diff)

normalperson (Eric Wong) wrote:

Opinions? Should we raise or just return 0 when no args are given?

I vote for the latter.

#2 Updated by Anonymous 4 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62967.


io.c: IO#write without args returns 0

This is consistent with other implementations of .write
in openssl and stringio.

  • io.c (io_write_m): return 0 on argc == 0 [Bug #14338]

Also available in: Atom PDF