I’ve just posted a universal binary build of qt_tools. No feature changes.
Download latest version here.
Yeesh, those differing Endiannesses sure can be annoying! Here’s a handful of development notes and observations, of interest only to deep geeks and search engines.
1. QTAtom data appears to always be big-endian. So inserting or extracting data must always be done endian-aware.
2. Here’s a nice little endian checker:
#define WE_LE ((*(short *)"12") == 0x3231) // Evaluates to "true" on a little-endian machine, "false" on big-endian
3. I much prefer to write packing code which is unconditional, using the arithmetic properties rather than the known in-memory layout. This function packs a long to big-endian, on either flavor host.
OSErr nr_insert_deep_atom_long(QTAtomContainer ac,char *path,long long_of_data)
{
unsigned char bytes[4];
// pack bytes big-endian, as per qt_atom-ness.
bytes[0] = (long_of_data >> 24) & 0xff;
bytes[1] = (long_of_data >> 16) & 0xff;
bytes[2] = (long_of_data >> 8) & 0xff;
bytes[3] = (long_of_data >> 0) & 0xff;
return nr_insert_deep_atom_data(ac,path,4,bytes);
}
4. I had some floating point code which changed behavior for the Intel build! Seriously! In some cases, double x; (some math); x = floor(x); x -= floor(x); would result in x being slightly non-zero, but not on the PPC build. Tricky, but easy to fix with an appropriate threshold.
5. Apple’s compiler is nifty. You can just say gcc -arch ppc -arch i386 to get universal objects, binaries. But can this be true: universal binary files have mandatory resource-fork contents? I just noticed that Fetch applies Stuffit compression during upload.
6. Wow, -gfull sure is important for debugging, but it changed the size of my complete machine-built release site from 5MB to 30MB! No symbols for release builds, thanks.
7. Automated tests! I cannot stress this enough. I have a little Perl test suite that exercises qt_tools’ features externally, and checks the results. Without that, the whole porting from big-endian to bi-endian would have been… much more than a weekend’s work. Having the basic feature-set nailed down by the tests means I don’t have to try to remember what the darn product is supposed to do! Just like you wouldn’t rely on manual builds — gcc, link, copy, whoops — that is, you use a Makefile, it’s nuts to rely on manual testing.