diff options
author | Guido van Rossum <guido@python.org> | 2007-07-15 13:00:05 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-15 13:00:05 (GMT) |
commit | 8ac004e69895e8fd525307fdc1e093f92b15ce09 (patch) | |
tree | 947227b6fa3f72f1b6591af1e14181ee30f1bc5d /Objects | |
parent | 49c12ac04e1bfb238454d9ca2cf3a5acd9991ef5 (diff) | |
download | cpython-8ac004e69895e8fd525307fdc1e093f92b15ce09.zip cpython-8ac004e69895e8fd525307fdc1e093f92b15ce09.tar.gz cpython-8ac004e69895e8fd525307fdc1e093f92b15ce09.tar.bz2 |
Make chr() and ord() return/accept surrogate pairs in narrow builds.
The domain of chr() and the range of ord() are now always [0 ... 0x10FFFF].
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2728f1f..a60fa8b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -915,21 +915,20 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode, PyObject *PyUnicode_FromOrdinal(int ordinal) { - Py_UNICODE s[1]; + Py_UNICODE s[2]; -#ifdef Py_UNICODE_WIDE if (ordinal < 0 || ordinal > 0x10ffff) { PyErr_SetString(PyExc_ValueError, - "chr() arg not in range(0x110000) " - "(wide Python build)"); + "chr() arg not in range(0x110000)"); return NULL; } -#else - if (ordinal < 0 || ordinal > 0xffff) { - PyErr_SetString(PyExc_ValueError, - "chr() arg not in range(0x10000) " - "(narrow Python build)"); - return NULL; + +#ifndef Py_UNICODE_WIDE + if (ordinal > 0xffff) { + ordinal -= 0x10000; + s[0] = 0xD800 | (ordinal >> 10); + s[1] = 0xDC00 | (ordinal & 0x3FF); + return PyUnicode_FromUnicode(s, 2); } #endif |