Project

General

Profile

Actions

Bug #3984

closed

Unexpeted StringIO.new(string) and string variable coupling

Added by phasis68 (Heesob Park) about 14 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3dev (2010-10-26 trunk 29591) [i386-mswin32_90]
Backport:
[ruby-core:32904]

Description

=begin
Consider this:

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> a = 'foo'
=> "foo"
irb(main):003:0> b = StringIO.new(a)
=> #StringIO:0x10f6698
irb(main):004:0> b.puts 'bar'
=> nil
irb(main):005:0> a
=> "bar\n"
irb(main):006:0> a << 'test'
=> "bar\ntest"
irb(main):007:0> b.string
=> "bar\ntest"
irb(main):008:0> a.clear
=> ""
irb(main):009:0> b.string
=> ""
irb(main):010:0> b.puts "12345"
=> nil
irb(main):011:0> a
=> "\x00\x00\x00\x0012345\n"
irb(main):012:0> b.string
=> "\x00\x00\x00\x0012345\n"

The last result is obviously unexpected and must be a bug.

This also occurs to StringIO#string= method.
=end

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 14 years ago

  • Status changed from Open to Rejected

=begin
$ { echo foo; sleep 5; echo bar; } > foo.test & { sleep 1; > foo.test; }; wait
$ od -tx1z foo.test
0000000 00 00 00 00 62 61 72 0a >....bar.<
0000010

=end

Actions #2

Updated by phasis68 (Heesob Park) about 14 years ago

=begin
2010/10/26 Nobuyoshi Nakada

Issue #3984 has been updated by Nobuyoshi Nakada.

Status changed from Open to Rejected

$ { echo foo; sleep 5; echo bar; } > foo.test & { sleep 1; > foo.test; };
wait
$ od -tx1z foo.test
0000000 00 00 00 00 62 61 72 0a >....bar.<
0000010

I understand this behavior.

What I want to know is whether the variable coupling in StringIO.new and
StringIO#string= is intended or not.
If it is intended, I think it should be documented.



2010/10/26 Nobuyoshi Nakada <>

Issue #3984 has been updated by Nobuyoshi Nakada.



Status changed from Open to Rejected



$ { echo foo; sleep 5; echo bar; } > foo.test & { sleep 1; > foo.test; }; wait

$ od -tx1z foo.test

0000000 00 00 00 00 62 61 72 0a                          >....bar.<

0000010


I understand this behavior.

What I want to know is whether the variable coupling in StringIO.new and StringIO#string= is intended or not.
If it is intended, I think it should be documented.

=end

Actions #3

Updated by nobu (Nobuyoshi Nakada) about 14 years ago

=begin
It's exactly intended and expected behaviour.
Documentation improvement will be welcome.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0