Project

General

Profile

Bug #10007

IO#read does not respect String Copy-On-Write in some cases

Added by zed_0xff (Andrey Zaikin) about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
[ruby-core:63523]

Description

#!/usr/bin/env ruby

CHUNK_SIZE = 29            # no problems with CHUNK_SIZE = 28

File.open(__FILE__,'r') do |f|
  d0 = ''
  a = []

  f.read(CHUNK_SIZE, d0)
  a << d0[15..-2]
  a << d0[5..-2]
  a << d0[-5..-2]
  a << d0[15..-1]
  a << d0[5..-1]           # <-- only this string will change
  a << d0[-5..-1]
  p a
  f.read(CHUNK_SIZE, d0)   # <-- 2nd read
  p a
end

output on ruby 1.9.3p448: (all strings are similar before and after 2nd read)

["ruby\n\nCHUNK_S", "r/bin/env ruby\n\nCHUNK_S", "NK_S", "ruby\n\nCHUNK_SI", "r/bin/env ruby\n\nCHUNK_SI", "NK_SI"]
["ruby\n\nCHUNK_S", "r/bin/env ruby\n\nCHUNK_S", "NK_S", "ruby\n\nCHUNK_SI", "r/bin/env ruby\n\nCHUNK_SI", "NK_SI"]

output on ruby 2.0.0p481, 2.0.0p353, 2.0.0p247: (5th string changed unexpectedly!)

["ruby\n\nCHUNK_S", "r/bin/env ruby\n\nCHUNK_S", "NK_S", "ruby\n\nCHUNK_SI", "r/bin/env ruby\n\nCHUNK_SI", "NK_SI"]
["ruby\n\nCHUNK_S", "r/bin/env ruby\n\nCHUNK_S", "NK_S", "ruby\n\nCHUNK_SI", "29\n\nFile.open(__FILE__,'", "NK_SI"]

Related issues

Is duplicate of Ruby master - Bug #9847: Cannot create new String when using File.read(size, buffer) Closed05/17/2014Actions

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

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

No problems in the trunk.

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED
  • Status changed from Open to Closed

2.0.0p510 and 2.1.2p161 have no problems.

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Is duplicate of Bug #9847: Cannot create new String when using File.read(size, buffer) added

Also available in: Atom PDF