[Python-3000] struni and the Apple four-character-codes

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 28 03:41:49 CEST 2007


Ronald Oussoren wrote:
> To reiterate: 4-character-codes in C are numeric literals

I'm still not convinced about that. The major use of 4-char
codes is in data structures stored on disk. I'd be surprised
if they're really stored in the opposite order on little
endian architectures, since then you wouldn't be able to
use a file system written from a PPC on an Intel or vice
versa.

It's much more likely that the C macros used to handle
4-char codes change depending on the architecture, so that
the order in memory stays the same.

So I stand by my opinion that *conceptually* they're still
4-character arrays, and the fact that they're declared as
ints in C is just a kludge to work around limitations of C.

> One example of an API that returns a dictionary where some keys refer  
> to values that are commonly encoded using 4-character-codes is - 
> [NSFileManager fileAttributesAtPath:traverseLink].

Blarg. Well, I think Cocoa is braindamaged in the way it
handles this. It should convert them to/from some friendlier
type automatically.

Note that if you use a specialised type for this in Python,
it still won't help with APIs like this that munge them in
with other types polymorphically. You'll still have to do
an explicit conversion in your Python code. So it doesn't
really matter whether the representation in Python is a
unicode string, byte string or something special.

--
Greg


More information about the Python-3000 mailing list