Index: Modules/_ctypes/cfield.c =================================================================== --- Modules/_ctypes/cfield.c (révision 85151) +++ Modules/_ctypes/cfield.c (copie de travail) @@ -1203,6 +1203,7 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size) { Py_ssize_t len; + wchar_t chars[2]; if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string expected instead of %s instance", @@ -1211,7 +1212,7 @@ } else Py_INCREF(value); - len = PyUnicode_GET_SIZE(value); + len = PyUnicode_AsWideChar((PyUnicodeObject *)value, chars, 2); if (len != 1) { Py_DECREF(value); PyErr_SetString(PyExc_TypeError, @@ -1219,7 +1220,7 @@ return NULL; } - *(wchar_t *)ptr = PyUnicode_AS_UNICODE(value)[0]; + *(wchar_t *)ptr = chars[0]; Py_DECREF(value); _RET(value); Index: Lib/ctypes/test/test_strings.py =================================================================== --- Lib/ctypes/test/test_strings.py (révision 85151) +++ Lib/ctypes/test/test_strings.py (copie de travail) @@ -74,6 +74,13 @@ buf[1] = "Z" self.assertEqual(buf.value, "xZCD") + @unittest.skipIf(sizeof(c_wchar) < 4, + "sizeof(wchar_t) is smaller than 4 bytes") + def test_nonbmp(self): + u = chr(0x10ffff) + w = c_wchar(u) + self.assertEqual(w.value, u) + class StringTestCase(unittest.TestCase): def XX_test_basic_strings(self): cs = c_string("abcdef")