support surrogate pair to Py_UCS4 coercion only in 16 bit Unicode builds
authorStefan Behnel <scoder@users.berlios.de>
Mon, 31 Jan 2011 07:56:52 +0000 (08:56 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 31 Jan 2011 07:56:52 +0000 (08:56 +0100)
Cython/Compiler/PyrexTypes.py
tests/run/py_ucs4_type.pyx

index ca997ee837dd0681c56e404109b9a8ed742de120..07142349367bc1ba594a5a17c3e6bd106815a94f 100755 (executable)
@@ -958,7 +958,9 @@ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject* x) {
    if (PyUnicode_Check(x)) {
        if (likely(PyUnicode_GET_SIZE(x) == 1)) {
            return PyUnicode_AS_UNICODE(x)[0];
-       } else if (PyUnicode_GET_SIZE(x) == 2) {
+       }
+       #if Py_UNICODE_SIZE == 2
+       else if (PyUnicode_GET_SIZE(x) == 2) {
            Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
            if (high_val >= 0xD800 && high_val <= 0xDBFF) {
                Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
@@ -967,8 +969,9 @@ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject* x) {
                }
            }
        }
+       #endif
        PyErr_Format(PyExc_ValueError,
-           "only single character unicode strings or surrogate pairs can be converted to Py_UCS4, got length "
+           "only single character unicode strings can be converted to Py_UCS4, got length "
            #if PY_VERSION_HEX < 0x02050000
            "%d",
            #else
index 930333d0212c0793809c4ae0c576153a334c9c84..b5790dced8c667a09d7ab821751a185fc2f9224b 100644 (file)
@@ -68,13 +68,13 @@ def unicode_ordinal(Py_UCS4 i):
     >>> unicode_ordinal(u0[:0])
     Traceback (most recent call last):
     ...
-    ValueError: only single character unicode strings or surrogate pairs can be converted to Py_UCS4, got length 0
+    ValueError: only single character unicode strings can be converted to Py_UCS4, got length 0
 
     More than one character:
     >>> unicode_ordinal(u0+u1)
     Traceback (most recent call last):
     ...
-    ValueError: only single character unicode strings or surrogate pairs can be converted to Py_UCS4, got length 2
+    ValueError: only single character unicode strings can be converted to Py_UCS4, got length 2
     """
     return i