On Feb 3, 2006, at 10:52 AM, Ronald Oussoren wrote:

>
> On 3-feb-2006, at 5:23, Bob Ippolito wrote:
>
>> It fixes a couple of the endian issues in the Mac modules  
>> (platform.mac_ver, applesingle, gestalt, and the OSType converter  
>> functions)
>
> How do you convert four character codes? Is 'abcd' big endian or  
> platform-native?

'abcd' is platform endian.

See http://svn.red-bean.com/bob/python24-fat/Python/mactoolboxglue.c

/* Convert a 4-char string object argument to an OSType value */
int
PyMac_GetOSType(PyObject *v, OSType *pr)
{
        uint32_t tmp;
        if (!PyString_Check(v) || PyString_Size(v) != 4) {
                PyErr_SetString(PyExc_TypeError,
                        "OSType arg must be string of 4 chars");
                return 0;
        }
        memcpy((char *)&tmp, PyString_AsString(v), 4);
        *pr = (OSType)ntohl(tmp);
        return 1;
}

/* Convert an OSType value to a 4-char string object */
PyObject *
PyMac_BuildOSType(OSType t)
{
        uint32_t tmp = htonl((uint32_t)t);
        return PyString_FromStringAndSize((char *)&tmp, 4);
}

-bob


_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to