Tuesday, January 16, 2007

Other People's Bugs Are My Bugs Too, Unfortunately

Quite a bit of my time is spent on bugfixing, and in many cases, I am bugfixing other people's code, be it 3rd party libraries, the compiler vendor's core libraries, or even the OS itself.

Lately, I've been fixing bugs in all three, and I'll give two examples.

Delphi comes with a core lib called "graphics.pas", and in it was a nasty memory leak in the bitmap handling code that caused GDI handles to disappear. My machine has 4 GB, 4 CPU cores and runs Windows x64, but Microsoft wouldn't be Microsoft if the limit of GDI handles wouldn't be some ridiculously low number, like two to the power of fifteen, minus many thousands. Yes, you read it correctly, the maximum number of GDI process handles in x64 is 10,000. A GDI handle is a font, a brush, a pen or a bitmap canvas etc.

I do not have the time and energy to hunt Bill Gates down like the rabid dog he is, neither would it help much, so I fixed the leak in Bore-land's Delphi instead. Not that this helped, because the 3rd-world (Indian) publishing package I'm using still evaporates GDI handles until the entire document has been printed. The only difference now is that they are returned, after the document has been produced. But a large document still runs into this ridiculous OS limit.

So I paid 11,000 USD for a 64-bit PC with oodles of RAM and a 64-bit OS, but Mr. Gates thinks that fourteen-and-a-half bits should be enough for everybody. Handing him over to Moqtada al Sadr's Mahdi Army would be much too good for the guy. I'll have to provide a very dirty workaround, as everyone has, who tries to do anything serious with a Windoze computer.

Up to the next Windoze bug that I had to fix in order to get my stuff running properly.. Moyo Go is cutting edge software. Everything is Unicode. So it flawlessly supports CJK languages.

Hah! That's what I THOUGHT!

The entire system breaks down when a Japanese user tells Windoze that he'd like Japanese formatting of numbers, currencies, dates etc. He them sets a Japanese "User Locale". And then all bets are off. Suddenly, when you send a Unicode string to a Windoze GUI widget, Windoze refuses to render it properly and turns it into Klingon instead.

Of course, this is a horrendous bug in Windoze, and it has plagued me for a year. Some Japanese customers claimed my app sucked donkeyschlongs, some said it was perfect and sent me presents. It all depended on whether they told Windoze to format their dates in a Japanese way.
Because that destroys the entire Windows' Unicode handling of the entire Operating System.

Cool. At least we found the cause.
The solution is so perverse and weird that you might not believe it (you might not believe anything in this blog posting, for that matter). I'm not even sure I should post the solution here. The enemy is listening too. I will divulge it anyway:

The solution to the bug: "Impossible to display Japanese on a Japanese computer running Japanese Windows with Japanese locale setting" is..

..

(It really is the solution, it has been tested & confirmed by my Japanese customers)

..
..
..
..
..
..

TO FORCIBLY SET THE THREAD LOCALE TO US ENGLISH!

All those billions that Gates gives to charity ain't gonna help him - he will go straight to hell where he belongs.