Mercurial > cpython-lru_cache-weakref
diff Python/modsupport.c @ 41766:d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
to PyObject_CallFunction()) that take a char * (and a size
in the case of 'U#') and create a unicode object out of it.
Add functions PyUnicode_FromFormat() and PyUnicode_FromFormatV()
that work similar to PyString_FromFormat(), but create a unicode
object (also a %U format character has been added, that takes
a PyObject *, which must point to a unicode object).
Change the encoding and reason attributes of UnicodeEncodeError,
UnicodeDecodeError and UnicodeTranslateError to be unicode
objects.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Fri, 18 May 2007 16:29:38 +0000 |
| parents | c48fe4dc34a9 |
| children | cd125fe83051 |
line wrap: on
line diff
--- a/Python/modsupport.c Fri May 18 13:12:10 2007 +0000 +++ b/Python/modsupport.c Fri May 18 16:29:38 2007 +0000 @@ -424,6 +424,39 @@ return v; } + case 'U': + { + PyObject *v; + char *str = va_arg(*p_va, char *); + Py_ssize_t n; + if (**p_format == '#') { + ++*p_format; + if (flags & FLAG_SIZE_T) + n = va_arg(*p_va, Py_ssize_t); + else + n = va_arg(*p_va, int); + } + else + n = -1; + if (str == NULL) { + v = Py_None; + Py_INCREF(v); + } + else { + if (n < 0) { + size_t m = strlen(str); + if (m > PY_SSIZE_T_MAX) { + PyErr_SetString(PyExc_OverflowError, + "string too long for Python string"); + return NULL; + } + n = (Py_ssize_t)m; + } + v = PyUnicode_FromStringAndSize(str, n); + } + return v; + } + case 'y': { PyObject *v;
