Mantis - Squeak
Viewing Issue Advanced Details
7167 System major always 08-29-08 11:46 09-19-09 20:55
norbertf  
 
normal  
feedback 3.10  
open  
none    
none  
0007167: ReadWriteStream opened with "on: aCollection" always has readLimit 0
Example:
"(ReadWriteStream on: 'abc') next"
returns nil

Encountered this when trying in vain:
"Form fromBinaryStream: (RWBinaryOrTextStream on: file contents)"

The reason is that ReadWriteStream is a subclass of WriteStream which does "readLimit := 0" in its WriteStream>on: method.

my fix is:
-----------
'From Squeak3.10-basic of 26 May 2008 [latest update: 0007160] on 29 August 2008 at 1:27:05 pm'!

!ReadWriteStream methodsFor: 'private' stamp: 'nf 8/29/2008 13:26'!
on: aCollection
'fixing the bug that a ReadWriteStream had the readLimit set to 0 from the WriteStream>on: method'
    super on: aCollection.
    readLimit := aCollection size! !
-----------
After fixing this I saw immediately one side effect:
A real time clock in a seaside interface showed extraneous garbage characters at the end. I suspect this is another bug.
A cursory glance at references to ReadWriteStream seems to indicate that most uses are for writing rather than reading which would explain why this bug was not noticed before.

Notes
(0012537)
norbertf   
08-29-08 12:32   
Found a better fix for my problem:
(ReadWriteStream with: 'abc') reset next
works
It seems like "on:" is for writing
and "with:" is for reading and writing.
(0012711)
Keith_Hodges   
10-01-08 01:35   
Do others agree with Norbert?
(0013007)
nicolas cellier   
03-05-09 19:35   
Good questions could be
What does ANSI says ?
What do other dialects do ?
And last, is it worth changing ?
(how much code would break ?)
(0013313)
nicolas cellier   
09-19-09 20:55   
Note: VW and Dolphin behave same as Squeak...
VW (ReadWriteStream on: 'abc') next -> nil
Dolphin (ReadWriteStream on: 'abc') next -> EndOfStreamError

But using #with: leads to same results as using #on: and is thus different than Squeak.
If I understand correctly, VW and Dolphin #with: are ANSI compliant, Squeak is not: ANSI says the stream initially has no future value (for read).