Bug #8625

IO#read(len, buf) shortens buf even if data is not read actually

Added by Nobuhiro IMAI about 2 years ago. Updated about 1 year ago.

[ruby-core:55951]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
ruby -v:ruby 2.1.0dev (2013-07-11 trunk 41923) [x86_64-linux] Backport:2.0.0: DONE, 2.1: DONE

Description

By r34580, IO#read(len, buf) does not expand buf until data is read actually,
but it still shortens if the original buf size is greater than len.
Is this an intended behavior?

def m(s)
  IO.pipe do |r, w|
    t = Thread.new{r.read(2, s)}
    Thread.pass until t.stop?
    t.kill
    t.value
  end
end

(1..3).each do |len|
  s = "x" * len
  s # => "x", "xx", "xxx"
  m(s)
  s # => "x", "xx", "xx"
end

Associated revisions

Revision 46360
Added by Nobuyoshi Nakada about 1 year ago

io.c: not shorten buffer unless succeeded

  • io.c (io_setstrbuf, io_read): should not shorten the given buffer until read succeeds. [Bug #8625]

Revision 46360
Added by Nobuyoshi Nakada about 1 year ago

io.c: not shorten buffer unless succeeded

  • io.c (io_setstrbuf, io_read): should not shorten the given buffer until read succeeds. [Bug #8625]

Revision 46372
Added by Nobuyoshi Nakada about 1 year ago

io.c: truncate before appending

  • io.c (read_all): truncate the buffer before appending read data, instead of truncating before reading. [Bug #8625]

Revision 46372
Added by Nobuyoshi Nakada about 1 year ago

io.c: truncate before appending

  • io.c (read_all): truncate the buffer before appending read data, instead of truncating before reading. [Bug #8625]

Revision 46629
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) r46360,r46372: [Backport #8625]

* io.c (io_setstrbuf, io_read): should not shorten the given buffer until
  read succeeds.   [Bug #8625]

* io.c (read_all): truncate the buffer before appending read data,
  instead of truncating before reading.
   [Bug #8625]

Revision 46738
Added by Usaku NAKAMURA about 1 year ago

merge revision(s) 46360,46372: [Backport #8625]

* io.c (io_setstrbuf, io_read): should not shorten the given buffer until
  read succeeds.   [Bug #8625]

* io.c (read_all): truncate the buffer before appending read data,
  instead of truncating before reading.
   [Bug #8625]

History

#1 Updated by Masaki Matsushita about 2 years ago

  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

Nakada-san, what do you think?

#2 Updated by Masaki Matsushita over 1 year ago

  • Assignee changed from Nobuyoshi Nakada to Masaki Matsushita

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • Description updated (diff)
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

#4 Updated by Nobuyoshi Nakada about 1 year ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

Applied in changeset r46360.


io.c: not shorten buffer unless succeeded

  • io.c (io_setstrbuf, io_read): should not shorten the given buffer until read succeeds. [Bug #8625]

#5 Updated by Usaku NAKAMURA about 1 year ago

  • Status changed from Closed to Assigned
  • Assignee changed from Masaki Matsushita to Nobuyoshi Nakada

r46360 breaks some tests on mswin.

#6 Updated by Nobuyoshi Nakada about 1 year ago

  • Status changed from Assigned to Closed

Applied in changeset r46372.


io.c: truncate before appending

  • io.c (read_all): truncate the buffer before appending read data, instead of truncating before reading. [Bug #8625]

#7 Updated by Tomoyuki Chikanaga about 1 year ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE

Backported into ruby_2_1 branch at r46629.

#8 Updated by Usaku NAKAMURA about 1 year ago

backported into ruby_2_0_0 at r46738.

#9 Updated by Usaku NAKAMURA about 1 year ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE

Also available in: Atom PDF