[Python-checkins] python/dist/src/Python bltinmodule.c,2.261,2.262
lemburg@users.sourceforge.net
lemburg@users.sourceforge.net
Sun, 11 Aug 2002 05:23:06 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv573/Python
Modified Files:
bltinmodule.c
Log Message:
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.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.261
retrieving revision 2.262
diff -C2 -d -r2.261 -r2.262
*** bltinmodule.c 30 Jun 2002 15:26:10 -0000 2.261
--- bltinmodule.c 11 Aug 2002 12:23:04 -0000 2.262
***************
*** 261,302 ****
{
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
! }
}
--- 261,269 ----
{
long x;
if (!PyArg_ParseTuple(args, "l:unichr", &x))
return NULL;
! return PyUnicode_FromOrdinal(x);
}