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. --- Modules/_ctypes/_ctypes.c | 65 ++++++++++++++++++++++++++++++++++------------- Python/mactoolboxglue.c | 26 ++++++++++++++++--- 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index ab5e895..83f23ca 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -1389,6 +1389,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject PyTypeObject *result; StgDictObject *stgdict; PyObject *name = PyTuple_GET_ITEM(args, 0); + PyObject *newname; PyObject *swapped_args; static PyObject *suffix; Py_ssize_t i; @@ -1399,17 +1400,17 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject if (suffix == NULL) #ifdef WORDS_BIGENDIAN - suffix = PyString_FromString("_le"); + suffix = PyUnicode_FromString("_le"); #else - suffix = PyString_FromString("_be"); + suffix = PyUnicode_FromString("_be"); #endif - Py_INCREF(name); - PyString_Concat(&name, suffix); - if (name == NULL) + newname = PyUnicode_Concat(name, suffix); + if (newname == NULL) { return NULL; + } - PyTuple_SET_ITEM(swapped_args, 0, name); + PyTuple_SET_ITEM(swapped_args, 0, newname); for (i=1; itp_base == &Simple_Type) { - switch (PyString_AS_STRING(proto)[0]) { + switch (*proto_str) { case 'z': /* c_char_p */ ml = &c_char_p_method; break; diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c index 26a1308..9a8d30b 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 v0.12