Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006736 [Squeak] Collections major always 10-19-07 13:28 10-19-07 20:26
Reporter noha View Status public  
Assigned To
Priority normal Resolution open Platform
Status new   OS
Projection none   OS Version
ETA none Fixed in Version Product Version 3.9
  Product Build
Summary 0006736: PositionableStream>>nextLittleEndianNumber: produces DNU: Character>>bitOr:
Description nextLittleEndianNumber: reads an amount of characters from a stream and converts them to a number. nextNumber: is working. In netLittleEndianNumber: a call to isInteger is missing.
Steps To Reproduce
Additional Information
Attached Files  PositionableStream-noha-M6736.1.cs [^] (492 bytes) 10-19-07 13:35

- Relationships

- Notes
(0011357 - 1164 - 1398 - 1398 - 1398 - 1398 - 1398)
nicolas cellier
10-19-07 20:14

Yes, good catch.
However, this might be a false good idea, because some file stream can groke several bytes with a single #next message (for example transform a CR-LF pair into a single Character cr).

The only safe way is to send #binary to your stream.

Observe typical example of #nextNumber: failure below:


| f n1 n2 |
f := FileStream newFileNamed: 'foo'.
[f binary.
f nextPutAll: #(16r01 16r02 16r0D 16r0A 16r00) asByteArray] ensure: [f close].

f := FileStream oldFileNamed: 'foo'.
n1 := [f binary.
f nextNumber: 4] ensure: [f close].

f := FileStream oldFileNamed: 'foo'.
n2 := [f ascii; wantsLineEndConversion: true.
f nextNumber: 4] ensure: [f close].

^({n1. n2.}) collect: [:e | e printStringBase: 16]


Another case with UTF-8:

| f n1 n2 |
f := FileStream newFileNamed: 'foo'.
[f binary.
f nextPutAll: #(16r01 16r02 16rE0 16r04 16r05 16r06) asByteArray] ensure: [f close].

f := FileStream oldFileNamed: 'foo'.
n1 := [f binary.
f nextNumber: 4] ensure: [f close].

f := FileStream oldFileNamed: 'foo'.
n2 := [f ascii.
f nextNumber: 4] ensure: [f close].

^ ({n1. n2.}) collect: [:e | e printStringBase: 16]
 
(0011358 - 215 - 237 - 237 - 237 - 237 - 237)
nicolas cellier
10-19-07 20:26

In other words, I would prefer #asInteger to be removed from #nextNumber: rather than added to #nextLittleEndianNumber:

A good exception telling me "hey your stream is not binary" is better than a false result...
 

- Issue History
Date Modified Username Field Change
10-19-07 13:28 noha New Issue
10-19-07 13:35 noha File Added: PositionableStream-noha-M6736.1.cs
10-19-07 13:36 noha Issue Monitored: noha
10-19-07 20:14 nicolas cellier Note Added: 0011357
10-19-07 20:26 nicolas cellier Note Added: 0011358


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
40 total queries executed.
29 unique queries executed.
Powered by Mantis Bugtracker