[MC] Overrides and condenseChanges?

Andreas Raab andreas.raab at gmx.de
Wed Apr 5 21:09:20 UTC 2006


tim Rowledge wrote:
> Alternatively, it isn't some artifact of multibytefilethingummy writing 
> the source in UTF-16 or whatever?

Close. I found it. And I don't know how to say it gently but this 
qualifies for the worst code I have *EVER* seen in Squeak (I was so 
pissed when I found it, I was seriously looking for a sand bag to 
deliver a few punches). Have a look at what lurks in 
MultiByteFileStream>>open:forWrite:

self localName = (FileDirectory localNameFor: SmalltalkImage current 
sourcesName)
	ifTrue: [converter := MacRomanTextConverter new]
	ifFalse: [converter := UTF8TextConverter new]

E.g., when a file has the same LOCAL name as the current image's source 
name the converter is set to MacRoman? WTF??? And not in openSourceFiles 
(where we actually know that we're dealing with the sources file), no 
*right there* in #open:forWrite:. That's freaking unbelievable.

Which, of course, means that when you create *any* file that happens to 
have the same name as your sources file (which naturally happens when 
you do a condenseSources) it'll end up with a @#^! up text converter. 
And the fact that MacRomanTextConverter doesn't raise an error when 
invoked with wide characters is just another major bug here since it 
would have pointed out immediately that something is wrong and prevented 
me from wasting a whole day hunting down that bug in the midst of trying 
to get a release out of the door.

So what happens is this: #condenseSources opens the file, the converter 
is set to MacRoman. You start filing out and everything works just fine, 
until you run into a wide character (like in JapaneseEnvironment). 
MacRomanTextConverter (instead of raising an error) lets this slip 
through, the "buffer1" iVar in FileStream (instead of raising an error) 
lets this slip through, too, and FileStream from here on writes every 
character as four bytes.

By my counting, there are at least four major bugs in the above:
1) The code in MultiByteStream>>open:forWrite:
2) The fact that MacRomanTextConverter doesn't raise an error for wide 
characters
3) The fact that the sources file is in a non-default (and undetectable) 
encoding which means that just fixing #1 will break with the current 
source file unless extra care is taken
4) The fact that ByteString automatically mutates into WideString via 
#become: (which I always considered dubious; by now I'm convinced it's a 
bug)
And of course, when you try to figure out what's going on, you're not 
going to use the current sources file name so the series of bugs just 
disappear.

I am so mad right now, I'll stop right here.
  - A.



More information about the Squeak-dev mailing list