From 5e23d5732b8e549588be7b0cc7c3deeb300df7e0 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 9 Jul 2007 11:17:33 +0000 Subject: Changes to ctypes and Mac toolbox glue that fix test_threading and test_platform. However, test_ctypes is still broken -- and apparently more than before. --- Python/mactoolboxglue.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'Python/mactoolboxglue.c') diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c index 26a13083f36..9a8d30b9545 100644 --- a/Python/mactoolboxglue.c +++ b/Python/mactoolboxglue.c @@ -159,12 +159,32 @@ int PyMac_GetOSType(PyObject *v, OSType *pr) { uint32_t tmp; - if (!PyString_Check(v) || PyString_Size(v) != 4) { + const char *str; + int len; + if (PyUnicode_Check(v)) { + v = _PyUnicode_AsDefaultEncodedString(v, NULL); + if (v == NULL) + return 0; + } + if (PyString_Check(v)) { + str = PyString_AS_STRING(v); + len = PyString_GET_SIZE(v); + } + else if (PyBytes_Check(v)) { + str = PyBytes_AS_STRING(v); + len = PyBytes_GET_SIZE(v); + } + else { + PyErr_SetString(PyExc_TypeError, + "OSType arg must be string (of 4 chars)"); + return 0; + } + if (len != 4) { PyErr_SetString(PyExc_TypeError, - "OSType arg must be string of 4 chars"); + "OSType arg must be (string of) 4 chars"); return 0; } - memcpy((char *)&tmp, PyString_AsString(v), 4); + memcpy((char *)&tmp, str, 4); *pr = (OSType)ntohl(tmp); return 1; } -- cgit v1.2.3