summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-02 11:25:35 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-02 11:25:35 (GMT)
commit749261e241849834a5cfc70808260a534e50875f (patch)
treeafbaa8979a5b74dd2f3236454b661fdcf2b9d4c8 /Modules
parent5593d8aeb4bcc904ff58e8e3eb8b799a0aabc302 (diff)
downloadcpython-749261e241849834a5cfc70808260a534e50875f.zip
cpython-749261e241849834a5cfc70808260a534e50875f.tar.gz
cpython-749261e241849834a5cfc70808260a534e50875f.tar.bz2
Issue #8670: ctypes.c_wchar supports non-BMP characters with 32 bits wchar_t
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/cfield.c5
-rw-r--r--Modules/_testcapimodule.c8
2 files changed, 7 insertions, 6 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index ba60deb..072b8c6 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1203,6 +1203,7 @@ static PyObject *
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 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
} 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 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
return NULL;
}
- *(wchar_t *)ptr = PyUnicode_AS_UNICODE(value)[0];
+ *(wchar_t *)ptr = chars[0];
Py_DECREF(value);
_RET(value);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index d2d3b19..912ba17 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1386,7 +1386,7 @@ test_widechar(PyObject *self)
}
static PyObject *
-test_aswidechar(PyObject *self, PyObject *args)
+unicode_aswidechar(PyObject *self, PyObject *args)
{
PyObject *unicode, *result;
Py_ssize_t buflen, size;
@@ -1417,7 +1417,7 @@ test_aswidechar(PyObject *self, PyObject *args)
}
static PyObject *
-test_aswidecharstring(PyObject *self, PyObject *args)
+unicode_aswidecharstring(PyObject *self, PyObject *args)
{
PyObject *unicode, *result;
Py_ssize_t size;
@@ -2321,8 +2321,8 @@ static PyMethodDef TestMethods[] = {
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
{"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS},
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
- {"test_aswidechar", test_aswidechar, METH_VARARGS},
- {"test_aswidecharstring", test_aswidecharstring, METH_VARARGS},
+ {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
+ {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
#ifdef WITH_THREAD
{"_test_thread_state", test_thread_state, METH_VARARGS},
{"_pending_threadfunc", pending_threadfunc, METH_VARARGS},