diff options
| author | Michael W. Hudson <mwh@python.net> | 2002-10-07 12:32:57 (GMT) |
|---|---|---|
| committer | Michael W. Hudson <mwh@python.net> | 2002-10-07 12:32:57 (GMT) |
| commit | d1bb75505fbb5b47f4f3d420e00964b38c24b203 (patch) | |
| tree | 301416738736d193214c3d6639c94682faf225af /Python | |
| parent | b45532abd26a9752e42ca589b5b0e49552761811 (diff) | |
| download | cpython-d1bb75505fbb5b47f4f3d420e00964b38c24b203.zip cpython-d1bb75505fbb5b47f4f3d420e00964b38c24b203.tar.gz cpython-d1bb75505fbb5b47f4f3d420e00964b38c24b203.tar.bz2 | |
Backport:
2002/08/11 12:23:04 lemburg Python/bltinmodule.c 2.262
2002/08/11 12:23:04 lemburg Objects/unicodeobject.c 2.162
2002/08/11 12:23:03 lemburg Misc/NEWS 1.461
2002/08/11 12:23:03 lemburg Lib/test/test_unicode.py 1.65
2002/08/11 12:23:03 lemburg Include/unicodeobject.h 2.39
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
u'%c' will now raise a ValueError in case the argument is an
integer outside the valid range of Unicode code point ordinals.
Closes SF bug #593581.
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/bltinmodule.c | 35 |
1 files changed, 1 insertions, 34 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4601c49..b85f685 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -301,44 +301,11 @@ static PyObject * builtin_unichr(PyObject *self, PyObject *args) { long x; - Py_UNICODE s[2]; if (!PyArg_ParseTuple(args, "l:unichr", &x)) return NULL; -#ifdef Py_UNICODE_WIDE - if (x < 0 || x > 0x10ffff) { - PyErr_SetString(PyExc_ValueError, - "unichr() arg not in range(0x110000) " - "(wide Python build)"); - return NULL; - } -#else - if (x < 0 || x > 0xffff) { - PyErr_SetString(PyExc_ValueError, - "unichr() arg not in range(0x10000) " - "(narrow Python build)"); - return NULL; - } -#endif - - if (x <= 0xffff) { - /* UCS-2 character */ - s[0] = (Py_UNICODE) x; - return PyUnicode_FromUnicode(s, 1); - } - else { -#ifndef Py_UNICODE_WIDE - /* UCS-4 character. store as two surrogate characters */ - x -= 0x10000L; - s[0] = 0xD800 + (Py_UNICODE) (x >> 10); - s[1] = 0xDC00 + (Py_UNICODE) (x & 0x03FF); - return PyUnicode_FromUnicode(s, 2); -#else - s[0] = (Py_UNICODE)x; - return PyUnicode_FromUnicode(s, 1); -#endif - } + return PyUnicode_FromOrdinal(x); } static char unichr_doc[] = |
